Send attachment from teams personal chat to teams group channel using bot framework

Copper Contributor

Hi All,

I am working on the Teams bot application and we wanted to send attachments from the team personal chat to the team group channel.

We have set supportedFiles to true in the manifest file and used the connector client to send the message from personal chat to the team group channel and vice versa.

 

ConnectorClient connectorClient = new ConnectorClient(new Uri(serviceUrl), microsoftAppCredentials);

connectorClient.Conversations.SendToConversationAsync(MessageActivity);

 

Message activity contains the attachment that personal chat has attached. But at the channel side the image is not visible or wrong image path,

LimnaAdmin_0-1695051193348.png

 

 

 

16 Replies
@LimnaAdmin- Thanks for reporting your issue.
We will check this at our end and will get back to you.

 you can send a message from a bot in a Teams channel to a bot in a Teams personal chat using the Bot Connector client. To achieve this, you need to use the proactive messaging feature of the Teams platform.

Here is an example of how you can send a message from a bot in a Teams channel to a bot in a Teams personal chat using the Bot Connector client:

  1. Fetch the team roster to get the list of users in the team. You can use the Microsoft Teams API or the Bot Connector API to fetch the team roster.

  2. Iterate through the list of users and send a direct message to each user. You can use the Bot Connector API to send a direct message to a user.

Here is an example code snippet in C# that demonstrates how to send a message from a bot in a Teams channel to a bot in a Teams personal chat using the Bot Connector client:

using Microsoft.Bot.Connector;
using Microsoft.Bot.Connector.Teams;
using Microsoft.Bot.Connector.Authentication;

// Fetch the team roster
var connectorClient = new ConnectorClient(new Uri(serviceUrl), new MicrosoftAppCredentials(appId, appPassword));
var teamRoster = await connectorClient.Conversations.GetConversationMembersAsync(teamId);

// Send a direct message to each user in the team
foreach (var member in teamRoster)
{
    var conversationParameters = new ConversationParameters
    {
        Bot = new ChannelAccount { Id = botId },
        Members = new ChannelAccount[] { new ChannelAccount { Id = member.Id } },
        ChannelData = new TeamsChannelData { Tenant = new TenantInfo { Id = tenantId } }
    };

    var response = await connectorClient.Conversations.CreateConversationAsync(conversationParameters);
    var conversationId = response.Id;

    var message = Activity.CreateMessageActivity();
    message.From = new ChannelAccount { Id = botId };
    message.Conversation = new ConversationAccount { Id = conversationId };
    message.Text = "Hello from the bot in the Teams channel!";

    await connectorClient.Conversations.SendToConversationAsync(conversationId, (Activity)message);
}

In the above code, serviceUrl is the URL of the Bot Connector service, appId and appPassword are the credentials of the bot, teamId is the ID of the Teams channel, botId is the ID of the bot, and tenantId is the ID of the tenant.

Make sure to replace these placeholders with the actual values specific to your bot and Teams environment.

By using the Bot Connector client and the proactive messaging feature, you can send messages from a bot in a Teams channel to a bot in a Teams personal chat.

@Sayali-MSFT 

My requirement is for sending attachments (images/ screenshots/smiley) from team's channel to the personal chat and vice versa . (not directly attaching a png/jpeg file. Need to send the same attachment from the sender to the recipient )

 

The example shared works fine while sending message but note for attachments (images/screenhots/smiley) But while adding the attachment from user activity to teams channel activity it is throwing exception as 'Bad Request'

I want to send the screenshot from personal chat to teams channel and vice versa

 

 

var message = Activity.CreateMessageActivity();
message.From = new ChannelAccount { Id = recipient.Bot.Id };
message.Conversation = new ConversationAccount { Id = conversationId };
message.Text = "Hello from the bot in the Teams channel!";
message.Attachments =  messageActivity.Attachments; ('messageActivity' will be the sender and 'message' should be the activity send to the recepient with the attachment send from sender )

 

 

'messageActivity' will be the sender and 'message' should be the activity send to the recipient with the attachment send from sender.

 

 

@Sayali-MSFT , is there any alternative to send images as attachments from personal chat to teams channel and vice versa. 

 

Could you please look into this sample-https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-add-media-attachments?view=azure-bot-service-4.0&tabs=csharp

@Sayali-MSFT 

 

This document doesn't contain any sample by passing the same attachment from the teams sender to the recipient.

In all these samples, they are directly attaching the image address or providing the image path in the system itself.  That is working scenario which we have already tested.

This is not the user case scenario that we needed we want to send the message activity which contains the attachment from the sender to the recipient. 

@LimnaAdmin-We will check this with internal team and let you know the update.
@LimnaAdmin-Currently we do not have any update, we will let you know once we have any.

@Sayali-MSFT 

 

Is there any update on this issue? Its already one week done. Do we have any alternative way to send image attachments between personal chat and channel in teams

@LimnaAdmin-Could you please share the attachment format ,so that we can try it from our end?

@Sayali-MSFT 

 

Its clearly mentioned in the issue that we are not adding any images path directly, directly sending the image or screenshot in teams app by copy paste. It is getting automatically added in the turn context activity of bot.

 

Below are the attachment format for image attachment ,

 

LimnaAdmin_0-1697649072322.png

 

LimnaAdmin_1-1697649139165.png

 

If possible can you set up a meeting or remote session for further investigation. We are already spending weeks for a solution for this issue

@Sayali-MSFT

Can you please update anything on this issue. Is it possible or not

@LimnaAdmin -We have also checked the above scenario, got the same issue as mentioned above.
Currently, this is not the possible scenario.

Could you please help by suggesting this feature on - Microsoft Teams · Community