Restart the conversation when the user leaves the conversation and joins it later.

In Skype or Facebook, when a user goes offline at a request or form flow (don't know about the rest) and joins it later, the user is forced to provide input for the last dialog stack he / she was left with; regardless of type (selection, text, etc.). For example, if a user leaves a "Yes" or "No" prompt and joins later, they are forced to answer "Yes" or "No" ("Invitations").

Is it possible to somehow reset the conversation, no matter where the user was on the conversation stack, when the user goes back online? (Probably a way to know the user is connected / online on Facebook and Skype, and reset?). It would be great if this reset can happen without user input of something like "quit" to actually trigger the reset. (proactive message?)

If the above solution is not possible, I have the following solution where the user can enter "quit" and it will start over from the beginning. It works on the emulator, but not on Skype and Facebook. My code looks like this:

if (activity.Text.ToString() == "quit")
            {
                BotData oldActivityData = activity.GetStateClient().BotState.GetUserData(activity.ChannelId, activity.From.Id);
                activity.GetStateClient().BotState.DeleteStateForUser(activity.ChannelId, activity.From.Id);
                activity.GetStateClient().BotState.SetUserData(activity.ChannelId, activity.From.Id, oldActivityData);
                await Conversation.SendAsync(activity, () => new RootDialog());
            }
            else
            {
                // Typing indicator                    
                var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                Activity isTypingReply = activity.CreateReply();
                isTypingReply.Type = ActivityTypes.Typing;
                await connector.Conversations.ReplyToActivityAsync(isTypingReply);

                // Sending the message to the dialog respective stack
                await Conversation.SendAsync(activity, () => new RootDialog());
            }

      

This works great on an emulator. I can type "quit" from anywhere in the dialog (prompts, form flows, etc.) and that brings me to my first question. But on Skype / Facebook, when I enter "quit", nothing happens. Then I need to send the message again (can be anything other than "quit") to start the conversation from the beginning.

So, any ideas for a user initiated user w70> and a user initiated session reset?

Update 1: with codes displaying my MessageController and PromptDialogs

MessageController:

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
    {
        if (activity.Type == ActivityTypes.Message)
        {
            if (listOfResetMessages.Contains(activity.Text.ToString().ToLower().Trim(' ')))
            {
                BotData oldActivityData = activity.GetStateClient().BotState.GetUserData(activity.ChannelId, activity.From.Id);
                activity.GetStateClient().BotState.DeleteStateForUser(activity.ChannelId, activity.From.Id);
                activity.GetStateClient().BotState.SetUserData(activity.ChannelId, activity.From.Id, oldActivityData);
                await connector.Conversations.ReplyToActivityAsync(newConvoMessage);
                await Conversation.SendAsync(activity, () => new RootDialog());
            }
            else
            {
                // Typing indicator                    
                var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                Activity isTypingReply = activity.CreateReply();
                isTypingReply.Type = ActivityTypes.Typing;
                await connector.Conversations.ReplyToActivityAsync(isTypingReply);

                // Sending the message to the dialog respective stack
                await Conversation.SendAsync(activity, () => new RootDialog());
            }
        }
        else
        {
            await this.HandleSystemMessage(activity);
        }

        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
    }

      

Sample tip (just like any other tip still posted):

public async Task StartAsync(IDialogContext context)
    {
         PromptDialog.Choice(context, this.NextFunction, new List<string>() { Constants.YES, Constants.NO }, "This is my question");
    }

    private async Task NextFunction(IDialogContext context, IAwaitable<string> result)
    {
        var optionSelected = await result;

        switch (optionSelected)
        {
            case Constants.YES:
                // Do whatever
                break;
            case Constants.NO:
                // Do whatever
                break;
        }
    }

      

Update 2: To keep the client unaware of the problem, I used a post to provoke how the client would enter the second message to reset.

if (activity.Text.ToString().ToLower().Trim(' ') == "quit")
            {
                BotData oldActivityData = activity.GetStateClient().BotState.GetUserData(activity.ChannelId, activity.From.Id);
                activity.GetStateClient().BotState.DeleteStateForUser(activity.ChannelId, activity.From.Id);
                activity.GetStateClient().BotState.SetUserData(activity.ChannelId, activity.From.Id, oldActivityData);
                var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                Activity newConvoMessage = activity.CreateReply();
                newConvoMessage.Text = "You have just quit. Say 'Hello' to start a new conversation!";
                await connector.Conversations.ReplyToActivityAsync(newConvoMessage);
                await Conversation.SendAsync(activity, () => new RootDialog());
            }

      

This does not solve the problem as the user needs to go back to the Internet and enter "quit" first. (This means the user should be aware of the "quit" command).

+3


source to share


1 answer


The reason this works in the emulator but not in other channels is because in the emulator you can actually leave the channel. In Skype / Facebook, conversations are saved even when they are not logged in. The only way to leave a conversation on Skype, for example, is to delete the bot and add it again.

Perhaps instead of asking the user to enter something, you can use a timer. The stream will work like this:



  • Received message
  • Mark
  • start timer
  • After x minute is over, if no other answer
  • User enters any beginning of a message
0


source







All Articles