Toni Gallardo
Toni Gallardo

Reputation: 95

How can I get the phone number from Twilio in fulfillment dialogflow

I'm working in a whastapp bot between Twilio and Dialogflow. In one of the intents, I'm sending media files from dialogflow to the user. Here it's the problem, now it's working with my mobile number hardcoded, but I need to access to the user phone number in each case to send the media file.

I develop this in fulfillment dialogflow, inline editor, using some nodejs code, but there I can't access to the user number.

Fulfillment node js

function sendAudioMensaje(agent) {
     client.messages.create({
       body: 'Body message',
       to: 'whatsapp:+34---------',  // Text to this number
       from: 'whatsapp:+14155238886', // From a valid Twilio number
       mediaUrl: 'https://demo.twilio.com/owl.png'
     }).then((message) => agent.add(message.sid));
   }

I expect that the message would be sent to the current number in each conversation

Upvotes: 1

Views: 1168

Answers (2)

test noob
test noob

Reputation: 43

In the payload of the OriginalDetectIntent request you will see a JSON like this in the webhook if it's enabled.

{
  "source": "twilio",
  "data": {
    "SmsSid": "",
    "Body": "",
    "SmsStatus": "received",
    "MessageSid": "",
    "ApiVersion": "2010-04-01",
    "From": "",
    "AccountSid": "",
    "NumMedia": "0",
    "To": "",
    "SmsMessageSid": "",
    "NumSegments": "1"
  }
}

Upvotes: 0

philnash
philnash

Reputation: 73057

Twilio developer evangelist here.

As far as I can tell, the Dialogflow webhook request comes with a originalDetectIntentRequest property in the JSON. This contains a OriginalDetectIntentRequest object, which has a payload property that contains the original request.

I'd start by logging the contents of the webhook request to see what is fully available to you though.

Let me know if that helps at all.

Upvotes: 2

Related Questions