Bot Framework Web聊天令牌协议不起作用 [英] Bot Framework Web Chat Token Protocol Not Working

查看:68
本文介绍了Bot Framework Web聊天令牌协议不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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":发生错误." }

如果我输入"hi"消息至:

请求网址: https://webchat.botframework.com/api/conversations/null/messages

我收到一条403 Forbidden消息,并显示以下响应:

{ "message":无效的令牌或机密" }

更新

我在解决方案

这是我们最近引入的错误,现已修复.

我们还有一个文档错误-有两种方法来检索令牌,而另一种方法与我们的网络聊天嵌入一起使用时会更好.无需发布到/api/conversations即可创建对话并获取令牌,而是只需获取/api/tokens(像以前一样在标头中包含您的机密),您将获得令牌但不会启动对话.网络聊天控件自行完成启动对话的工作,因此,如果控件未实际加载,这将阻止我们从机器人启动对话./api/tokens调用可能会在今天晚些时候开始工作.

The Bot Framework WebChat control isn't working with the Token protocol, as described in the Embed the Chat Control docs. Here's the code I'm having trouble with:

        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>";

the WebChatTokenResponse is

public class WebChatTokenResponse
{
    public string ConversationID { get; set; }

    public string Token { get; set; }
}

When I debug and hit a breakpoint, I do have a ConversationID and a Token. No exceptions are being thrown.

If I just use the secret, like this (instead of the code above, everything works:

        string webChatSecret = ConfigurationManager.AppSettings["WebChatSecret"];
        return $"<iframe width='400px' height='400px' src='https://webchat.botframework.com/embed/PigLatinBotJoeMayo?s={webChatSecret}'></iframe>";

Here are the error messages I'm seeing with F12 tools:

I'm seeing a 500 Internal Server Error on

Request URL: https://webchat.botframework.com/api/conversations

with the error message:

{ "message": "An error has occurred." }

If I enter a 'hi' message to:

Request URL: https://webchat.botframework.com/api/conversations/null/messages

I receive a 403 Forbidden message with the response:

{ "message": "Invalid token or secret" }

Update

I blogged about how I got this working at Using the Bot Framework Chat Control.

解决方案

This is a bug we recently introduced and are fixing now.

We also have a doc bug -- there are two ways to retrieve a token and the other way will work better when used with our web chat embed. Instead of POSTing to /api/conversations, which creates a conversation and gets a token, you can just GET /api/tokens (with your secret in the header like before) and you'll get a token but won't start a conversation. The web chat control does the work of starting the conversation on its own, so this prevents us from starting conversations from the bot in the event the control isn't actually loaded. The /api/tokens call will be working likely later today.

这篇关于Bot Framework Web聊天令牌协议不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆