我正在尝试使用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);