Trigger intent from API and send massage to twilio

Hi, I am trying to trigger an intent from an external API created with flask, and then send a massage back to whatsapp using twilio. In the API i am using a http request to send the message as follows:

import requests

headers = {‘Content-type’: ‘application/json’,} data = '{“sender”:“whatsapp:+57123456”, “message”:“external event has to be triggered”}

response = requests.post(‘https://04729ef77836.ngrok.io/webhooks/twilio/webhook’, headers=headers, data=data)

This is not working and I’m thinking that this is because the protocol doesn’t have all parameters such as the authentication token and sid. Do you know which parameters are necessary to specify in order for twilio to receive the message? Or is there another way to do it?

Thank you very much for yore kind help.

Hi @franciscoreales1, have you configured the Twilio connector as specified here?

@b-quachtran, Thanks for your response. The communication with twilio is working perfectly. I have already specified the SID and token to set the communication. What I don’t know is how to trigger a message from an API (external event) to RASA. I am doing the http request with the above code but only sending as parameters a sender id and the message:

“sender”:“whatsapp:+57123456”, “message”:“external event has to be triggered”

I don’t know what properties rasa needs e.g. sid, auth_token or how to specify them to simulate a message from twilio that triggers a given intent in the rasa server.

Hi @franciscoreales1, for something like that you should use Rasa’s HTTP API to inject an intent into the tracker and sends the response to the user. The spec for doing that is available here, and in the request you can specify the output_channel.

@b-quachtran, thanks!! that was really helpful, it is identifying correctly the intent (infoLink) that was injected. However the entities are not set properly. In this case when i check the entity “banco” it is set to None, which means that the entity did not change after the request. This is the request i am using:

curl -H “Content-Type: application/json” -X POST
-d ‘{“name”: “infoLink”, “entities”: {“banco”: “BANCOLOMBIA”}}’
https://localhost:5005/conversations/whatsapp:+57123456/trigger_intent?output_channel=twilio

@franciscoreales1 Can you try passing in this for the intent name: infoLink{"banco": "BANCOLOMBIA"} and see if it resolves the slot loading?

Hi @b-quachtran there was an error, seems like giving the parameter in that way is not supported

File “/home/francisco/anaconda3/envs/FACTU/lib/python3.7/site-packages/sanic/request.py”, line 177, in load_json raise InvalidUsage(“Failed when parsing body as json”) sanic.exceptions.InvalidUsage: Failed when parsing body as json