【发布时间】:2016-04-08 06:08:17
【问题描述】:
如Embed the Chat Control 文档中所述,Bot Framework WebChat 控件无法使用令牌协议。这是我遇到问题的代码:
string webChatSecret = ConfigurationManager.AppSettings["WebChatSecret"];
var request = new HttpRequestMessage(HttpMethod.Post, "https://webchat.botframework.com/api/conversations");
request.Headers.Add("Authorization", "BOTCONNECTOR " + webChatSecret);
HttpResponseMessage response = await new HttpClient().SendAsync(request);
string responseJson = await response.Content.ReadAsStringAsync();
WebChatTokenResponse webChatResponse = JsonConvert.DeserializeObject<WebChatTokenResponse>(responseJson);
return $"<iframe width='400px' height='400px' src='https://webchat.botframework.com/embed/PigLatinBotJoeMayo?t={webChatResponse.Token}'></iframe>";
WebChatTokenResponse 是
public class WebChatTokenResponse
{
public string ConversationID { get; set; }
public string Token { get; set; }
}
当我调试并遇到断点时,我确实有一个 ConversationID 和一个令牌。没有抛出异常。
如果我像这样使用秘密(而不是上面的代码,一切正常:
string webChatSecret = ConfigurationManager.AppSettings["WebChatSecret"];
return $"<iframe width='400px' height='400px' src='https://webchat.botframework.com/embed/PigLatinBotJoeMayo?s={webChatSecret}'></iframe>";
以下是我在使用 F12 工具时看到的错误消息:
我在
上看到 500 内部服务器错误请求网址:https://webchat.botframework.com/api/conversations
带有错误信息:
{ "message": "发生错误。" }
如果我输入“嗨”消息:
请求网址:https://webchat.botframework.com/api/conversations/null/messages
我收到 403 Forbidden 消息和响应:
{ "message": "无效的令牌或秘密" }
更新
我在 Using the Bot Framework Chat Control 上写了一篇关于我是如何完成这项工作的博客。
【问题讨论】:
标签: botframework