How to get attached mail in mail? - outlook

I am using Microsoft Graph. Right now I can read attachment by
GET /me/messages/{messageId}/attachments
But if someone attach a mail in a mail and send to me by using Outlook's Attachment feature.
Then there is no contentBytes field returned. So how to get attached mail in mail?
{
"value": [
{
"#odata.type": "#microsoft.graph.itemAttachment",
"id": "{attachmentId}",
"lastModifiedDateTime": "2018-02-06T09:08:02Z",
"name": "Hi",
"contentType": "message/rfc822",
"size": 5341,
"isInline": false
}
]
}

Use $expand to expand the attachment:
GET /me/messages/{id}/attachments/{attach-id}?$expand=microsoft.graph.itemAttachment/item

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

Mandrill emails stuck in queued

I managed to figure out how to send emails via Mandrill and Parse Cloud Code with Back4App. When checking the API logs for Mandrill I see the following:
Full Request
{
"message": {
"text": "asdf Email Test",
"subject": "adsf Email Test",
"from_email": "no-reply#asdf.ca",
"from_name": "Site",
"to": [
{
"email": "myemail#gmail.com",
"name": "Martin",
"type": "to"
}
],
"headers": {
"Reply-To": "no-reply#adsf.ca"
}
},
"async": false,
"ip_pool": "Main Pool",
"send_at": "2018-03-13T17:14:41.645Z",
"key": "oc7ueJMLRGgaEDrjhk5DBg"
}
Full Response
[
{
"email": "myemail#gmail.com",
"status": "queued",
"_id": "7c28e80e4de1405f93d1d096600128d4",
"reject_reason": null
}
]
It seems as if the code is executing properly but the response body indicates that the email is queued. I decided to wait 24 hours and nothing has changed. I sent some more test emails and I get the same result. Basically, the emails are not sending. What is going on?
apparently for Mandrill work with Back4App you need to setup a own domain, and it looks like you're using a Gmail email address. Therefore, it is recommended to use SendGrid in this case :)

How to send a mail with mention?

When I get mails:
GET /beta/me/messages
I can check this to see if someone mentioned me.
mentionsPreview: {
isMentioned: true
}
How can I send out a mail and mention someone or some people in the mail?
I didn't find any info in the document.
UPDATE 1:
I can successfully add mentions when create a new mail and send out by
POST /beta/me/sendMail
{
// ...
"mentions":[{
"mentioned": {
"name": "Jack",
"address": "jack#example.com"
},
"createdBy": {
"name": "Me",
"address": "me#example.com"
}
}]
}
However, I failed to add mentions when reply a mail. I create a draft first by
POST /beta/me/messages/{messageId}/createReplyAll
Then I update it by (this step failed to add mentions)
PATCH /beta/me/messages/{messageId}
{
"body": {
"contentType": "html",
"content": "hi"
},
"mentions":[{
"mentioned": {
"name": "Jack",
"address": "jack#example.com"
},
"createdBy": {
"name": "Me",
"address": "me#example.com"
}
}]
}
I send it out by
POST /beta/me/messages/{messageId}/send
In the mail Jack got, the content successfully updated. But mentionsPreview is still null.
UPDATE 2:
Thanks Jason's help.
Further test, I succeed add mention by
POST /beta/me/messages/{messageId}/mentions
{
"mentioned": {
"address": "jack#example.com"
}
}
But I failed to add mentions using array
POST /beta/me/messages/{messageId}/mentions
{
"mentions":[{
"mentioned": {
"address": "jack#example.com"
}
}]
}
which means I have to POST mentions one by one at least for now.
https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/mention
When creating a message, an app can create a mention in the same POST request by including the mention in the mentions property.
UPDATE
On your new question about doing this on a reply, the problem is you cannot PATCH in mentions like that. You can only include mentions inline with the rest of the message if you do it at message creation. Since you've already created the message (via the createReplyAll method), to update mentions you need to POST new mentions to the /mentions relationship on the message, like:
POST /me/messages/{messageId}/mentions
{
"mentioned": {
"name": "Jack",
"address": "jack#example.com"
},
"createdBy": {
"name": "Me",
"address": "me#example.com"
}
}
As an interesting side note, you CANNOT currently include mentions inline using the replyAll method. It seems that you can only do this when creating a brand new message or when sending a new message. For all other cases, you need to do a POST to the /mentions relationship as above.

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