private IMessageActivity CreateFBMessage(IDialogContext context, FacebookProfile profile)
        {
            var message    = context.MakeMessage();
            var attachment = CreateFBProfileCard(profile);

            message.Attachments.Add(attachment);
            return(message);
        }
        private IMessageActivity CreateFBMessage(WaterfallStepContext context, FacebookProfile profile)
        {
            var message    = context.Context.Activity;
            var attachment = CreateFBProfileCard(profile);

            message.Attachments = new List <Attachment> {
                attachment
            };
            return(message);
        }
 private Attachment CreateFBProfileCard(FacebookProfile profile)
 {
     return(new ThumbnailCard
     {
         Title = Strings.FBLoginSuccessPrompt + " " + profile.Name,
         Images = new List <CardImage> {
             new CardImage(profile.ProfilePicture.data.url)
         },
     }.ToAttachment());
 }
 private Attachment CreateFBProfileCard(FacebookProfile profile)
 {
     return(new ThumbnailCard
     {
         Title = Strings.FBLoginSuccessPrompt + " " + profile.Name + "(" + profile.Gender + ")",
         Images = new List <CardImage> {
             new CardImage(profile.ProfilePicture.data.url)
         },
         Buttons = new List <CardAction>
         {
             new CardAction(ActionTypes.OpenUrl, Strings.FBCardButtonCaption, value: profile.link)
         }
     }.ToAttachment());
 }
        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));
        }