Reputation: 119
Iam using an Outgoing webhook in teams to send text's as well as attachments/Images to an custom webservice. Iam getting the text message data inside the webservice, but i dont get the image data or any attachments when send from teams (Outgoing webhook)
Is it supported? If not any workaround?
Upvotes: 2
Views: 744
Reputation: 509
The actual card JSON attachment is not sent to the webhook. This is similar to bot scenario.
For images, if user attaches an image, it is parsed by the Bot back-end and converted into img tag, and this should be available in the content as HTML in one of the attachment object. The image itself is stored in AMS (a Teams back-end store) and the source URL also will represent the AMS URL, not the original one. Sample image sent by user:
img height=\"142\" src=\"https://us-api.asm.skype.com/v1/objects/0-eus-d1-abe032166f0b806fe9cb17411e42678f/views/imgo\" width=\"336\" id=\"x_0-eus-d1-abe032166f0b806fe9cb17411e42678f\" itemscope=\"\" itemtype=\"http://schema.skype.com/AMSImage\" style=\"vertical-align:bottom; width:336px; height:142px\">
You should be able to download the image using MicrosoftAppCredential. Sample code:
using (HttpClient httpClient = new HttpClient())
{
// MS Teams attachment URLs are secured by a JwtToken, so we need to pass the token from our bot.
var token = await new MicrosoftAppCredentials("id", "password").GetTokenAsync();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var responseMessage = await httpClient.GetAsync(imageUrl);
var contentLenghtBytes = responseMessage.Content.Headers.ContentLength;
// You could not use this response message to fetch the image for further processing.
if (responseMessage.StatusCode == System.Net.HttpStatusCode.Accepted)
{
Stream attachmentStream = await responseMessage.Content.ReadAsStreamAsync();
attachmentStream.Position = 0;
System.Drawing.Image image = System.Drawing.Image.FromStream(attachmentStream);
image.Save(@"ImageFromUser.png");
}
}
Upvotes: 1