I'm building a facebook login dialog in C# using the Botframework but after getting the access token, it wont resume the conversation normally I dont understand why. I'm following this example: https://github.com/Microsoft/BotBuilder/tree/master/CSharp/Samples/SimpleFacebookAuthBot But I cant resume my conversation and I get this Exception:
System.InvalidOperationException
Message: Operation is not valid due to the current state of the object.
It occures when I want to resume the conversation.
[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
//WHERE I GET THE EXCEPTION
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!"));
}
}
}