Attach Sharepoint file in the Microsoft Teams webhook message - sharepoint

I have a file that is on Sharepoint for the Team and in the folder corresponding to my channel in Microsoft Teams.
E.g. Team Banana channel ripe, so my file is in https://whatever.sharepoint.com/Banana/ripe
I want to share this file to the channel with a message programmatically to get this result:
I got the above message in the teams client by going to Files tab, clicking on file and then Start conversation.
I want to share this file using a webhook.
Unfortunately i can't find anything in regards to MessageCard payloads that the webhook seems to use that would allow me to do the above.
I tried adding attachments part of the bot reference to the message like so but had no success:
POST https://outlook.office.com/webhook/whateverelsehere HTTP/1.1
Host: outlook.office.com
Content: application/json
Content-Length: 401
{
"#type": "MessageCard",
"text":"This is a message3",
"attachments": [{
"contentType": "application/vnd.microsoft.teams.card.file.info",
"contentUrl": "https://wherever.sharepoint.com/sites/feed-support/Banana/ripe/test.txt",
"name": "text.txt",
"content": {
"uniqueId": "df90889f-e8a7-452a-8795-972be16fac6f",
"fileType": "txt",
}
}]
}

Currently it is not possible to send files using webhooks. Files support in webhook is something we are working on but we do not have an ETA for it. As of now, the only way of sending files is using Bots.

Related

MS Bot Framework Direct Line API 3.0: Get starting message

I published a bot using the Azure bot framework to the Azure cloud servers, and made an application that uses the Direct Line API 3.0 to send user responses and receive bot messages through HTTP requests. Everything works except that I'm not sure how to get the starting message of the bot at the start of the conversation. I open the conversation with the /v3/directline/conversations endpoint, but I'm not sure how to receive the first message of the bot (that is normally sent without any user interaction). A message request after opening the conversation doesn't include any bot responses, but the next message request after sending the first user input includes the first two messages of the bot (starting message and response to the user).
EDIT: From reading this I came to the conclusion that it will be easier to just use a custom event as a trigger for the welcome message. I updated my bot as follows to reflect this within bot composer, adding a new CUSTOM event trigger with a test response message:
However, I still can't seem to trigger this event via the Direct Line API. Currently, I send a request as follows, following the event activity structure:
{
"type": "event",
"channelId": "directline",
"from": { "id": "UnityUserId", "name": "Unity User 1" },
"value": "test",
"name": "welcome"
}
I then get a response with ID, normally indicating that the request was successfull. However, upon requesting the bot response messages, I get the following:
{
"activities": [
{
"type": "event",
"id": "5FZsHpWBxm1hjhWQYY7gr-eu|0000000",
"timestamp": "2022-04-09T14:39:15.90169Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "UnityUserId",
"name": "Unity User 1"
},
"conversation": {
"id": "5FZsHpWBxm1hjhWQYY7gr-eu"
},
"value": "test",
"name": "welcome"
}
],
"watermark": "0"
}
Indicating that the bot has no responses, which doesn't seem quite right when looking at the bot composer screenshot above. Is there something wrong with my current method?
Regards
The onMembersAdded event usually does the trick. Sample code is in https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-send-welcome-message?view=azure-bot-service-4.0&tabs=csharp
I thought I remembered seeing the bot's welcome message when using Direct Line, so I tried to quickly repro it again. I connected a simple echo bot via Direct Line. Then I created a conversation, sent a simple message, and then retrieved all activities (all via REST calls), and the bot's welcome message was indeed present in the response, as you can see in this screenshot:
Perhaps you should use these Direct Line 3.0 API reference docs as opposed to the one you linked above. I followed these steps using the basic Echo bot sample, Postman, and a bot resource in Azure for simple and easy testing, but you could use a full application if you wish.

Update message card in Teams via webhook connector

I have a build machine from which I want to post updates in Microsoft Teams. I created a webhook connector for my channel in Teams and I can send a simple POST request to the webhook url to post a message card in Teams with this json payload:
{
"#type": "MessageCard",
"#context": "http://schema.org/extensions",
"summary": "Build Status",
"sections": [{
"facts": [{
"name": "Status",
"value": "<build status>"
}]
}]
}
Now I want to update the <build status> value as the build progresses and maybe add another fact with download link when the build is finished. Is it possible to update an existing card once it is posted? It seems like a common use case to me, but I was not able to find an answer to it. There are some blogs about updating card as a result of an action, but I don't have or want to have any actions. And obviously I don't want to keep adding cards for the same build process.
Currently update card via web-hook is supported in teams. Could you please Raise a user voice
Sorry, I jumped the gun on that. It appears it isn't supported from webhooks.
https://techcommunity.microsoft.com/t5/microsoft-teams/refresh-cards-not-working-in-teams/m-p/93282

How to do downloadable file in response from the bot

Hello there :)
Challenge Skype; Bot Framework; receive downloadable files
I have an issue. My project is to ask something to the bot (using Bot Framework Emulator currently but later I will use Skype) and the bot answers with an attached image/chart.
I can display through the interface the answer and the image. However, the user cannot download this image.
How can I do that ?
There is an option in an AdaptiveCard message to be able to download the attached image thanks to a Button ?
I tried with HeroCard, ThumbnailCard, AdaptiveCard and a simple attachment but it did not solve my problem.
Thanks in advance :)
There's a couple of different ways you can go about this.
Using Cards
First, cards don't allow you to directly download an attachment. At best, they can link you to the image (or other file) you want your user to download. Example json for an Adaptive Card that can do this:
{
"type": "AdaptiveCard",
"body": [
{
"type": "Image",
"selectAction": {
"type": "Action.OpenUrl",
"url": "https://dev.botframework.com/Client/Images/ChatBot-BotFramework.png"
},
"url": "https://dev.botframework.com/Client/Images/ChatBot-BotFramework.png"
},
{
"type": "TextBlock",
"text": "This card's action will open an image"
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Open Image",
"url": "https://dev.botframework.com/Client/Images/ChatBot-BotFramework.png"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
And looks like this:
This card displays an image and includes a link for a user to open and download it. Because I added an Action.OpenUrl directly to the image, the user can click the image to open and then download it--the "Open Image" button is just to show another method.
Here's a great website for Adaptive Card Documentation, Schema, and a user-friendly Designer. Note that the Designer doesn't allow you to easily add Actions at this time. You have to manually add them in the JSON portion.
Sending Attachments
You can, however, directly send a message that includes the ability to download files.
You can define an attachment with:
const attachment = {
name: 'PDF',
contentType: 'application/pdf',
contentUrl: 'https://media.readthedocs.org/pdf/microsoftbotframework/latest/microsoftbotframework.pdf',
}
And then send it to the user with:
await step.context.sendActivity({
text: 'Attachment',
attachments: [attachment],
});
Two important notes:
This method works well for sending files. If you use an image, it will display an unclickable image. This means Adaptive Cards would be better for sending downloadable images.
Your code might use something other than step.context. This is for sending it as part of a Waterfall Dialog. You may need some other version of context.sendActivity for your bot.
If you found this answered your question, please mark it as "Answered" and I can clear it off of my support ticket tracker. Otherwise, feel free to comment and I can help you further.

Getting the email id from the Outlook REST API when sending email

I am trying to use the Microsoft Rest API to send emails on behalf of our users. When I create a message as a draft, I get back an ID that I can use in future requests for editing, deleting, viewing the full conversation (after it is sent), etc.
I do not want to save it as a draft since I have no reason to, I just want to send it directly. After it is sent, I would still like to view the full conversation. However, if I just send the email (using the /sendmail endpoint), I do not get that ID. Is there anyway to get it? Here is my request:
POST https://outlook.office.com/api/v2.0/Users/email/sendmail
{
"Message": {
"Subject": "Test",
"Importance": "Normal",
"ToRecipients": [{
"EmailAddress": {
"Address": "<email>",
"Name": "<name>"
}
}],
"Sender": {
"EmailAddress": {
"Address": "<email",
"Name": "<name>"
}
},
"Body": {
"ContentType": "HTML",
"Content": "<html>\\n<head>\\n <style>\\n p { color: red; }\\n </style> \\n</head>\\n<body>\\n <p>Test</p>\\n</body>\\n</html>\\n"
}
},
"SaveToSentItems": "true"
}
The HTTP response code is 202, the email sends, but the body is empty (no content, whatsoever).
I don't think this matters, since I can recreate this in Postman, but I am running this in Nodejs using the node-outlook package.
Emails in Exchange via REST and EWS are submitted for transport, but the actual send and subsequent save to the sent items folder are done async. This is why you don't get the id. Transport is who actually writes the email to the sent items folder, not REST.
If you really need to find the item after it has been saved to the sentItems folder, set something like the PR_SEARCH_KEY and then do a view of the sent items folder and seek to that search key value.
Also note when you save a draft, the id that you get back will be different than the id of the item in the sent items folder because the folder Id is part of the id of the item, so that id wouldn't help you anyways.
I don't know which rest api version are you using (i'm using v2.0) but i will try to explain this issue. Sorry for my english i advance.
You have 2 ways to reply a message: on the fly way or the complete way.
On the fly way
Its the easy way, just send a post request to
https://outlook.office.com/api/v2.0/me/messages/{message_id}/reply
or
https://outlook.office.com/api/v2.0/me/messages/{message_id}/replyall
and with the body
{
"Comment": "This is your message in plain text or html code"
}
and thats all.
The problem with this methos that you can only send plain text or HTML, no attachments or anything else. If that's all you need this is your best option.
The complete way
If you need to send an attachment or perform any other action you need to perform these 3 steps:
1. Create a draft from the message you want to reply
Send a post request to
https://outlook.office.com/api/v2.0/me/messages/{message_id}/createreply
This will give you an json object save the "Id" property {draft_id} of this draft for later use.
2. Update the draft
Send a patch request to
https://outlook.office.com/api/v2.0/me/messages/{draft_id}
and with the body
{
"Body": {
"ContentType": "HTML or Text",
"Content": "Your response in plain text or html"
}
}
or any other parameter you want to change.
3. Send the draft
Send a post request to
https://outlook.office.com/api/v2.0/me/messages/{draft_id}/send
And thats it.
If you need more info abut this check https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations

Api version change but docs not updated?

I've been trying to do various things through your Mail REST API today and not having much success... My project (using the api) has been running for at least a month now, but requests to your api are failing.
For example:
GET https://outlook.office365.com/EWS/OData/Me/messages (works)
GET https://outlook.office365.com/EWS/OData/Me/inbox (doesn't work)
Looking at the documentation, still says its available.
Trying to send an email using:
POST https://outlook.office365.com/EWS/OData/Me/Messages?MessageDisposition=SendAndSaveCopy also just returns 400 (Bad Request)
Any info about this?
Also, the http status codes returned are not useful at all; almost all errors return as 400's. In one instance, I didn't provide auth creds, and a 400 was returned instead of the appropriate 401. The accompanying status code detail could also be more helpful.
Thanks for the feedback and sorry for the inconvenience. We are currently deploying some non-backwards compatible changes described here, and this is causing your issues. The current set of changes including versioning support, and deploying non-backwards compatible changes won't cause issues for your app in the future. For the queries, that don't work, please use the following:
Accessing Inbox: https://outlook.office365.com/ews/odata/me/folders/inbox
Send email (new action called SendMail):
POST https://outlook.office365.com/ews/odata/me/sendmail
{
"Message":
{
"Subject": "Test message",
"Body":
{
"Content": "This is test message!"
},
"ToRecipients":
[
{ "EmailAddress": { "Address": "John#contoso.com", "Name": "John Doe" }},
{ "EmailAddress": { "Address": "Jane#fabrikam.com", "Name": "Jane Smith" }}
]
},
"SaveToSentItems": true
}
Hope this helps. We are updating the documentation to reflect the changes, and it should be available shortly. Thanks for the feedback on the HTTP status codes, we will review the status codes returned currently and make any fixes required.
Conversation support is in our roadmap but we don't yet have a timeline to share. Currently, you can search using https://outlook.office365.com/ews/odata/Folders/FolderId/Messages?$filter=ConversationId%20eq%20%%27ConversationID%27 but this will only return messages within the specified folder belonging to that conversation.
Let me know if you have any questions or need more info.
Thanks,
Venkat

Resources