Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bot Framework: How to exit Conversation?

so right now I'm using Microsoft.Bot.Builder.Dialogs.Conversation.SendAsync and Microsoft.Bot.Builder.Dialogs.Conversation.ResumeAsync to implement a way to pause and resume conversation but it seems impossible to 'exit' or go back to the previous state. It's stuck in the conversation dialog.

Do I just implement a 'Cancel' command? If so, what data do I need to clear so that it will be back to the original state?

    public static readonly IDialog<string> dialog = Chain
        .PostToChain()
        .Switch(
            new Case<Message, IDialog<string>>((msg) =>
            {
                var regex = new Regex("login", RegexOptions.IgnoreCase);
                return regex.IsMatch(msg.Text);
            }, (ctx, msg) =>
            {
                return Chain.ContinueWith(new ChatDialog(msg),
                            async (context, res) =>
                            {
                                var token = await res;
                                //var valid = await Helpers.ValidateAccessToken(token);
                                //var name = await Helpers.GetProfileName(token);
                                var name = "User";
                                context.UserData.SetValue("name", name);
                                return Chain.Return($"You are logged in as: {name}");
                            });
            })
        ).Unwrap().PostToUser();

so if I send a 'login' it will go and start a new ChatDialog conversation but it seems to get stuck in this state. Even if I try to send another command, it will keep asking for login. Do I implement another Case class to handle a 'Cancel' command? Or should it automatically cancel the conversation when the user sends the same 'login' command more than once? Seems kinda clunky to have to send a 'cancel' command separately.

like image 856
user299709 Avatar asked May 09 '16 21:05

user299709


1 Answers

I think you are missing the DefaultCase. Check this. It shows the implementation of the DefaultCase for the Facebook Auth Sample. BTW, in that sample they also have a Logout command.

like image 71
Ezequiel Jadib Avatar answered Nov 03 '22 04:11

Ezequiel Jadib