Forum Discussion
Send attached images in teams to another connected user or agent.
Is there any update on this. Will be able to send images to connected user or agent using bot framework ?
I also tried the below code,
IMessageActivity forwardedMessage = activity;
foreach (var attachment in activity.Attachments)
{
if (attachment.ContentType.StartsWith("image/"))
{
forwardedMessage = Activity.CreateMessageActivity();
forwardedMessage.Attachments = new List<Attachment> { attachment };
forwardedMessage.ApplyConversationReference(recipient);
}
}
and send the message activity using connector client. Got the same image invalid in recipient teams bot
Also tried to access the content url we are getting in the activity attachment , but it shows the below authorization error message
{"message":"Authorization has been denied for this request."}
We are trying to send message from teams bot personal chat to the teams groups chat.
Image was getting received at group chat side when manually edited the attachment conent url with a jpeg image .
- Sayali-MSFTSep 11, 2023
Microsoft
Lakshmi_145 -Could you please try the below code for image attachment-
Also refer the sample -Microsoft-Teams-Samples/samples/bot-file-upload/csharp/Bots/TeamsFileUploadBot.cs at main · OfficeDev/Microsoft-Teams-Samples (github.com)private async Task ProcessInlineImage(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken) { var attachment = turnContext.Activity.Attachments[0]; var client = _clientFactory.CreateClient(); // Get Bot's access token to fetch inline image. var token = await new MicrosoftAppCredentials(microsoftAppId, microsoftAppPassword).GetTokenAsync(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var responseMessage = await client.GetAsync(attachment.ContentUrl); // Save the inline image to Files directory. var filePath = Path.Combine("Files", "ImageFromUser.png"); using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None)) { await responseMessage.Content.CopyToAsync(fileStream); } // Create reply with image. var reply = MessageFactory.Text($"Attachment of {attachment.ContentType} type and size of {responseMessage.Content.Headers.ContentLength} bytes received."); reply.Attachments = new List<Attachment>() { GetInlineAttachment() }; await turnContext.SendActivityAsync(reply, cancellationToken); } private static Attachment GetInlineAttachment() { var imagePath = Path.Combine("Files", "ImageFromUser.png"); var imageData = Convert.ToBase64String(File.ReadAllBytes(imagePath)); return new Attachment { Name = @"ImageFromUser.png", ContentType = "image/png", ContentUrl = $"data:image/png;base64,{imageData}", }; }
- Lakshmi_145Sep 11, 2023Iron Contributor
Is it possible to send the images from teams bot personal chat and teams bot groups channel.
In our project we are using the connector client to send the message from personal chat to group channel and viceversa.
https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/bots-filesv4
We have referred the above document and updated supportedFiles true in manifest file . But it is also not sending the message from personal chat to group channel using connector client
- Lakshmi_145Sep 13, 2023Iron Contributor
Is there any update on this question, can we able to send message from bot teams channel to bot teams personal chat using bot connector client