Utter template immediately

In an action, dispatcher.utter_template does not utter the template immediately. It only dispatches at the end of the action. How can I force the bot to say a utter before the action is complete?

The reason why I want to force the bot to say something right away is that I want it to say something while it is calling an external API (which takes a while). In this way, the user at least has some feedback that the bot received a message

Thank you

Currently, we do not support something like this. All messages are uttered once the action is complete.

However, you could maybe split up the action. Let’s say your action is called action_make_request. Can’t you do something like

* some_trigger_intent
- utter_might_take_a_while
- action_make_request

So you basically first perform an action to utter that the following request might take a while and then the actual action is performed. Does that work for you?

Hi @Tanja,

I recently read the chapter about Proactively Reach Out to the User either by calling a POST request to the endpoint or using the CallbackInput.

Couldn’t that be a solution to use inside an action before actually executing the long running function if someone doesn’t want to model the case inside the stories? I am asking because I didn’t try that function yet but it may become important.

Regards Julian

Hi @JulianGerhard, thanks for pointing that out! Did not thought about that, but I guess you are right. It should work.

Thank you both! I’ll try this and get back to you :slight_smile:

Ok so basically I tried with the Callback input but I’m not receiving the first message (“let’s see what options…”) in my application. I think the reason is because it is creating a tracker. How do I avoid this?

Creating a new tracker for id 'default'.
2019-11-08 12:15:18 DEBUG    rasa.core.tracker_store  - Recreating tracker for id 'default'
2019-11-08 12:15:18 DEBUG    rasa.core.processor  - Action 'utter_options_available' ended with events '['BotUttered(text: Let\'s see what options we have available, data: {"elements": null, "quick_replies": null, "buttons": null, "attachment": "default", "image": "default", "custom": null}, metadata: {})']'
2019-11-08 12:15:18 DEBUG    rasa.core.lock_store  - Deleted lock for conversation 'default'.
2019-11-08 12:15:18 DEBUG    rasa.core.tracker_store  - Recreating tracker for id 'default'
2019-11-08 12:15:20 DEBUG    rasa.core.processor  - Action 'book_form' ended with events '['BotUttered(text: (....)']'

My application receives bot message by sending a post request to rasa with the user message.

@JulianGerhard @Tanja

Can you help me please?

If there is no tracker yet, Rasa will create one. This is a normal process. We need the tracker to keep track of all the incoming and outgoing messages.

Is there any error? Can you please paste the full log here?

2019-11-12 10:15:47 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, {}, {'intent_book': 1.0, 'prev_action_listen': 1.0, 'entity_location': 1.0}]
2019-11-12 10:15:47 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2019-11-12 10:15:47 DEBUG    rasa.core.policies.mapping_policy  - There is no mapped action for the predicted intent, 'give_cabin_class'.
2019-11-12 10:15:47 DEBUG    rasa.core.policies.form_policy  - There is an active form 'book_form'
2019-11-12 10:15:47 DEBUG    rasa.core.policies.two_stage_fallback  - NLU confidence threshold met, confidence of fallback action set to core threshold (0.3).
2019-11-12 10:15:47 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_3_FormPolicy
2019-11-12 10:15:47 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2019-11-12 10:15:47 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'
2019-11-12 10:15:47 DEBUG    rasa.core.lock_store  - Deleted lock for conversation '123'.
2019-11-12 10:15:53 DEBUG    rasa.core.tracker_store  - Recreating tracker for id '123'
2019-11-12 10:15:53 WARNING  root  - Could not parse timestamp 6bd9a488f5eb4e6eb0fb89a86a7026e7. Instead current UTC time will be passed to duckling. Error: invalid literal for int() with base 10: '6bd9a488f5eb4e6eb0fb89a86a7026e7'
2019-11-12 10:15:53 DEBUG    rasa.core.processor  - Received user message 'arrive faster' with intent '{'name': 'arrive_fast', 'confidence': 0.9331502318382263}' and entities '[]'
2019-11-12 10:15:53 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 101 events
2019-11-12 10:15:53 DEBUG    rasa.core.policies.memoization  - Current tracker state [None, None, None, {}, {'intent_book': 1.0, 'prev_action_listen': 1.0, 'entity_location': 1.0}]
2019-11-12 10:15:53 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2019-11-12 10:15:53 DEBUG    rasa.core.policies.form_policy  - There is an active form 'book_form'
2019-11-12 10:15:53 DEBUG    rasa.core.policies.two_stage_fallback  - NLU confidence threshold met, confidence of fallback action set to core threshold (0.3).
2019-11-12 10:15:53 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_3_FormPolicy
2019-11-12 10:15:53 DEBUG    rasa.core.processor  - Predicted next action 'book_form' with confidence 1.00.
2019-11-12 10:15:53 DEBUG    rasa.core.actions.action  - Calling action endpoint to run action 'book_form'.
2019-11-12 10:15:53 DEBUG    rasa.core.tracker_store  - Creating a new tracker for id 'default'.
2019-11-12 10:15:53 DEBUG    rasa.core.tracker_store  - Recreating tracker for id 'default'
2019-11-12 10:15:53 DEBUG    rasa.core.processor  - Action 'utter_options_available' ended with events '['BotUttered(text: Let\'s see what options we have available, data: {"elements": null, "quick_replies": null, "buttons": null, "attachment": "default", "image": "default", "custom": null}, metadata: {})']'
2019-11-12 10:15:53 DEBUG    rasa.core.lock_store  - Deleted lock for conversation 'default'.
2019-11-12 10:15:53 DEBUG    rasa.core.tracker_store  - Recreating tracker for id 'default'
2019-11-12 10:15:56 DEBUG    rasa.core.processor  - Action 'book__form' ended with events '['BotUttered(text: .........']'

This is the only time in the middle of the conversation where it creates a new tracker.

My POST request looks like this:

    def say_options_available(self):
    headers = {
        'Content-Type': 'application/json',
    }

    data = '{"name":"utter_options_available"}'
    response = requests.post('http://localhost:5005/conversations/default/execute', headers=headers, data=data)

    print(response)

Hi @teresalazar13,

if I am not wrong, you need to use the right conversation_id - otherwise it would create the new (mentioned) tracker. You execute:

http://localhost:5005/conversations/default/execute

which means that the conversation_id is default (maybe you got that from the example).

If am right, you already have however created a tracker:

2019-11-12 10:15:47 DEBUG rasa.core.lock_store - Deleted lock for conversation '123'.

Can you please try to send the POST request to the “running” conversation and see if your expected behaviour happens?

Regards Julian

Thank you @JulianGerhard

If I change the POST request to:

    def say_options_available(self):
    headers = {
        'Content-Type': 'application/json',
    }

    data = '{"name":"utter_options_available"}'
    response = requests.post('http://localhost:5005/conversations/123/execute', headers=headers, data=data)

    print(response)

I get errors saying:

2019-11-14 14:13:48 DEBUG rasa.core.lock_store - Failed to acquire lock for conversation ID ‘123’. Retrying… 2019-11-14 14:13:49 DEBUG rasa.core.lock_store - Failed to acquire lock for conversation ID ‘123’. Retrying…

Can you help me please?

This error makes sense. You cannot modify a conversation (by sending a message to the user) when you are currently already modifying the same conversation (through the custom action). Same as @Tanja I’d suggest to

  • split your actions or
  • run the api request asynchronously and return the “message received” notification with the custom action

How do I split the actions if this is a slot of a FormAction?

How are you currently running your (long-running) backend request to retrieve the information?

In a loop I:

  • record the user message
  • send the message to RASA with a POST request (/webhooks/rest/webhook)
  • parse the bot message and display it to the user

I can’t record and receive the bot message at the same time

@Tobias_Wochinger “run the api request asynchronously and return the “message received” notification with the custom action” -> how/where do I return the message notification with the custom action? In my backend application or in rasa itself?

Thank you

In a loop I:

  • record the user message
  • send the message to RASA with a POST request (/webhooks/rest/webhook)
  • parse the bot message and display it to the user

But how would “responding immediately” then work? Rasa would be required to return multiple responses to your POST request?

You want to do this, right?

  1. Send message to Rasa via REST channel
  2. Message triggers custom action
  3. Rasa forwards message to action server
  4. Action server starts running an action and notifies user that it started some backend request
  5. Action finishes and returns the result of the backend request
  6. Rasa returns the action server result to the user
1 Like

Yes, that’s right!