Formatting bot response with newline etc

Is it possible to apply formatting to bot responses that comes from custom actions? I can’t figure out how to do things like linebreak, bold, italic, bullets, when the response comes form python code.

I’m also looking for documentation on the formatting syntax for Rasa X.

In the UI I can format the test with this markdown-like syntax:

Rasa X also creates this prefix on longer messages: text: |- and text: >-, but I don’t know what they do.

1 Like

Hello @Krogsager,

I’m not sure what you mean by responses that come from custom actions, but i will try to answer in 2 situations:

Situation 1: Responses are constructed with Python string in custom actions

Just format the response with new line character ‘\n’ or tab character ‘\t’. You can use the format function of Python string to make it easier with variables, e.g: “This is what {} ordered:\n \t- {}\n \t-{}\n”.format(name, item1, item2) results in something like:

This is what Fuih ordered:
    - Playstation 4
    - Nintendo switch

Situation 2: Responses are defined as template in domain.yml

You can use the character ‘|’ to indicate that every line in the template will be append the new line character (this is yaml format).

text: |
        This is what {name} ordered:
        - {item1}
        - {item2}

This results in:

This is what Fuih ordered:
- Playstation 4
- Nintendo switch

Unfortunately i don’t remember how can you create tab character in yaml.

1 Like

Is the same possible in custom actions? E.g.:

def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
    #[...] some logic
    message = f"hello {username}! \n\n" #\n does not produce new line
    message = message + f" todays opening-hours are: {hours}"

    return []

There is no line break with \n when I test in rasa x shareable client. Maybe it works in other chat clients. image

PS. I found that I get tab/indentation in yaml using 2 spaces:

This is what Fuih ordered:
  - Playstation 4
  - Nintendo switch

Nice :wink:

That’s weird. I used Rasa X client before and the new line character ‘\n’ worked normally back then. Is it the same with the “Talk to your bot” tab ? I have never tried the share client, wonder if they are the same.

Edit: \n works! but \n\n does not work! I’m submitting a bug report later…

Yes, from that tab the formatting is the same. Line-break is missing.

how does \n work. Can you tell me

Edit: I realised that the responses are saved in a .yaml file, so thats it. TL:DR, for new lines use \n in custom actions and the yaml markdown formatting in rasa x. But it might not work for everything.

I’m still looking for the documentation of the syntax for editing responses. Anyone?

@Krogsager, Did you file a bug report on the \n\n issue?

I looked for it in github but couldn’t find one, so I must have forgotten to do it ¯\ _(ツ)_/¯

Thanks for checking!

any body got the answer? for me \n in domain.yml responses not working, it just shows /n


If you are using custom actions, the sentence first line \n\n second line will be displayed in two different messages, if you wish to display them in the same message but in the different lines, do the following first line \n \n second line


it is not working for me. my code in :

 while j<count:
     msg= "part1:" + str(data(j)) + '\n' \
          "part2:" + str(data(j)) 
 part2: xyz

but expected output is:

(line space need here)

i tried: 1.\n 2.\r\n 3.\n \n. these splitting into two parts. i want in single part with line space between two parameters.

Hey @Krogsager , did you find the documentation on editing responses?