Microsoft团队中的模拟

时间:2019-01-17 13:10:45

标签: c# botframework microsoft-teams

我正在尝试使用Teams中的Microsoft Bot Framework将消息转发给选定的用户。 该功能可以在Bot Emulator中正常运行,但是在使用Teams(具有有效用户ID)在我的组织内对其进行测试时

消息作为漫游器直接发送给用户。

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);

这也适用于频道对话,用于将消息转发到指定频道:

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);

1 个答案:

答案 0 :(得分:0)

一种选择是使用Graph API to send message并使用用户的委托权限。请注意,该API当前处于测试阶段,仅支持发送纯文本消息。