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

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"
}
}
]
}

Related

Mentioning a tag when posting a channel message from a teams bot

I would very much like to mention a tag when creating a teams message. I read the tag ID from Microsoft graph (I've also tried fetching tag id from an incoming message).
I can do this as my self using Microsoft Graph api with the following payload
{
"body": {
"contentType": "html",
"content": "<div>New incident ##### assigned to <at id=\"0\">App operations</at></div>"
},
"mentions": [
{
"id": 0,
"mentionText": "Operations",
"mentioned": {
"application": null,
"device": null,
"user": null,
"conversation": null,
"tag": {
"id": "my tag Id which I got using graph lookup",
"displayName": "App operations"
}
}
}
]}
Is this at all possible using the bot framework? Can the payload be manipulated to do this?
Right now, it is not supported to mention a tag using bot. The possible workaround is to use Graph API in the bot. To do that you can refer to this sample. Follow this to Add authentication to a bot. You will need to add the required permission and call the required API in sample.

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.

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

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.

How to know it is auto reply mail in Microsoft Graph?

I am using Microsoft Graph API to get mails.
GET /v1.0/me/messages
It returns
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('576552d5-3bc0-42a6-a23d-bfceb405db23')/messages",
"#odata.nextLink": "https://graph.microsoft.com/v1.0/me/messages?$skip=11",
"value": [
{
"#odata.etag": "W/\"HwAAABYAAACpTc/InBsuTYwTUBb+VIb4AACqi2tx\"",
"id": "AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA1ODZlMDI2MgBGAAAAAACUbnk-iwQZRbXMgkfKtmYhBwCpTc-InBsuTYwTUBb_VIb4AAAAAAEMAACpTc-InBsuTYwTUBb_VIb4AACqNTk9AAA=",
"createdDateTime": "2017-12-06T21:57:09Z",
"lastModifiedDateTime": "2017-12-06T21:57:19Z",
"changeKey": "HwAAABYAAACpTc/InBsuTYwTUBb+VIb4AACqi8tx",
"categories": [],
"receivedDateTime": "2017-12-06T21:57:09Z",
"sentDateTime": "2017-12-06T21:56:16Z",
"hasAttachments": false,
"internetMessageId": "<e74a536a53d245e49d779d47f774f4a0#CO2PR00MB0214.namprd00.prod.outlook.com>",
"subject": "Automatic reply: Hi",
"bodyPreview": "I am OOF.",
"importance": "normal",
"parentFolderId": "AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA2ODZlMDI5MgAuAAAAAACUbnk-iwQZRbXMgkfKtmYhAQCpTc-InBsuTYwTUBb_VIb4AAAAAAEMAAA=",
"conversationId": "AAQkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA2ODZlMDI5MgAQAPekscpearpHmBFbhG0DKuc=",
"isDeliveryReceiptRequested": null,
"isReadReceiptRequested": false,
"isRead": true,
"isDraft": false,
"webLink": "https://outlook.office365.com/owa/?ItemID=AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA1ODZlMDI5MgBGAAAAAACUbnk%2FiwQZRbXMgkfKtmYhBwCpTc%2FInBsuTYwTUBb%2BVIb4AAAAAAEMAACpTc%2FInBsuTYwTUBb%2BVIb4AACqNTk2AAA%3D&exvsurl=2&viewmodel=ReadMessageItem",
"inferenceClassification": "focused",
"body": {
"contentType": "html",
"content": "hi"
},
"sender": {
"emailAddress": {
"name": "Jack",
"address": "jack#example.com"
}
},
"from": {
"emailAddress": {
"name": "Jack",
"address": "jack#example.com"
}
},
"toRecipients": [
{
"emailAddress": {
"name": "Rose",
"address": "rose#example.com"
}
}
],
"ccRecipients": [],
"bccRecipients": [],
"replyTo": []
}
]
}
I didn't find any field related with determine whether it is an auto reply mail.
Right now I am using
mail.subject.startsWith('Automatic reply:')
to determine whether is auto reply mail in code.
However, it is not reliable. Because sometimes I got mails starting with a different language such as Resposta automática:.
So how to know it is auto reply mail correctly?
As #Horkrine said there is no officially guaranteed way of detecting if an email is an auto reply or not.
But there are two ways that may be useful:
Method 1 : Detect the response time
If you are capable, consider checking the amount of time between the email sent and the response. If that time is within a certain threshold, it is almost certainly an auto reply. Consider a reply received within seconds, for example. This has a lot of correlations with modern-day spam-robot detection techniques.
Method 2 : Keywords
The other way to do it is to look for keywords, just as you are doing now. However, you also have to account for other languages, variations on spelling, misspellings, etc. You will not get everything.
For example:
mail.subject.contains('Automatic') OR mail.subject.contains('Auto-matic') OR mail.subject.contains('Away') OR mail.subject.contains('out of office')
...
OR mail.subject.contains('automática') ...
Rather than typing out such a list, I would recommend doing a quick search on the internet and see if there are any such lists you can copy-paste from, as surely someone has done this sort of thing before and has some free code.
I'm no expert but I don't believe there's any way to determine whether or not an email is an automatic reply unless the email actually contains a string saying "This is an automatic reply" or something.
Just found another interesting API getMailTips, however this can only help determine the auto mail if the other user is Outlook or Office 365 user.
Copy the demo below for convenience.
POST https://graph.microsoft.com/api/beta/users/{id|userPrincipalName}/getMailTips
{
"EmailAddresses": [
"danas#contoso.onmicrosoft.com",
"fannyd#contoso.onmicrosoft.com"
],
"MailTipsOptions": "automaticReplies, mailboxFullStatus"
}
It will return something like
{
"#odata.context":"https://graph.microsoft.com/api/beta/$metadata#Collection(microsoft.graph.mailTips)",
"value":[
{
"emailAddress":{
"name":"",
"address":"danas#contoso.onmicrosoft.com"
},
"automaticReplies":{
"message":"<style type=\"text/css\" style=\"\">\r\n<!--\r\np\r\n\t{margin-top:0;\r\n\tmargin-bottom:0}\r\n-->\r\n</style>\r\n<div dir=\"ltr\">\r\n<div id=\"x_divtagdefaultwrapper\" style=\"font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif\">\r\n<p>Hi, I am on vacation right now. I'll get back to you after I return.<br>\r\n</p>\r\n</div>\r\n</div>",
"messageLanguage":{
"locale":"en-US",
"displayName":"English (United States)"
}
},
"mailboxFull":false
},
{
"emailAddress":{
"name":"",
"address":"fannyd#contoso.onmicrosoft.com"
},
"automaticReplies":{
"message":""
},
"mailboxFull":false
}
]
}

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