Microsoft Teams Change Notification Subscription validation error - microsoft-graph-api

We have implemented Change notification for Microsoft Teams channel messages and the subscription and renewal worked well. Suddenly we received the following error :
error: {
'InvalidRequest',
message: 'Subscription validation request failed. Response must exactly match validationToken query parameter.',
innerError: {
date: '2020-10-07T06:27:51',
'request-id': '1f5b7190-d2ab-459a-a9de-a086cc1a8584',
'client-request-id': '1f5b7190-d2ab-459a-a9de-a086cc1a8584'
}
}
}
Additionally we are receiving lot of life cycle notification from Microsoft Teams with and its payload is empty.
Any help is much appreciated.

Related

Invalid Request 409 when trying to subscribe to Microsoft Graph for Presence

Executing a subscription to presence request for users with the SDK targeting the MS Graph API is resulting in an error:
409Graph service exception Error code: InvalidRequest
Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: InvalidRequest
Error message: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
POST https://graph.microsoft.com/v1.0/subscriptions
SdkVersion : graph-java/v5.16.0
SdkVersion : graph-java/v5.16.0
[...]
400 : Bad Request
[...]
My code is:
final Subscription subscriptionRequest = new Subscription();
subscriptionRequest.changeType = ChangeType.UPDATED.toString();
subscriptionRequest.notificationUrl = notificationsHost;
subscriptionRequest.resource = "/communications/presences?$filter=id in ("+userIdsSb.toString()+")";
subscriptionRequest.clientState = subscribeToPresenceRequest.getClientState();
}el
subscriptionRequest.clientState = UUID.randomUUID().toString();
subscriptionRequest.expirationDateTime = OffsetDateTime.now().plusHours(1);
Subscription subscription = null;
try {
subscription = graphClient.subscriptions().buildRequest().post(subscriptionRequest);
response.setSubscribed(false);
failedIds.addAll(this.getFailedIds(e));
log.error("Error while trying to execute subscribeToPresence. ", e);
if(failedIds!=null && !failedIds.isEmpty()) {
log.error("The ids {} failed during the subscription request ",failedIds);
response.setFailedIds(failedIds);
}
}catch(Exception e) {
log.error("General Error while trying to execute subscribeToPresence. ", e);
retur
}
My subscription request includes the following values:
applicationId: null
changeType: UPDATED
clientState: 7fc6bf6b-6cc2-438d-a293-aa47539ad02a
creatorId: null
id: null
latestSupportedTlsVersion: null
lifecycleNotificationUrl: null
notificationQueryOptions: null
notificationUrl: https://myhost:port/graph/listen
notificationUrlAppId: null
oDataType: null
resource: /communications/presences?$filter=id in ('932b90ca-e5a4-42c7-a985-f4ddfc6d6715','6be2455d-63ac-4423-aa3e-7188fdbd5e73','41b3d168-5c28-4596-ba3b-d5c70a3c3967','8830a8bc-f882-4c13-b33a-7031423b5a24','ab548af7-d5a9-4388-9800-7668a20bb2b9')
expirationDateTime: 2023-02-02T16:41:11.737+02:00
includeResourceData: false
I saw this article regarding the beta version of the sdk https://learn.microsoft.com/en-us/graph/api/resources/subscription?view=graph-rest-1.0.
It indicates "Subscriptions to resources marked with an asterisk (*) are available on the /beta endpoint only." and presence is one of those resources. Is this related to my error?
I tried to use this version instead, but I still have the same Invalid request error.
I am using delegated permission to call the /subscription/presence endpoint of the Microsoft Graph API.
I was able to fetch previous subscriptions by calling /subscription endpoint and was also able to find users through /users/filter endpoint with application permission.
Is there something wrong in the format of my subscription request? This all worked fine a few months ago and I haven't changed anything.
Is this related to SSL/TLS secure communication? But then again, why would my other requests get responses?

Microsoft teams messaging extension inconsistently sending a valid conversation ID to use in a graph call

I am developing a MSTeams application, and inside I use a messaging extension. Upon opening the extension, a request is fired over to my message handler, which I use an azure function to handle. Alongside the request is a payload, with details about the context (in this case the conversation or chat) of where the messaging extension was opened from.
Now, I've built up a graph URL with the conversation ID from the payload:
const id = context.req.body.conversation.id
const graphEndpoint = encodeURIComponent(`https://graph.microsoft.com/beta/me/chats/${id}/members`)
I authenticate a user by calling microsoftTeams.authentication.authenticate({...}) before I make the call, and use the token in the request.
Sometimes, this call will succeed, and return the information I want. However, the other times it will fail with a 400, telling me I had a bad request, despite it being a GET request with no body.
I notice in bad requests, that the conversation ID doesn't trail with #thread.v2 or #unq.gbl.spaces etc. I have no clue why this is so inconsistent, or if it's my fault. Any help would be appreciated.
EDIT: I have also seen that the issue only occurs when the id starts with a:, and succeeds when it starts with 19:. However, the context in which I open the messaging extension is the same each time: In a 1:1 / User:User chat.
I have previously implemented installing the bot in the conversation to get this information, but this method is very undesirable. Perhaps a side point - it seems that the conversations where I have previously installed the bot seem to return the 19: id, and everything else a:.
Here's an example of the 400 response:
{
"error": {
"code": "BadRequest",
"message": "Bad Request",
"innerError": {
"date": "2021-01-25T09:43:26",
"request-id": "3bb55aa2-e694-4c80-952c-88842f482dc1",
"client-request-id": "3bb55aa2-e694-4c80-952c-88842f482dc1"
}
}
}
The conversation id you received in the turn-context is not the chat-id. The conversation id is different from conversation id. Conversation id the id between bot and the user and chat id the id of the chat. Both are different. You cannot use conversation id to call the graph API. Please use the chat id to call graph API. You can get the chat id using list chats API.

Subscription not created despite 201 message with correct body

I used to received the notification after receiving a new mail after making a subscription. However, since I accidently spammed my own mail box (create an event that make it so that each time there is a new message, a new draft message was created (and draft message count as new message), each time I create a subscription, I got the answer that everything is fine, but no new subscription is created. What should I do to have a functionnal subscription ?
Annex:
the post call which ask to call a ws each times a new message is received
https://graph.microsoft.com/post/subscriptions
with those params
{
changeType: 'created',
notificationUrl: 'the adresse of the webservice',
resource: 'me/messages',
expirationDateTime: '2018-10-23T17:46:08Z',
clientState: 'Message Created'
}
the answer (I also got a log indicating that the webservice got the notification token and answer it with a plain/text with statut 200 message containing the notification token.
{
changeType: 'created',
notificationUrl: 'the adresse of the webservice',
resource: 'me/messages',
expirationDateTime: '2018-10-22T17:37:21Z',
clientState: 'Message Created'
}
A few things to check:
The results returned by the list subscriptions API varies depending on the permissions (the linked article explains that). Make sure that when you check for the existence of the sub, you have the right permissions for the subscription you are looking for. Best, test with the same app and identity.
You mentioned you did receive a notification from the subscription? If so, the notification contains the ID of the subscription that generated it. That in itself is proof that the subscription was indeed created. Are you able to do a GET on that subscription?

Twilio SMS sending

await client.messages.create(
{
to: `+${userEntity.telephoneNumber}`,
from: `+${process.env.TWILIO_NUMBER}`,
body: `Your activation code is ${userEntity.activationCode}`,
},
(err, message) => {
if (err) {
throw err
} else {
return this._res.status(200).json({message: message}).end()
}
}
);
Error: The number +xxxxxxx is unverified. Trial accounts cannot send messages to unverified numbers; verify +xxxxxxx at twilio.com/user/account/phone-numbers/verified, or purchase a Twilio number to send messages to unverified numbers.
Hi everyone. I was trying to send a message from Twilio to the user but I've got this error.Who can help me? Maybe I don't understand how does it work. Should I add a number to which I want to send a message to Twilio? Or what does this message mean?
Yes that is exactly what it means, you have to verify the number you want to send your message to. The verification is done by either a call or a text.
Twilio - Verify Phone number
This will also allow you to use this number as a caller id when making a call(does not work with texting).
This is a somewhat common limitation setup for trial accounts.

Can I Update Subscription Properties via REST API using PATCH method?

I know that when you want to renew your subscription I need to call subscriptions endpoint with payload which tells new expiration date or nothing, to get maximum 3 days.
// endpoint
me/subscriptions($subscriptionId)
// payload
{
"#odata.type": "#Microsoft.OutlookServices.PushSubscription"
}
What I want to do now, is to update NotificationURL property of that subscription.
I figured it should work like this using PATCH method:
// endpoint
me/subscriptions($subscriptionId)
// payload
{
"#odata.type": "#Microsoft.OutlookServices.PushSubscription",
"NotificationURL": "https://app.domain.com/notifications"
}
But when I try to do this I only get following errors:
code: ErrorInvalidParameter
message: Notification URL 'https://oldapp.domain.com/notifications?validationtoken=[someHashCode]' verification failed 'System.Net.WebException: The remote server returned an error: (404) Not Found.
Well, of course it fails and gives 404, because it's trying to connect old NotificationURL. It looks like, it's just trying to renew subcription instead of only updating NotificationURL property of that subscription.
I know I can handle this manually in few ways for example by creating new subscriptions, but I want to make this to work automatically everytime my server boots. And it feels like a good idea to just update the NotificationURL instead of unsubscribing from all notificaitons and creating new ones.
Any help would be appreciated!

Resources