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

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

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

Microsoft Graph API - How to find out which user sent an email on behalf of a shared mailbox address with Send As permission?

I have a shared mailbox. The shared mailbox has an address SHAREDBOX1#mycompany.com. A handful of users have access to send emails on behalf of that mailbox. Via the Microsoft Graph API, is it possible to see which user sent an individual email via the sharedbox1 address?
With this use case in mind, it makes sense this would only be something we would check on outgoing messages.
Looking at the docs https://learn.microsoft.com/en-us/graph/api/resources/message?view=graph-rest-1.0 , the message properties specifically, is there any way to find which user sent an email on behalf of a shared mailbox?
For example, this is a (fake, all ids have been faked and sanitized) example email sent from a shared mailbox by a user on behalf of the shared mailbox represented in the the MS Graph API to 3 other users
{
"#odata.etag": "W/\"CQSJDKJGKJGROwCC\"",
"id": "AASDGSDGSDFMP4-RK_VSDFA1-bSDFSDFjB-JHUffy=",
"createdDateTime": "2022-07-06T16:50:55Z",
"lastModifiedDateTime": "2022-07-06T16:51:03Z",
"changeKey": "CSDFSDFSDGSFDSDFSFCC",
"categories": [],
"receivedDateTime": "2022-07-06T16:50:00Z",
"sentDateTime": "2022-07-06T16:50:45Z",
"hasAttachments": false,
"internetMessageId": "<PDSVSSVSVFGNFGHJ.something.prod.outlook.com>",
"subject": "RE: Work Stuff",
"importance": "normal",
"parentFolderId": "SDFFGAGSDFHSDFHDFNIUERGHSJHDNVUIAGNOIGAIU",
"conversationId": "JHFBVJHSBVJBVJHZVJ=",
"conversationIndex": "ETHYTJTJDGNRYJD",
"isDeliveryReceiptRequested": false,
"isReadReceiptRequested": false,
"isRead": true,
"isDraft": false,
"webLink": "https://outlook.office365.com/owa/?ItemID=SFBHWIUEwfADtegVAJBVSHFBVYUS&exvsurl=1&viewmodel=ReadMessageItem",
"inferenceClassification": "focused",
"sender": {
"emailAddress": {
"name": "SHAREDBOX1",
"address": "SHAREDBOX1#mycompany.com"
}
},
"from": {
"emailAddress": {
"name": "SHAREDBOX1",
"address": "SHAREDBOX1#mycompany.com"
}
},
"toRecipients": [
{
"emailAddress": {
"name": "Thad",
"address": "thad#mycompany.com"
}
}
],
"ccRecipients": [
{
"emailAddress": {
"name": "Chad",
"address": "chad#mycustomer.com"
}
},
{
"emailAddress": {
"name": "Vlad",
"address": "vlad#mycustomer.com"
}
}
],
"bccRecipients": [],
"replyTo": [],
"flag": {
"flagStatus": "notFlagged"
}
}
The email is from SHAREDBOX1#mycompany.com, being sent to Chad, Vlad, and Thad.
Let's say the user who actually sent the email on behalf of SHAREDBOX1#mycompany.com is brad#mycompany.com
I was hoping that the "sender" field would have contained brad#mycompany.com, as according to these docs https://learn.microsoft.com/en-us/graph/outlook-send-mail-from-other-user#send-on-behalf but that appears to not be the case. Both "sender" and "from" are always populated as SHAREDBOX1#mycompany.com (so that would indicate that the permission on the shared box for the users is "Send As" instead of "Send on Behalf")https://learn.microsoft.com/en-us/graph/outlook-send-mail-from-other-user#send-as
Assuming the permission is "Send As", is there somewhere else in the API where that information can be looked up?
Thank you!

MS Teams - automatic addin integration

I built a MS Teams Add-In. If I create a new meeting, I have to add the Add-In every time manually to this meeting.
Is there any way to integrate it to every (new) meeting by default?
Thank you!
Currently there is no way to integrate automatic addin in meeting. Alternatively you can create an event as online meeting using Graph API with below request.
POST https://graph.microsoft.com/v1.0/me/events
Prefer: outlook.timezone="Pacific Standard Time"
Content-type: application/json
{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does noon work for you?"
},
"start": {
"dateTime": "2017-04-15T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2017-04-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address":"samanthab#contoso.onmicrosoft.com",
"name": "Samantha Booth"
},
"type": "required"
}
],
"allowNewTimeProposals": true,
"isOnlineMeeting": true,
"onlineMeetingProvider": "teamsForBusiness"
}
Please go through this documentation for more info.

Detect the speaker of Google Home or Amazon's Alexa

I would like to detect who is interacting with my agent.
For example I read that Alexa should be able to detect different users. The Google Home advertisement also let me think that it should detect who is talking. So how can I see who is talking?
In slack it seems to be easier since it is well known who is writing. However I cannot see who I get the current user.
I found out how to detect the user in slack: If you implement that hook you will get this example json:
{
"id": "f7912345-e21c-450f-a8ca-d01e38012345",
"timestamp": "2016-12-20T06:53:51.071Z",
"result": {
"source": "agent",
"resolvedQuery": "echo hallo welt",
"speech": "",
"action": "",
"actionIncomplete": false,
"parameters": {
"myInput": "hallo welt"
},
"contexts": [{
"name": "generic",
"parameters": {
"slack_user_id": "U0AT12345",
"myInput": "hallo welt",
"slack_channel": "D3DR12345",
"myInput.original": "hallo welt"
},
"lifespan": 4
}],
"metadata": {
"intentId": "06212345-06a0-40fe-bbeb-9189db412345",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"intentName": "Response"
},
"fulfillment": {
"speech": "",
"messages": [{
"type": 0,
"speech": ""
}]
},
"score": 0.75
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "10612345-c681-11e6-af08-875120912345",
"originalRequest": {
"source": "slack_testbot",
"data": {
"channel": "D3DR12345",
"match": ["echo hallo welt"],
"text": "echo hallo welt",
"team": "T04H12345",
"type": "message",
"event": "direct_message",
"user": "U0AT12345",
"ts": "1482216830.000005"
}
}
}
So in case of slack you can access result->contexts[0]->paramaters->slack_user_id.
Google Home does not (at least currently) have a way to handle multiple users on the same device.
Google Home keeps improving (even removing development hurdles I've faced with their recent updates). It can now be trained to know your voice vs someone else's voice.
Tomato, tomahto. Google Home now supports multiple users

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