Break long answers into small sentences in rasa

When Rasa answers a question, those answers may contain several lengthy sentences. This can be difficult to read. It would be nice, if we could break these paragraphs up and send the individual sentences to the user, in a delayed manner.

Is there any possible way to that?

1 Like

From within a custom action, you can call dispatcher.utter_template (or utter_message) multiple times and the user will get multiple messages even though only a single action got executed.

Not sure if we removed this, but I think you can also create multiple messages by using a double newline: "Hey how are you?\n\n I am here to help!".

Hi tmbo , i agree on first point that we can send multiple response using utter_message multiple times but your point of add “\n\n” is not working.

\n\n is adding a new line when send response back to bot but its not splitting the string in actions . Does rasa have any inbuild function which does this functionality.(other approach is also fine)

Which input / output channel are you using?

I am using socketio channel .

ah great - the socketio connector is the only connector which doesn’t have this implemented. Would be great if you can open a feature request on github. If you have a second and want to contribute to the project: this would be a great contribution :wink:

@tmbo Yeah socketio is not support for the new line character specification (\n) into the domain.yml. Could you please provide any alternative for that?

the socket io channel will be fixed and properly splits messages at \n\n after the next release

@tmbo \n\n splits the bot answers throughout separately. I want the line splitting in only one message from the bot.

Hi for bullets use “\n* line1. \n* line2” you will get output as:

  • line1
  • line2

Using \ \n (\double space\n) worked for me.


utter_message: "Hi! \ \n This is Sid"

Gives the output [in the same message] : -


This is Sid

1 Like

Hi @tmbo ,

how about adding a time delay between each of the splitted response ?

1 Like

Hello, I’d like to add a time delay between messages. Any ideas on how this can be achieved?

@asc I will encourage not to follow this approach, as user will disconnected from the chat response as it will display the response as per set delay time, rather then I will encourage you please show the response in one go and only in a small paragraph and at the end provide http link [read more…],if the message is long or covering a lot of chat screen. This is the best conversational dialogue approach to engage the user. Hope you understand my points thanks.

But for your actual query it depends on the UI you are using for displaying the messages on the chat screen.

\n\n is not working for me


domain.yml under your response

Your text you want to show( not much as it will looks odd in the small widget screen) [read more…] (]

Example from my other thread solution:

 - text: | 
       - what
       - are
       - you
       - doing
       - today 
       - ?

This will come line by line, within a few sec.

Next, separate line in one output:

  - text : " what \n
             you \n 

Do, share the text only few sentences, else customer or user will be bored. Try make a bullet points.

Good Luck! Got it?

@nik202 Thanks for your response. but it doesn’t quite solve my issue.
your first suggestion returns the sentences as bullet points, there is no delay in time between them. The second suggestion returns the response in one message separated into multiple lines.
What I am trying to do is the following:
I am building a chat-bot to provide support for a specific topic, the responses are typically very long paragraphs, I want to split a single response into separate messages that get sent to the user, is there any way I can do that without having to create multiple utterances?

@WafaaMohammed Ohh. sorry to hear that. you need to check yml format to represent messages and read my last line of previous post.

Multiple utter_messages are not working on Slack, please look at my post:

@nik202 could you also look at this please?

i am also using channel and this worked for me

dispatcher.utter_message(text=f"job : {t}  \
                                             \n level : {l} \
                                             \n type : {et} \
                                             \n location : {location} \
                                             \n deadtime : {deadline.strftime('%Y %B %d')} \
                                             \n salary : {salary}. \
                                             \n apply : {url}")