public async virtual Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument) { var msg = await(argument); ConversationReference conversationReference; FacebookAcessToken facebookToken = new FacebookAcessToken(); string magicNumber = string.Empty; string token = string.Empty; if (context.PrivateConversationData.TryGetValue("persistedCookie", out conversationReference)) { magicNumber = conversationReference.User.Properties[ConfigurationManager.AppSettings["FBMagicNumberKey"].ToString()].ToString(); if (string.Equals(msg.Text, magicNumber)) { conversationReference.User.Properties[ConfigurationManager.AppSettings["FBIsValidatedKey"].ToString()] = true; context.PrivateConversationData.SetValue("persistedCookie", conversationReference); token = conversationReference.User.Properties[ConfigurationManager.AppSettings["FBAccessTokenKey"].ToString()].ToString(); var valid = await FacebookHelpers.ValidateAccessToken(token); if (valid) { FacebookProfile profile = await FacebookHelpers.GetFacebookProfileName(token); var message = CreateFBMessage(context, profile); await context.PostAsync(message); await context.PostAsync(Strings.FBLginSuccessPromptLogoutInfo); context.PrivateConversationData.SetValue(AuthTokenKey, token); context.Done(token); } } else { //When entered number is not valid await context.PostAsync(Strings.AuthMagicNumberNotMacthed); await LogIn(context); } } else { await LogIn(context); } }
private async Task <DialogTurnResult> LoginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // Getting the token from the previous step. var tokenResponse = (TokenResponse)stepContext.Result; if (tokenResponse?.Token != null) { // Getting basic facebook profile details. FacebookProfile profile = await FacebookHelpers.GetFacebookProfileName(tokenResponse.Token); var message = CreateFBMessage(stepContext, profile); await stepContext.Context.SendActivityAsync(message); return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = MessageFactory.Text("Would you like to view your token?") }, cancellationToken)); } await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken); return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken)); }