Utter while processing custom action

Hey everyone!

I was wondering if it’s possible to utter something while a request is processing. For example, if the user asks a question that goes to a custom action, is it possible to utter “Give me a second to search that for you…”, perform the HTTP request and when the results are obtained, utter the result (all within the same custom action?).

I tried to use dispatcher.utter_message twice but it only prints after everything is done.

Thank you!

Hi,

You can do this in the stories. Something like this:

* Intent
  - utter_wait
  - action_Your_customAction

Define utter_wait in your templates in domail.yml as Give me a second to search that for you…. When the intent is identified, it will utter_wait and then trigger your custom action.

Thank you a lot for the suggestion! Although that solves part of the problem, it doesn’t really solve sending multiple wait messages before the final result is delivered, however I’ll accept the answer if no other alternative exists.

Actually I’ve just tried this approach and it still only sends the messages after everything is done…

Oh, it should send it before the action. Is it uttering once the action is executed?

Hi @wassgha,

is it necessary to wait for the HTTP request to return in the custom action? If not I would suggest to enter the custom action, utter via dispatcher, start the request either in a new thread or with asyncio and return the custom action.

Regards

Hmm but how would you utter the result of the HTTP request afterwards?

@srikar_1996 it should but surprisingly it doesn’t, even though they are two separate actions

Hi @wassgha

this is why I asked for the necessity to wait for the request. It could have been the case that it is a fire-and-forget process and then you could have done it my way. Unfortunately, Python handles things synchronously - so no, you can’t simply utter something this way.

Regards

Hi guys, @JulianGerhard

rasa 2.x has CallbackInput. I have not tried it yet. but will the messages be uttered synchronously using this ?

@wassgha Hi. I have tested CallbackInput in rasa 2.X. and it sends dispatcher.utter_message() synchronously