How to send Intent/Action with POST messages to REST webhook to bypass NLU and call specific Intent/Action

Hi guys,

I’m using an own written client to communicate with rasa. However I want to send instead of the default JSON-Request:

{
  "sender": "test_user",
  "message": "Hi there!"
}

a more advanced version like:

{
  "sender": "test_user",
  "message": "Hi there!",
  "intent/action": "<callIntent>/<callAction>"
}

Overall I want to call a Custom Action which is connected to an Intent, so it doesn’t matter whom would be called in first place. I’ve seen Rich Responses through Buttons which can handle this behaviour in some way but I’m tied to the Client and the User Input and no Buttons.

Does anyone of you have a clue/link to solve this problem? Appreciate your help in advance!

You can send a payload to force an intent (and entities):

{
  'sender': 'test_user',
  'message': '/greet{"name": "Darkkap"}'
}

Thanks Chris. My JSON body is now:

{
  'sender': 'test_user',
  'message': '/intentXYZ{"entityXYZ": "<UserInput>"}'
}

and for testing purposes:

{
  'sender': 'test_user',
  'message': '/intentXYZ{"<UserInput>"}'
}

but the respond in both cases is:

400: Failed when parsing body as json

This approach is just working fine:

{
  'sender': 'test_user',
  'message': '<UserInput>'
}

It seems it is not possible to bypass the NLU through POST-method or do you know another approach?

To be more clear what I want to achieve: Every time a User sends a specific string a specific Intent/Action should be called without the intent classification of rasa. So I want to tell Rasa: Hey look I’ve got this UserInput and he wants to trigger the intentXYZ, so just do what is commanded :smile:

It depends where you’re sending the message from.

It should be fine from JavaScript, but if you’re sending it via Postman for example, remember than single quotes are not valid in JSON.

Therefore, try this:

{
  "sender": "test_user",
  "message": "/intentXYZ{\"entityXYZ\": \"<UserInput>\"}"
}

Be careful, the payload ({"entityXYZ": "<UserInput>"}) should also be a valid JSON and therefore it needs double quotes too.

2 Likes

Thanks Chris! Your solution worked.

Another approach could be to inject an intent into a conversation with the path:

<yourServer>/conversations/{user_id}/trigger_intent

In this case the JSON should look like:

{
  "name": "intentXYZ",
  "entities": {
        "entityXYZ": "<UserInput>"
  }
}

For further reading see: Rasa Open Source Documentation

1 Like

I did this to some of by intents since the messages are computer generated. And then I investigated the execution time from when I send of the message to a response is received. The time in the action server for the intent is only 20% of the entire execution time. And if I run the rasa server with --debug, there is a lot of processing going on anyway.

Is there a way to exclude even more rasa server execution and just have it set the slots and doing no prediction and other things for these intents?

Could I maybe change something in the config.yml file to do that?

Thanks for any reponses Mats

Did some more test on this topic and it actually takes longer time through the rasa server using the method described in this post. I was expecting it to be faster.

When removing the intents from the nlu.yml file it does not make any difference either.

Could I use " Core request to execute a custom action" - Rasa & Rasa Pro Documentation to call the actions server directly from my front-end for computer generated intents to bypass the Rasa server?

I tried it and it took 2 seconds off my normal 5 second round trip.But still the action code takes around 1 second so there is a 2 second overhead even though the action is called this way. Some is most likely due to interfaces beween by the test program, the rasa server and and the actions server. But 2 seconds for that? And the action calls 2 internet apis and three local databases.

Hi Mats, did you find a better approach to this problem?