我正在制作一个连接到网络聊天频道的机器人。但是,对于用户输入的特定消息,我想在与我已建立连接的Directline频道上向不同用户发送消息。
我在Directline频道上有用户的id,name和conversationID,所以我尝试过这样的事情:
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);
}
但是,我收到此错误: “对不起,我的机器人代码出了问题。”我该怎么办?
答案 0 :(得分:0)
由于直接通道与来自的消息不同,您需要将其服务网址标记为可信,然后初始化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);