【发布时间】:2017-03-16 17:11:23
【问题描述】:
我有一个基于 BotFramework 3.5 构建并作为 WebApp 托管在 Azure 上的机器人。在实现机器人需要响应用户输入的场景时,我没有遇到任何问题。然而,有必要教他按某个时间表开始对话。 为了达到这个目标,我创建了一个 WebJob,它基本上是一个简单的控制台应用程序。这是用于从机器人向用户发起消息的代码:
var botAccount = new ChannelAccount(id: from);
var userAccount = new ChannelAccount(id: to);
var conversation = new ConversationAccount(false, conversationId);
var connector = new ConnectorClient(serviceUrl);
IMessageActivity message = Activity.CreateMessageActivity();
message.From = botAccount;
message.Recipient = userAccount;
message.Conversation = conversation;
message.Text = text;
message.Locale = locale;
await connector.Conversations.SendToConversationAsync((Activity)message);
from, to, serviceUrl, conversationId - 取自之前的对话,所以我希望它们是有效的。但是在SendToConversationAsync 上抛出异常:
System.UnauthorizedAccessException: Authorization for Microsoft App ID 3a26a4d4-f75a-4feb-b3e0-37a7fa24e5fc failed with status code Unauthorized and reason phrase 'Unauthorized' ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized)
app.config 文件包含与原始机器人 API 相同的值,包括 AppId 和 AppSecret。我看到了一些关于同一主题的问题,但没有找到答案。
我错过了什么吗?从控制台应用程序代表机器人发送消息是一种有效的方法吗?
【问题讨论】:
-
你的webapp是否使用认证、授权?
-
它使用 web.config 中定义的 3 个身份验证参数(AppId、AppPassword 和 BotId)。将相同的值注入控制台应用程序
-
你能发布配置身份验证的webapp的代码吗?你如何对 webapp 进行身份验证?你在发送令牌吗?
标签: c# .net botframework azure-webjobs