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?