对话不会恢复机器人框架

Conversation wont resume bot framework

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

System.InvalidOperationException

Message: Operation is not valid due to the current state of the object.

当我想恢复对话时出现。

[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

//我在哪里得到异常

await 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!"));
            }
        }
    }

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