我正在使用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
//我在哪里获得例外
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!"));
}
}
}