Search code examples
rasa-nlurasa-core

Purpose of on_new_message in RASA


What is the function of on_new_message and how is it callable in Rasa?

I was trying to create an output channel and found on_new_message function. I am able to create the channel but still wondering what is it doing in Background.


Solution

  • If you want to create an OutputChannel there is no on_new_message function. The on_new_message function is a callback which gets passed to your InputChannel. You use it to pass the received message to Rasa Core after you have parsed it. A typical workflow might be:

    1. Start Rasa Core which sets your custom InputChannel up.
    2. A user writes a message within an app (e.g. Slack, Telegram)
    3. The app (e.g. Slack, Telegram) forwards this message by calling the endpoint of your InputChannel
    4. You parse the message
    5. You pass the content of the message to Rasa Core by calling on_new_message
    6. You either return the bots answer directly (see RestInput as an example) or you use a separate OutputChannel for that (see class SlackBot for an example)

    The documentation of Rasa Core has also a section on how to create custom channels: Creating a new Channel