Bot Framework Web 聊天令牌协议不起作用
Bot Framework Web Chat Token Protocol Not Working
Bot Framework WebChat 控件无法使用 Token 协议,如 Embed the Chat Control 文档中所述。这是我遇到问题的代码:
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 内部服务器错误
请求URL:https://webchat.botframework.com/api/conversations
错误信息:
{
"message": "An error has occurred."
}
如果我输入 'hi' 消息至:
请求URL:https://webchat.botframework.com/api/conversations/null/messages
我收到一条 403 禁止访问消息,响应为:
{
"message": "Invalid token or secret"
}
更新
上写了关于我是如何让它工作的博客
这是我们最近引入的错误,现在正在修复。
我们还有一个文档错误 -- 有两种方法可以检索令牌,另一种方法在与我们的网络聊天嵌入一起使用时效果更好。您可以 GET /api/tokens(像以前一样在 header 中使用您的秘密)而不是发布到 /api/conversations,这会创建一个对话并获得一个令牌,您将获得一个令牌但是不会开始对话。 Web 聊天控件会自行开始对话,因此这会阻止我们在控件未实际加载的情况下从机器人开始对话。 /api/tokens 电话可能会在今天晚些时候工作。
Bot Framework WebChat 控件无法使用 Token 协议,如 Embed the Chat Control 文档中所述。这是我遇到问题的代码:
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 内部服务器错误请求URL:https://webchat.botframework.com/api/conversations
错误信息:
{ "message": "An error has occurred." }
如果我输入 'hi' 消息至:
请求URL:https://webchat.botframework.com/api/conversations/null/messages
我收到一条 403 禁止访问消息,响应为:
{ "message": "Invalid token or secret" }
更新
上写了关于我是如何让它工作的博客这是我们最近引入的错误,现在正在修复。
我们还有一个文档错误 -- 有两种方法可以检索令牌,另一种方法在与我们的网络聊天嵌入一起使用时效果更好。您可以 GET /api/tokens(像以前一样在 header 中使用您的秘密)而不是发布到 /api/conversations,这会创建一个对话并获得一个令牌,您将获得一个令牌但是不会开始对话。 Web 聊天控件会自行开始对话,因此这会阻止我们在控件未实际加载的情况下从机器人开始对话。 /api/tokens 电话可能会在今天晚些时候工作。