Search code examples
outlook-addinoffice-jsoutlook-restapi

Outlook add-in: take action on calendar event date and time changes


We have an Outlook office.js add-in which uses add-in commands to help our users create a custom calendar event. We would like to perform some actions when that event's date or time is changed by the user.

With the older COM-based Outlook add-ins this was possible since you could have your add-in start-up automatically when a particular calendar event was opened add you could hook into the send event.

With the new add-in commands model there are problems. Here is what I understand so far:

  1. When the user edits their event date or time while the add-in task pane is open, there is no way to be informed that they made changes. Worst yet, the user can open the event up later from their calendar and unless they triggered your add-in task pane, your add-in will not even be running. The user has to manually trigger an Outlook add-in command to open your task pane since the task pane cannot auto-trigger based on some detectable data attached to the calendar item.

  2. If you hook into the send event you might be able to call the Outlook REST API to get the date and time and perform actions. Unfortunately, to hook into the on send event you need an Administrator to turn on that feature and your add-in will be rejected for Office Store Validation. Besides, I am not sure if the on send event works for calendar items. It seems like it is limited to emails.

  3. If you want to use the Outlook Notification REST API to be notified about calendar event creation/modification/deletion, that notification subscription is time limited, does not have a way to auto-renew the notification subscription, and there does not seem to be built-in way to pass back custom parameters to the notification listener.

I hope I was clear enough and that the details I list above are accurate.

Does anyone have any suggestions on how we can automatically perform actions when the user edits the date or time of one of the calendar events created by our add-in?


Solution

  • This is done by leveraging Webhook Subscriptions and Event Deltas via Microsoft Graph.

    The webhook will get fired off whenever it detects a change to the calendar. When you receive the event, you request the calendar delta from Microsoft Graph. This will give you all of the events that were changed since the last time you polled. From here you can request a specific event, including any extended data you previously stored with that event.

    As for renewals, when you create the subscription it returns the expirationDateTime for that subscription. When your subscription expires, you can renew it and receive a new expiration date:

    PATCH https://graph.microsoft.com/v1.0/subscriptions/{id}
    
    Content-Type: application/json
    {
      "expirationDateTime": "2016-03-22T11:00:00.0000000Z"
    }