How do we get to know to which response user has reacted(like/dislike) on MS teams? - botframework

We need help in understanding how Microsoft teams like and dislike works with BotFramework. When user clicks on like option provided in background we are getting reactionID but how do we get to know for which specific message user has given his feedback. Do we have this feasibility on Teams?

You can find it in the replyToId. Example from the docs:
The messageReaction event is sent when a user adds or removes his or her reaction to a message which was originally sent by your bot. replyToId contains the ID of the specific message.
{
"reactionsAdded": [
{
"type": "like"
}
],
"type": "messageReaction",
"timestamp": "2017-10-16T18:45:41.943Z",
"id": "f:9f78d1f3",
"channelId": "msteams",
"serviceUrl": "https://smba.trafficmanager.net/amer-client-ss.msg/",
"from": {
"id": "29:1I9Is_Sx0O-Iy2rQ7Xz1lcaPKlO9eqmBRTBuW6XzkFtcjqxTjPaCMij8BVMdBcL9L_RwWNJyAHFQb0TRzXgyQvA",
"aadObjectId": "c33aafc4-646d-4543-9d4c-abd28e4d2110"
},
"conversation": {
"isGroup": true,
"id": "19:3629591d4b774aa08cb0887902eee7c1#thread.skype"
},
"recipient": {
"id": "28:f5d48856-5b42-41a0-8c3a-c5f944b679b0",
"name": "SongsuggesterLocal"
},
"channelData": {
"channel": {
"id": "19:3629591d4b774aa08cb0887902eee7c1#thread.skype"
},
"team": {
"id": "19:efa9296d959346209fea44151c742e73#thread.skype"
},
"tenant": {
"id": "72f988bf-86f1-41af-91ab-2d7cd011db47"
}
},
"replyToId": "1:19uJ8TZA1cZcms7-2HLOW3pWRF4nSWEoVnRqc0DPa_kY"
}
Note, however, that this replyToId is specific to Teams and I don't believe it will persist if you set it yourself. Once you have that, you can update the activity.
If you're trying to analyze which messages are reacted to, you might want to log the outgoing activity's Id and Text in TurnContext.OnSendActivities. Then, when a reaction comes in, you can use the new Activity Handler to handle the message and add the reaction to your log. I believe this would come in OnUnrecognizedActivityTypeAsync. This is similar to the previous link, update the activity.

Related

Teams: How can we set a a global notification for every new post in a specific channel?

in our company we use Microsoft Teams.
We have a team "All" and in it a channel "Broadcast".
How can we set it centrally so that all employees receive a notification when a new post is written?
Currently we write "#All" at the beginning of the text.
But I'm sure this can be done more elegantly.
I am looking forward to your tips.
Many thanks and greetings
Frank
You can #mention the channel, so that all the members will get notified. You can achieve so using Graph API.
POST https://graph.microsoft.com/beta/teams/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/channels/19:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx#thread.tacv2/messages
{
"body": {
"contentType": "html",
"content": "Hello World <at id=\"0\">General</at>"
},
"mentions": [
{
"id": 0,
"mentionText": "General",
"mentioned": {
"conversation": {
"id": "19:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx#thread.tacv2",
"displayName": "General",
"conversationIdentityType#odata.type": "#Microsoft.Teams.GraphSvc.conversationIdentityType",
"conversationIdentityType": "channel"
}
}
]
}

Send Conversation History API returning HTTP 400 BotFramework

I'm trying to sendConversation History API provided by Microsoft in BotFramework Documentation. It takes Transcript object (array of activities) as the input. But I've getting HTTP 400 Bad Request when using trying that.
I'm making a POST request on this and authenticating it using JWT Token generated by client credentials for the bot.
https://directline.botframework.com/v3/conversations/HBoZPkTiBYOAadigqEqFaJ-us/activities/history
This is the error I get.
{
"error": {
"code": "BadSyntax",
"message": "Invalid or missing activities"
}
}
This is the activity array payload that I'm using
[
{
"type": "message",
"id": "HBoZPkTiBYOAadigqEqFaJ-us|0000003",
"timestamp": "2022-09-05T08:10:00.3574378Z",
"localTimestamp": "2022-09-05T13:39:57.633+05:30",
"localTimezone": "Asia/Calcutta",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "dl_uID1",
"name": "userName"
},
"conversation": {
"id": "HBoZPkTiBYOAadigqEqFaJ-us"
},
"recipient": {
"id": "bot-name-dev#abcd",
"name": "bot-name-dev"
},
"textFormat": "plain",
"locale": "en-GB",
"text": "hi",
"channelData": {
"clientActivityID": "1662365337633rmq6e8mbm09",
"clientTimestamp": "2022-09-05T08:09:57.633Z"
}
}
]
I'm not able to figure out what's the correct format of activity object that it is expecting.
Create the bot and get it connected to the Direct Line. Get the secret keys of the site that need to connect.
Before calling SendConversationHistory if the message is delivered to the recipient, it will create the bad request error message as it is unable to get the conversation history as the message was already received. SendConversationHistory must be called before sending the message then the Conversation History will be tracked. The below screens will be helpful to create the DirectLine connection to the bot created. Then needed to add the trusted sites to DirectLine. Then proceed with the code sample mentioned below which takes the conversation history.
Click on Create a resource
Search for bot and click on create
Select Channels
Get the App Service Extension Keys and click on Default_site
Click on the toggle and enable the enhanced authentication options and add the website which we need to communicate.
In the code block of the current working application, to get the conversation history, use the following code block.
foreach (var a in activities)
{
incrementId++;
// Use your own ID format
a.Id = string.Concat("history|", incrementId.ToString().PadLeft(7, '0'));
a.ChannelData = null;
a.Conversation = new ConversationAccount(id: convId);
if (a.From.Name == message.Recipient.Name)
{
// Bot to recipient connection
a.Recipient = message.From;
a.From = message.Recipient;
}
else
{
// User to bot connection (here bot will be the recipient)
a.Recipient = message.Recipient;
a.From = message.From;
}
}
After connecting with Microsoft, I found this is the correct payload for this API.
{
"activities": [
{
"type": "message",
"id": "whatever-conversation-id-in|0000000",
"timestamp": "2022-11-20T20:14:26.242902Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "dl_test_id",
"name": ""
},
"conversation": {
"id": "whatever-conversation-id-in"
},
"recipient": {
"id": "ABC_bot",
"name": "ABC_bot"
},
"text": "Hello Bot"
}
]
}

Send proactive chat message to initiator of Microsoft Teams Calling Bot voice caller

I have a teams bot that can answer 1-to-1 voice calls. During the call I want the bot to be able to send chat messages to the user and be able to reference user data (like their name).
Although an incoming call does have a encrypted source identity, from my experiments it appears this is not a valid user id for proactive messaging.
Interestingly enough this is easily possible in group calls as it starts passing you participant lists (which i've done before), but 1-to-1 calls appear to rely on the source field which effectively leaves the user as anonymous.
{
"#odata.type": "#microsoft.graph.commsNotifications",
"value": [
{
"#odata.type": "#microsoft.graph.commsNotification",
"changeType": "created",
"resource": "/app/calls/4a1f2c00-831f-4e4e-9d7c-1648b6dddb73",
"resourceUrl": "/communications/calls/4a1f2c00-831f-4e4e-9d7c-1648b6dddb73",
"resourceData": {
"#odata.type": "#microsoft.graph.call",
"state": "incoming",
"direction": "incoming",
"callbackUri": "https://...",
"source": {
"#odata.type": "#microsoft.graph.participantInfo",
"id": "7684a0ea-7db6-4f3e-a339-eb46e16d57f0",
"identity": {
"#odata.type": "#microsoft.graph.identitySet",
"encrypted": {
"#odata.type": "#microsoft.graph.identity",
"id": "1g7qrdwga2udafuebrjcyobchnq7r4xigupowjluuccfdceufmew6ush6wlx-kellf96ky2nnhsl084rn6vegqmwawiqpux0kk5aw5lqq9oydrewxe9awkrk_uh_0nxat", // <-- not a valid chat user
"tenantId": "{tenancyId}",
"identityProvider": "None"
}
},
"endpointType": "default",
"region": "apac",
"languageId": "en-us"
},
"targets": [
{
"#odata.type": "#microsoft.graph.invitationParticipantInfo",
"identity": {
"#odata.type": "#microsoft.graph.identitySet",
"application": {
"#odata.type": "#microsoft.graph.identity",
"id": "a2716ab5-9b38-4364-8869-b9b8deeff897",
"identityProvider": "AAD"
}
},
"endpointType": "default",
"id": "023126f0-904f-4c01-a78d-03f28e77e7a7",
"region": null,
"languageId": null
}
],
"tenantId": "{Azure Tenancy}",
"myParticipantId": "023126f0-904f-4c01-a78d-03f28e77e7a7",
"callChainId": "37de77c7-54b3-4d04-9e9c-181e5f5b5773",
"incomingContext": {
"#odata.type": "#microsoft.graph.incomingContext",
"sourceParticipantId": "7684a0ea-7db6-4f3e-a339-eb46e16d57f0"
},
"id": "4a1f2c00-831f-4e4e-9d7c-1648b6dddb73"
}
}
]
}
Yes, we can able to send the chat messages by creating Responder Call handler from bot.
Could you please try to implement the sample code.
In the sample code, will have a class named "ResponderCallHandler.cs", please have a look.

Microsoft bot framework for teams capturing unique user id

We are building a product integration using ms teams and ms bots. We are having an existing integration with Slack already. In the slack World we identify a unique user by TEAM_ID and USER_ID . In case of Teams I can see even id in the from node is a very long string suggesting its unique. Below payload is one example coming to our server. Can someone confirm if using id from the from node is wont change a particular user ever?
the user id being assumed unqiue to a user below is "29:1374Bmi6ngJLBlF9oGVcDuTaBbMfJmcOF9eUvQVdx_rgYh5spPNQ5Mi6fLdVvCiT7mQPMNytT0zGk_iAUtvqKAwXXXX"
{
"_activity": {
"id": "1576102076169",
"from": {
"id": "29:1374Bmi6ngJLBlF9oGVcDuTaBbMfJmcOF9eUvQVdx_rgYh5spPNQ5Mi6fLdVvCiT7mQPMNytT0zGk_iAUtvqKAwXXXX",
"name": "My Name",
"aadObjectId": "37a2516a-baf2-41d8-a406-a067888d676c"
},
"conversation": {
"conversationType": "personal",
"tenantId": "9bfb3569-994e-4908-855c-c7f6c1a94100",
"id": "a:1DcGjCAgiuinvuzR0Mx6dR9uJOB3YUwjMdLOiGTAwQ7KWSGsiEijNfvir66ep7k0fABwoSXxCAACx2_3GflfTNIZL7XMkfjrMm0v8OzJJ7vvIFKasqrClrZ_T-8dDfdT0"
},
"channelData": {
"tenant": {
"id": "9bfb3569-994e-4908-855c-c7f6c1a94100"
}
},
"text": "contact mat",
"textFormat": "plain",
"type": "message",
"channelId": "msteams",
"serviceUrl": "https://smba.trafficmanager.net/amer/",
"recipient": {
"id": "28:a835cf1d-83a8-4ae9-845a-23a68a1df442",
"name": "FlashCX.ai"
}
}
}
#Moblize IT Yes the id obtained from activity.from.id is the unique id for user and it wont change.

How can I interpret /perceive the presence of buttons in the response of directline api?

Consider there is a action card response from the MS bot & it looks as follows in skype:
When this similar response comes in the REST APIs i.e using Direct Line APIs. The following is the relevant part of JSON response.
{
"id": "1t90Ym3PEry|000000000000000014",
"conversationId": "1t90Ym3PEry",
"created": "2016-12-06T09:34:55.6280699Z",
"from": "rich3cards",
"images": [
"https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Seattlenighttimequeenanne.jpg/320px-Seattlenighttimequeenanne.jpg"
],
"attachments": [],
"eTag": "W/\"datetime'2016-12-06T09%3A34%3A54.94083Z'\""
},
{
"id": "1t90Ym3PEry|000000000000000014",
"conversationId": "1t90Ym3PEry",
"created": "2016-12-06T09:34:55.6280699Z",
"from": "rich3cards",
"text": "Hero Card\n\nSpace Needle\n\nThe <b>Space Needle</b> is an observation tower in Seattle, Washington, a landmark of the Pacific Northwest, and an icon of Seattle.\n\n(Current Weather) action?weather=Seattle, WA",
"images": [],
"attachments": [],
"eTag": "W/\"datetime'2016-12-06T09%3A34%3A54.94083Z'\""
}
Now, the question is about how do we parse this json to get the button data [(Current Weather) action?weather=Seattle, WA"] out of the text attribute? Is the only way is patter match ?
Has anyone faced or know solution, please put some light here too ;)
Update: If its different channel like skype/webchat/etc.. the JSON response looks very proper to consume, following is the sample JSON.
{
"type": "message",
"id": "5AdoK89rtSc|000000000000000018",
"timestamp": "2016-12-06T09:53:20.4777291Z",
"channelId": "webchat",
"from": {
"id": "rich3cards",
"name": "RichCards"
},
"conversation": {
"id": "5AdoK89rtSc"
},
"attachments": [
{
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"title": "Hero Card",
"subtitle": "Space Needle",
"text": "The <b>Space Needle</b> is an observation tower in Seattle, Washington, a landmark of the Pacific Northwest, and an icon of Seattle.",
"images": [
{
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Seattlenighttimequeenanne.jpg/320px-Seattlenighttimequeenanne.jpg"
}
],
"buttons": [
{
"type": "postBack",
"value": "action?weather=Seattle, WA",
"title": "Current Weather"
}
]
}
}
]
As mentioned in the comments, you are using DirectLine v1.1. Unfortunately, v1.1 doesn't support attachments/cards and so there isn't a good way to understand/parse the card.
You might want to consider moving to DirectLine v3 which has full support for attachments.
Alternatively, if you want to support Cards, you might have to do something custom as shown in the DirectLine sample. There, the bot is sending the hero card through the ChannelData field and the client is parsing that accordingly. However, you might have to add the logic to detect who is talking to the bot so you send the cards as ChannelData only if the caller is DirectLine and not one of the other clients (such as skype)

Resources