【问题标题】:How to send a message to a new channel using bot framework?如何使用机器人框架向新频道发送消息?
【发布时间】:2017-06-25 19:51:24
【问题描述】:

我正在制作一个连接到网络聊天频道的机器人。但是,对于用户输入的特定消息,我想向已与之建立连接的 Directline 频道上的其他用户发送消息。

我有 Directline 频道上用户的 ID、姓名和对话 ID,所以我尝试过这样的事情:

var msg1 = await result as Activity;       //Message from Webchat channel
IMessageActivity message = Activity.CreateMessageActivity();

message.From = new ChannelAccount(name: "Bolo", id: "bol24x7");
message.Recipient = new ChannelAccount(name: "Auto", id: "aa24x7");
message.Conversation = new ConversationAccount(id: "GxBTy2R7nDq94FEvAvBd5A");
message.ChannelId = "directline";
message.Text = "1234";

var connector3 = new ConnectorClient(new Uri("https://directline.botframework.com/"));

if (msg1.Text == "1234") {
await connector3.Conversations.SendToConversationAsync((Activity)message);
}

但是,我收到此错误: “抱歉,我的机器人代码有问题。”我能做什么?

【问题讨论】:

  • 如果我的回答对你有用,请告诉我

标签: c# botframework direct-line-botframework


【解决方案1】:

由于直达通道不同于来自一条消息的消息,您需要将其服务 url 标记为受信任,然后初始化connector3,如下所示:

MicrosoftAppCredentials.TrustServiceUrl("https://directline.botframework.com/", DateTime.Now.AddDays(1));

var account = new MicrosoftAppCredentials("MicrosoftAppId", "MicrosoftAppPassword");

var connector3 = new ConnectorClient(new Uri("https://directline.botframework.com/"), account);

【讨论】:

    猜你喜欢
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    相关资源
    最近更新 更多