【发布时间】:2017-03-23 06:57:54
【问题描述】:
我正在创建一个机器人来主动与一个我以前从未与之交谈过的帐户开始对话。我创建了另一个要发布到的控制器并执行以下步骤:
public class OutboundController : ApiController {
public HttpResponseMessage Post([FromUri] int id, [FromBody] OutboundData outboundData) {
MicrosoftAppCredentials.TrustServiceUrl(outboundData.ServiceUrl);
//create conversation
var connector = new ConnectorClient(new Uri(outboundData.ServiceUrl));
var botAccount = new ChannelAccount { Id = outboundData.FromAccountId, Name = outboundData.FromAccountName };
var toAccount = new ChannelAccount { Id = outboundData.ToAccountId, Name = outboundData.ToAccountName };
if(!MicrosoftAppCredentials.IsTrustedServiceUrl(outboundData.ServiceUrl)) {
throw new Exception("service URL is not trusted!");
}
var conversationResponse = connector.Conversations.CreateDirectConversation(botAccount, toAccount);
var client = new BuslogicClient();
var confirmData = client.GetOutboundData(id);
var greetingMessage = CreateGreetingMessage(confirmData);
var convoMessage = Activity.CreateMessageActivity();
convoMessage.Text = greetingMessage;
convoMessage.From = botAccount;
convoMessage.Recipient = toAccount;
convoMessage.Conversation = new ConversationAccount(id: conversationResponse.Id);
convoMessage.Locale = "en-Us";
connector.Conversations.SendToConversationAsync((Activity)convoMessage);
string message = string.Format("I received correlationid:{0} and started conversationId:{1}", id, conversationResponse.Id);
var response = Request.CreateResponse(HttpStatusCode.OK, message);
return response;
}
当我调用 connector.Conversations.CreateDirectConversation 时,我收到以下异常:附加信息:Microsoft 应用程序 ID [ID] 的授权失败,状态码未授权,原因短语“未授权”。如果我使用 appId 和密码空白执行此操作,则通道模拟器中的一切正常。我尝试将 MicrosoftAppCredentials 提供给 ConnectorClient 的构造函数,但这没有任何影响。我在其他线程上读到必须信任服务 URL,因此我使用了 MicrosoftAppCredentials.TrustServiceUrl。
我正在使用的版本: 机器人生成器 3.5.3 频道模拟器 3.0.0.59
我的机器人的用例是向出站控制器发布一些用户信息,以创建要发送的主动消息(特别是 SMS)。如果用户对我的消息做出响应,它将被消息控制器拦截并传递给我的对话框,以便在同一频道上进行进一步处理和对话响应。
我也看过:https://github.com/Microsoft/BotBuilder/issues/2155,但不太了解 cmets 中描述的解决方案,或者它是否与我要解决的问题有关。
任何建议或帮助将不胜感激!
【问题讨论】:
-
@artem 情况有点不同,因为我没有恢复以前的传入对话。我正在发起新的对话。在您提供的链接中,有人询问了 CreateDirectConversationAsync,您回答“当然我做到了。它不起作用。显然错误与创建对话的方式无关”我想知道我是否必须将帐户发布到连接器 api数据优先,以便连接器可以完全信任对话创建。
标签: botframework