0

I am trying to build a chat app which changes it's online status whenever a user's Microsoft presence changes. And I also do the reverse when a user changes his presence on my chat app using the setPresence api.

So I tried subscribing to the user's presence. I received a change notification and it is of the following structure:

{
  "value": [
    {
      "id": "lsgTZMr9KwAAA",
      "subscriptionId":"{subscription_guid}",
      "subscriptionExpirationDateTime":"2016-03-19T22:11:09.952Z",
      "clientState":"secretClientValue",
      "changeType":"created",
      "resource":"users/{user_guid}@{tenant_guid}/messages/{long_id_string}",
      "tenantId": "84bd8158-6d4d-4958-8b9f-9d6445542f95",
      "resourceData":
      {
        "Availability":"Busy,
        "Activity":"InACall"
        "id":"{long_id_string}"
      }
    }
  ]
}

This change notification has the user availability and activity, but it does not specify which app triggered this presence change. This results in the following loop:

My app changing teams presence -> teams sending me a webhook -> my app changing teams presence because of the webhook -> teams sending me a webhook and so on.

One simple fix would be to not change teams presence if both the app have the same presence. But my app does not have a one to one mapping for every presence value in teams. So it might set ,say, away for multiple states of my app. So when the away webhook arrives, I don't know for which state away was sent. Also while changing states in quick succession in my app, it does not allow me to accurately verify if both app states are in sync.

Is there any possibilities to avoid such loops in change notification webhooks?

Shri
  • 709
  • 1
  • 7
  • 23

1 Answers1

0

My advice would be to not use the presence data in the webhook, but rather when a webhook is triggered go and get the data from graph again. This will avoid any issues you might get with webhooks coming out of order.

Your app will have to manage state and decide what to do with it, but it sounds like you shouldn't update the presence state in your app unless it really is a change in presence to avoid infinite loops.

Chris Johnson
  • 1,230
  • 7
  • 15
  • But there is a limit on how many times you can fetch an user's presence through the API. It's somewhere around 1500 requests in a span of 30 seconds. I am expecting a lot more than this. So it is impossible for me to keep polling the Microsoft for every webhook. – Shri Feb 07 '22 at 04:26
  • @Clutch Prince -Could you please check on below sample documentation:-https://github.com/microsoftgraph/aspnetcore-webhooks-sample#:~:text=%20Microsoft%20Graph%20Change%20Notifications%20Sample%20for%20ASP.NET,contribute%20to%20this%20sample%2C%20see%20CONTRIBUTING.MD.%20More%20 Let us know if you have any query. – Sayali-MSFT Feb 08 '22 at 13:15
  • @Sayali-MSFT I see that the sample you have sent is about chat app, in which case works fine, but in my case of presence, this is not relevant. – Shri Feb 08 '22 at 14:11
  • @ChetanSharma-msft I have raised a feature request for this on the developer portal. If you would know some contacts, is it possible to consider this? https://techcommunity.microsoft.com/t5/microsoft-365-developer-platform/graph-api-add-information-about-the-client-that-triggered-a/idi-p/3124407 – Shri Feb 08 '22 at 14:13
  • @Sayali-MSFT the above link also has more information on the exact problem I am facing. – Shri Feb 08 '22 at 14:13