Skip to content

Solution overview

Adrian Solis edited this page Oct 7, 2019 · 2 revisions

Overview

The Celebrations app has the following main components:

  • Bot: The bot is how the app notifies users and teams of upcoming events.
  • Tabs: The personal tab lets users manage their events.
  • Azure functions: The function app triggers the bot periodically to send event previews, event notifications, and retry delivery of messages.

Bot

The bot is built using the Bot Framework SDK v3 for .NET and ASP.NET Web API 2.2. The bot has multiple functions:

  • It listens to team and user installation events, maintaining a data store that tracks which teams and users have the app installed, and which users belong to each team. This is especially useful for the following cases:
    • To notify a user in 1:1 chat, we need the user's 29:xxx Teams user ID. This ID is unique to a bot + user combination, so we need to keep track of the mapping between the user's AAD ID and the Teams user ID.
    • To show a list of teams that are common to both the user and app, we need to get the intersection of (A) teams that have the bot installed, and (B) teams that have the user as a member. Set (A) is not available through an API call: the bot must track this information itself. Set (B) can be obtained from Graph, but to use this API,. the app must have at least User.Read.All permission, and that requires tenant admin consent.
  • The app uses the bot to send notifications:
    • Users get a notification 3 days prior to the event, letting them know that the event will be shared with any teams that the users has selected. The user can choose to skip the event this year.
    • If the user doesn't skip the event, then at the appointed time, the bot will post a notification to the selected teams, letting them know of the special occasion.
    • When the bot is installed to a new team, the bot sends welcome messages to all team members who already have events, so that they can share the events to the new team (but only if they want to).

Tab and task module

Celebrations has an Events tab through which users can view and manage their special events. The tab uses an HTML-based task module as an interface for creating and editing events.

The tab is implemented using ASP.NET MVC 5, running in the same app service as the bot. The tab uses Azure AD authentication to validate the user's identity: it does not rely solely on the hints provided by the tab context.

Azure functions

Time-based Azure functions run periodically to trigger the notifications:

  • Preview: The preview function runs once daily. It looks for events that are coming up in the next 3 days, and sends a reminder to the event owner.

  • EventNotification: The notification function runs once an hour. It looks for events occurrences that are due, and sends notifications to the appropriate teams.

    Time zones can have a minute offset of up to 45 minutes, so events set to be delivered in those time zones can be delayed by up to 45 minutes. If this is a concern, set this function to run more frequently.

  • MessageDelivery: The delivery function runs every 15 minutes. It looks for messages that failed to post the first time, and that are eligible for retry, and attempts to send them again. The app retries the messages for up to 12 hours, before finally giving up.

Clone this wiki locally