Resume Conversation after Pause

Hello!

I am trying to resume the conversation after returning ConversationPaused() from custom action. I could not find any way to resume it. Rasa Core stops listening to new messages. Is there any way that I can call Events API to update the conversation while my conversation is paused?

@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

@Arjaan

I was trying to hit the /conversations/SENDER_ID/tracker/events endpoint but for some reason I keep getting a 404 “Not found” error. I even ran rasa with the -vv flag to see what endpoints were available and this is listed in my logs. Do you know what the issue could be? Other endpoints work find for me, this one is the one giving me an error.

Here’s my code for hitting the /conversations/SENDER_ID/tracker/events endpoint:

response = requests.post("http://url/api/conversations/{}/tracker/events".format(sender_id),
json={"event": "slot", "name": "my_slot", "value": False},
headers={"Authorization": "Bearer " + auth_token})

The /conversations/SENDER_ID/tracker endpoint, however works find for me using the same code format for the above request.

Any help would be much appreciated

@Arjaan

by sending this curl request

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

i am having a error

{“version”:“1.10.1”,“status”:“failure”,“message”:“An unexpected error occurred. Error: Failed when parsing body as json”,“reason”:“ConversationError”,“details”:{},“help”:null,“code”:500}

here is the log

File “c:\users\arora\anaconda3\lib\site-packages\sanic\request.py”, line 173, in load_json self.parsed_json = loads(self.body) ValueError: Expected object or value

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File “c:\users\arora\anaconda3\lib\site-packages\rasa\server.py”, line 494, in append_events events = _get_events_from_request_body(request)

File “c:\users\arora\anaconda3\lib\site-packages\rasa\server.py”, line 508, in _get_events_from_request_body

events = request.json

File “c:\users\arora\anaconda3\lib\site-packages\sanic\request.py”, line 167, in json self.load_json()

File “c:\users\arora\anaconda3\lib\site-packages\sanic\request.py”, line 177, in load_json raise InvalidUsage(“Failed when parsing body as json”)

sanic.exceptions.InvalidUsage: Failed when parsing body as json

can you pleas help.thanks in advance

@basil-chatha,

It sounds like you have it deployed with Rasa X.

If that is the case, then you need to use this endpoint: /core/conversations/SENDER_ID/tracker/events

Nginx will route everything that starts with /core to the rasa-production container in a Rasa-X deployment.

@paras,

how are you running the rasa server ? Options are:

  1. Rasa server, locally, with rasa run
  2. Rasa container by itself, using docker run ...
  3. Within a Rasa-X deployment, using docker-compose or kubernetes/helm

@Arjaan Rasa server, locally, with rasa run -m models --enable-api --cors “*” --debug

1 Like

@Paras,

And how are you talking to the bot?

using this chat UI

@Arjaan

Thank you, however, now I’m getting a 500 error with the following logs:

rasa-production_1  | Traceback (most recent call last):
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/sanic/app.py", line 976, in handle_request
rasa-production_1  |     response = await response
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/rasa/server.py", line 160, in decorated
rasa-production_1  |     request
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/sanic_jwt/authentication.py", line 514, in is_authenticated
rasa-production_1  |     is_valid, *_ = self._verify(request)
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/sanic_jwt/authentication.py", line 371, in _verify
rasa-production_1  |     payload = self._decode(token, verify=verify)
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/sanic_jwt/authentication.py", line 184, in _decode
rasa-production_1  |     **kwargs,
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/jwt/api_jwt.py", line 92, in decode
rasa-production_1  |     jwt, key=key, algorithms=algorithms, options=options, **kwargs
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/jwt/api_jws.py", line 156, in decode
rasa-production_1  |     key, algorithms)
rasa-production_1  |   File "/opt/venv/lib/python3.7/site-packages/jwt/api_jws.py", line 216, in _verify_signature
rasa-production_1  |     raise InvalidAlgorithmError('The specified alg value is not allowed')
rasa-production_1  | jwt.exceptions.InvalidAlgorithmError: The specified alg value is not allowed

Looks like something to do with my authorization header? Do I need to authenticate in a different way than how I’m currently authenticating for other endpoints like so?

 response = requests.post("http://url/core/conversations/{}/tracker/events".format(sender_id),
json={"event": "slot", "name": "my_slot", "value": False},
headers={"Authorization": "Bearer " + auth_token})

hello,

I am facing the same issue… after sending the curl request, i get an utter_default any ideas please

@Arjaan

Does this work the same with kubernetes? I have my bot deployed with a helm chart.

I’ve tried everything, but I can’t get the conversation from paused to resumed.

@Arjaan, can you help with option 3 → Rasa-X deployment, using kubernetes/helm ?

I tried:

curl 
--request POST 
--url 'http://url/core/conversations/6986563364751623/tracker/events' 
--header 'content-type: application/json' 
--data '[{"event": "resume"}, {"event": "followup", "name": "action_resume_conversation"}]'

And that gave me:

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://url/core/conversations/6986563364751623/tracker/events">here</A>.
</BODY></HTML>

I tried:

curl 
--request POST 
--url 'http://localhost/core/conversations/6986563364751623/tracker/events' 
--header 'content-type: application/json' 
--data '[{"event": "resume"}, {"event": "followup", "name": "action_resume_conversation"}]'

And that gave me:

<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

I tried:

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

And that gave me:

curl: (7) Failed to connect to localhost port 5005: Connection refused

I tried:

curl 
--request POST 
--url 'http://localhost:8000/core/conversations/6986563364751623/tracker/events' 
--header 'content-type: application/json' 
--data '[{"event": "resume"}, {"event": "followup", "name": "action_resume_conversation"}]'

And that gave me:

curl: (7) Failed to connect to localhost port 8000: Connection refused

I also added --enable-api to the values.yml. Not sure if this is necessary.

rasa:
    extraArgs: ['--enable-api']

Still I got:

curl: (7) Failed to connect to localhost port 8000: Connection refused

@rctatman can you help?