Is there a way to trigger a user intent (not an action) from the code or from the API?

Hi there!

We started making use of webviews in Facebook Messenger and have Call-to-Action buttons in some of our webviews (for example, a button to “Schedule a viewing”). When a user click on this button, we want the bot to behave as if the user had said something with the intent /schedule_viewing.

I understand we can use the HTTP API to trigger an action in Rasa which works fine. However, in this case, we would like to trigger an intent for which Rasa will predict the next action depending on the rest of the story.

Right now, we are able to insert user intents in the tracker and call specific actions from a custom endpoint. However, that means doing the story logic within this custom endpoint instead of relying on the stories to do so.

Therefore:

  1. Is there a way to trigger a user intent and let Rasa predict the next actions from the API?
  2. If not, can we force Rasa to predict the next actions through the code or API? (That way, we can just insert the intent in the tracker and force Rasa to predict the next steps)

Thanks a lot for your help! Cheers, Nicolas

Would using payloads and buttons calling the intents not work for this example?

@btotharye do you mean a button showing up in our bot messages? Our use-case is to embed a button within a Facebook Messenger webview (ie: the button will be displayed outside of the bot as Facebook displays an iframe in the webview).

What about just using the http://localhost:5005/model/parse with a {"text": "hello"} and do it that way and parse the intent from it maybe?

HTTP API has more information on it, maybe something like this or equiv API commands could work for your situation. Sorry I’m not as familiar with webview.

You can send the intent payload to the same webhook as a normal message:

e.g. to http://your-domain.com/webhooks/facebook/webhook, send

{
  "message": "/schedule_viewing", 
  "sender": "your sender's id, optional or UUID"
}
2 Likes

Thanks for your answer @erohmensing! In the webhook, there is a signature validation which checks the signature set in the X-Hub-Signature (which I assume Facebook Messenger sets). What should we put in there?

hmm that’s a good question i don’t know the answer to off the top of my head. I think there are two ways to debug + find out:

  1. use chrome developer tools to inspect the network requests that get sent when you send a regular message

  2. set up ngrok (temporarily) in front of your existing bot and redirect the webhook url to the ngrok server. ngrok provides a nice UI to be able to inspect requests that come in to the server

  3. add some debugging information in the facebook webhook in the rasa code to figure out what it is checking

Thanks!

A colleague of mine found that the value is the sha1 hash of the raw payload and app secret, it shouldn’t be hard to do that. https://developers.facebook.com/docs/messenger-platform/webhook/#security

Cheers, Nicolas

@nbeuchat Intent-triggering external events (and reminders) are released now! See Releases · RasaHQ/rasa · GitHub and Responses

Hi @j.mosig, that’s great, thanks for the heads-up! We got super excited to see it pops-up in the changelogs (I’m monitoring it not to miss any update!)

We’ll be trying it out in the next days, this should cleanup quite a bit of our hacks :slight_smile:

Best, Nicolas

1 Like

Thanks, @erohmensing, This is good but we won’t get the actual user response right? In my case, I want to trigger the intent to extract some entities and store that in DB.

@sanketchavan08 what is your use case? Do you just want to parse the user message to get the intent name and entities but you don’t care about the actual conversation? If so, you can use the parse endpoint: {{protocole}}://{{url}}/model/parse which will just do the NLU pipeline on the message you pass to it. See: Rasa Open Source Documentation

@sanketchavan08 you should use the trigger_intent endpoint that Johannes mentioned! Rasa Open Source Documentation

Ok thanks. I have one more question regarding the same topic. Can I trigger action ? is there any endpoint something like “trigger_action” ?

Currently I have to trigger intent and then it triggers action. The problem is sometimes it cannot detect next action and gives default message.

next_question

  • push_next_question
    • action_next_question

Hi @sanketchavan08

There used to be an action trigger endpoint, but we removed (or deprecated) it because using it breaks your stories (they become un-learnable as Rasa cannot know when an external action might be triggered).

If you use Rasa 1.x, you can use the Mapping Policy to ensure that the triggered intent is always followed by your desired action. If you use Rasa 2.x, you can write a simple rule that does the same thing, like

- rule: React to external event
  steps:
  - intent: your_external_event
  - action: action_in_response_to_external_event

Thanks @j.mosig for replying to my question. I am working on the same thing right now.

I tried using both the versions: In the previous versions error is : “There is no mapped action for the predicted intent” or “there is no memorized action”

In the new versions: “there is no applicable rule”

I set the stories or rule correctly but rasa is not able to predict next action I want and then it performs default fallback.

I tried using both the versions: In the previous versions error is : “There is no mapped action for the predicted intent” or “there is no memorized action”

In the new versions: “there is no applicable rule”

@sanketchavan08 just to be sure, did you retrain your model after adding the mapped triggers to your domain file (Rasa 1.x) or the rule (2.x)?

Yes in the older version I am trying using mapping policy:

Domain file —>

session_config: session_expiration_time: 60 carry_over_slots_to_new_session: false intents:

  • out_of_scope
  • push_next_question: triggers: action_next_question

slots: candidate_id: type: text job_id: type: text question_id: type: text response_text: type: text

responses: utter_default:

  • text: Sorry, I didn’t understand. Could you please rephrase?

actions:

  • action_next_question

nlu —>

intent:push_next_question

  • get me next question please
  • what is the next question
  • next question please

intent:out_of_scope

  • please help with my ice cream it’s dripping
  • no wait go back i want a dripping ice cream but a cone that catches it so you can drink the ice cream later
  • i want a non dripping ice cream
  • someone call the police i think the bot died
  • show me a picture of a chicken
  • neither
  • I want french cuisine
  • i am hungry
  • restaurant
  • can i be shown a gluten free restaurant
  • i don’t care!!!
  • i do not care how are you
  • again?
  • oh wait i gave you my work email address can i change it?
  • hang on let me find it
  • stop it, i do not care!!!
  • how come?
  • I changed my mind
  • what?
  • did i break you
  • that link doesn’t work!
  • you already have that
  • this is a really frustrating experience
  • no stop
  • give me food
  • i want food
  • Can I ask you questions first?
  • is it a wasteland full of broken robot parts?
  • can we keep chatting?
  • talk to me
  • who is your favourite robot?
  • can you help me to build a bot

stories —>>

default fallback

  • out_of_scope
    • action_default_fallback

next_question

  • push_next_question
    • action_next_question

config -->>

policies:

- name: MemoizationPolicy

  • name: MappingPolicy
  • name: FallbackPolicy nlu_threshold: 0.4 core_threshold: 0.4 fallback_action_name: “action_default_fallback”

in the action file i am adding “async” before “def run(…”

Yes I did retrain multiple times. same problem

What is the output of rasa data validate? (Btw., you can use three backticks (like ```) before and after code to create a code block in this forum.)