kordek21
kordek21

Reputation: 61

Impersonation in Microsoft Teams

I am trying to forward messages to a selected user using Microsoft Bot Framework inside Teams. The functionality works as expected inside Bot Emulator, but while testing it within my organization using Teams (with valid user id's)

messages are sent straight to the user as a Bot.

IMessageActivity newMessage = Activity.CreateMessageActivity();

newMessage.Type = ActivityTypes.Message;
newMessage.From = new ChannelAccount("Impersonated User ID", "Impersonated User Name");
newMessage.Conversation = context.Activity.Conversation;
newMessage.Recipient = new ChannelAccount("Recipient ID");
//newMessage.From.Name = "Stephane Fornaroli";
newMessage.ReplyToId = context.Activity.From.Id;
newMessage.Text = text;

await context.PostAsync(newMessage);

This also applies to channel conversations, for forwarding message into specified channel:

var messagee = JsonConvert.DeserializeObject<ConversationReference>(conversationReference).GetPostToBotMessage();
var channelData = context.Activity.ChannelData;

var message = Activity.CreateMessageActivity();

message.Text = text;
message.From = new ChannelAccount("Impersonated User ID", "Impersonated User Name");

var conversationParameters = new ConversationParameters
{
    IsGroup = true,
    ChannelData = channelData,
    Activity = (Activity)message
};
var connectorClient = new ConnectorClient(new Uri(messagee.ServiceUrl));

await connectorClient.Conversations.CreateConversationAsync(conversationParameters);

Upvotes: 1

Views: 1372

Answers (1)

Wajeed Shaikh
Wajeed Shaikh

Reputation: 3168

One option would be to use Graph API to send message using delegate permissions from user. Note that currently this API is in beta and only supports sending plain text message.

Upvotes: 2

Related Questions