【问题标题】:Conversation wont resume bot framework对话不会恢复机器人框架
【发布时间】:2017-09-10 11:42:34
【问题描述】:

我正在使用 Botframework 在 C# 中构建一个 facebook 登录对话框,但是在获取访问令牌后,它通常不会恢复对话,我不明白为什么。我正在关注这个例子:https://github.com/Microsoft/BotBuilder/tree/master/CSharp/Samples/SimpleFacebookAuthBot 但我无法继续我的谈话,我得到了这个例外:

System.InvalidOperationException

消息:由于对象的当前状态,操作无效。

当我想恢复对话时发生。

[HttpGet]
    [Route("api/OAuthCallback")]
    public async Task<HttpResponseMessage> OAuthCallback([FromUri] string userId, [FromUri] string botId, [FromUri] string conversationId, [FromUri] string channelId, [FromUri] string serviceUrl, [FromUri] string locale, [FromUri] string code, [FromUri] string state, CancellationToken token)
    {
        // Get the resumption cookie
        var address = new Address
            (
                botId: FacebookHelper.TokenDecoder(botId),
                channelId: channelId,
                userId: FacebookHelper.TokenDecoder(userId),
                conversationId: FacebookHelper.TokenDecoder(conversationId),
                serviceUrl: FacebookHelper.TokenDecoder(serviceUrl)
            );
        var resumptionCookie = new ResumptionCookie(address, userName: null, isGroup: false, locale: locale);

        var accessToken = await FacebookHelper.ExchangeCodeForAccessToken(resumptionCookie, code, FacebookAuthDialog.FacebookOauthCallback.ToString());

        // Create the message that is send to conversation to resume the login flow
        var msg = resumptionCookie.GetMessage();
        msg.Text = $"token:{accessToken.AccessToken}";

        // Resume the conversation to FacebookAuthDialog

//我在哪里得到异常

等待 Conversation.ResumeAsync(resumptionCookie, msg);

        using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, msg))
        {
            var dataBag = scope.Resolve<IBotData>();
            await dataBag.LoadAsync(token);
            ResumptionCookie pending;
            if (dataBag.PrivateConversationData.TryGetValue("persistedCookie", out pending))
            {
                // remove persisted cookie
                dataBag.PrivateConversationData.RemoveValue("persistedCookie");
                await dataBag.FlushAsync(token);
                return Request.CreateResponse("You are now logged in! Continue talking to the bot.");
            }
            else
            {
                // Callback is called with no pending message as a result the login flow cannot be resumed.
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new InvalidOperationException("Cannot resume!"));
            }
        }
    }

【问题讨论】:

    标签: c# facebook botframework


    【解决方案1】:

    此 OAuth 方法适用于旧版本的机器人框架。新版bot框架更好的解决方案和可行的是this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-05
      • 2016-04-26
      • 1970-01-01
      相关资源
      最近更新 更多