从bot框架仿真器向团队发送查询,并从团队向bot框架仿真器获取回复

时间:2020-09-17 18:41:53

标签: botframework microsoft-teams

  • 我想将我的机器人模拟器连接到团队以发送查询(正在运行)
  • 一旦我们收到小组查询,则应将对查询的答复发送回机器人模拟器

我没有收到来自团队模拟器的答复

1 个答案:

答案 0 :(得分:0)

要从网络聊天连接到团队,我正在使用以下代码:

string teamsChannelId = "****************************";
string serviceUrl = "****************************";
string botClientID = "****************************";
string botClientSecret = "****************************";
MicrosoftAppCredentials.TrustServiceUrl(serviceUrl);
var connectorClient = new ConnectorClient(new Uri(serviceUrl), new MicrosoftAppCredentials(botClientID, botClientSecret));
var topLevelMessageActivity = MessageFactory.Text(saveconv);
var conversationParameters = new ConversationParameters
{
    IsGroup = true,
    ChannelData = new TeamsChannelData
    {
        Channel = new ChannelInfo(teamsChannelId),
    },
    Activity = topLevelMessageActivity
};
await connectorClient.Conversations.CreateConversationAsync(conversationParameters);

以下代码可以将Microsoft团队的响应发送到Web聊天机器人:

var userAccount = new ChannelAccount(id: "userid", name: "username", role: "user", aadObjectId: null);
var botAccount = new ChannelAccount(id: "botid", name: "botname", role: "bot", aadObjectId: null);
string botClientID = "****************************";
string botClientSecret = "****************************";
string serviceUrl = "****************************";
MicrosoftAppCredentials.TrustServiceUrl(serviceUrl);
var connector = new ConnectorClient(new Uri(serviceUrl), new MicrosoftAppCredentials(botClientID, botClientSecret));
IMessageActivity message = Activity.CreateMessageActivity();
message.ChannelId = "channelid";
message.From = botAccount;
message.Recipient = userAccount;
message.Conversation = new ConversationAccount(id: "conversationid");
message.Text = "Reply from Microsoft Teams: *" + turnContext.Activity.Text;
message.Locale = "en-us";
await connector.Conversations.SendToConversationAsync((Activity)message);