简体   繁体   中英

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.

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.

I would consider how your users will interpret the end of the conversation, and think about those scenarios and how people end conversations.

You can add code to handle resetting or the end of a conversation based on specific keywords, and by using the GlobalMessageHandler pattern.

https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/core-GlobalMessageHandlers

Also, expect users to just "hang up" / close the window once they are done.

A good set of metrics can help collect information on how people are using the bot for the owners to improve it. ie: Did interaction X lead on to expected interaction Y, or what was the last interaction we saw for this conversation... etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM