Resume Conversation after Pause

@omerraheem,

Once you paused the conversation from your custom action, you are not able to resume it from another custom action that is triggered by another intent, because the conversation is paused. The bot will start ignoring whatever you send it’s way for this particular conversation.

However, you can resume the conversation by sending this curl request to the rasa-production container. This adds the resume event to the tracker of the conversation that you paused:

curl --request POST
--url 'http://localhost:5005/conversations/SENDER_ID/tracker/events?token=RASA_TOKEN'
--header 'content-type: application/json'
--data '[{"event": "resume"}, {"event": "followup", "name": "action_resume_conversation"}]'

Two things that will help.

One, if you look closely, you can see that I send both a resume event and a followup event. The followup event is a custom action with name action_resume_conversation, which is optional, just to notify the user upon his next message entry that the conversation has resumed. This is an example:

class ActionResumeConversation(Action):
    """Just to inform the user that a conversation has resumed. 
This will execute upon next user entry after resume"""

    def name(self):
        return "action_resume_conversation"

    async def run(self, dispatcher, tracker, domain) -> List[EventType]:
        logger.info(f"Resumed the conversation")

        sender_id = tracker.sender_id

        dispatcher.utter_message(
            f"Resumed this conversation, with ID: " f"{sender_id}."
        )

        return []

Second, the curl request is sent to the paused conversation, and you need to know the SENDER_ID of that conversation. It could help if you add a message to your custom action that pauses the conversation, something like this:

class ActionPauseConversation(Action):
    """Pause a conversation"""

    def name(self):
        return "action_pause_conversation"

    async def run(self, dispatcher, tracker, domain) -> List[EventType]:
        logger.info(f"Pausing the conversation")

        sender_id = tracker.sender_id

        dispatcher.utter_message(
            f"Pausing this conversation, with SENDER_ID: " f"{sender_id}"
        )

        dispatcher.utter_message(
            f"To resume, send this resume event to the rasa-production container:"
        )

        dispatcher.utter_message(
            """curl --request POST
 --url 'http://localhost:5005/conversations/SENDER_ID/tracker/events?token=RASA_TOKEN'
 --header 'content-type: application/json'
 --data '[{"event": "resume"}, {"event": "followup", "name": "action_resume_conversation"}]'       
"""
        )

        dispatcher.utter_message(
            f"When you're running it within Rasa X, send this resume event to the rasa-production container via the Rasa X /core/... endpoint:"
        )

        dispatcher.utter_message(
            """curl --request POST
 --url 'http://HOST:PORT/core/conversations/SENDER_ID/tracker/events?token=RASA_TOKEN'
 --header 'content-type: application/json'
 --data '[{"event": "resume"}, {"event": "followup", "name": "action_resume_conversation"}]'       
"""
        )

        return [ConversationPaused()]

And a final comment is that you need to add these type of stories to get robust predictions of the next actions:

## greet with pause & resume & greet
* greet
  - utter_greet
* pause_conversation
  - action_pause_conversation
  - action_resume_conversation
* greet
  - utter_greet

Note that you do not need to add pause and resume into the stories, because those events do not influence the prediction of the next bot action.

4 Likes