-1

We are setting up a chat bot through Dialogflow. A user will receive a weblink to the bot in a call or SMS sent through twilio. I'm wondering if it is possible for us to set up an HTTP get request to twilio in fulfillment so that we can set a context parameter to the user's phone number in the fulfillment inline editor in Dialogflow.

I took a look at twilio's api docs but could only find information on HTTP requests regarding numbers purchased or available for purchase through twilio.

So to clarify: in Dialogflow's fulfillment inline editor, we want to set a context parameter equal to the user's phone number that twilio called or sent the SMS to with a weblink to our chat bot.

Thanks!

Nahuel Varela
  • 1,022
  • 7
  • 17
mdb
  • 229
  • 5
  • 16
  • I'm not clear on what you're asking here. What do you want the HTTP request to Twilio achieve? – philnash Dec 19 '18 at 07:02
  • Hi Phil, I want to get the phone number of the user who received a url to our bot that was sent by SMS or phone call through Twilio. The chatbot is for real estate - the user expresses interest in a house, and the agency will send them a weblink to our chatbot to their phone by text or call with Twilio. We might not need an HTTP request - I'm new to working with twilio so I'm just looking for some input on how to get that phone number into Dialogflow – mdb Dec 19 '18 at 17:05

1 Answers1

0

Twilio developer evangelist here.

If I'm understanding right, you want to send a URL to a user via SMS (or over the phone?) which will link them to a web based chat with your bot. And you want to be able to link that chat back to the original phone number?

If that is the case, then the first thing that comes to mind for me would be to create a unique URL for each phone number you send this message to. If you store a link between the URL and the number it is sent to in a database somewhere, then when th euser clicks through to it you can recover the phone number and apply it to your Dialogflow context.

I don't believe you need to make any requests to the Twilio API for this aside from sending the initial SMS.

I hope this helps.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Hey Phil, thanks for sticking with me to try to figure this out. We already have Twilio sending the weblink to the user's phone number in a text or voice call. I'll take a look at our Twilio dash to see if we're making unique URLs for each phone number. Would I be able to reference this URL in a HTTP request or something similar to pull that phone number into our Dialogflow inline editor? Thanks again! – mdb Dec 19 '18 at 23:02
  • Where is your bot hosted? Where are you linking people to? I assumed this was on your own site and that you would be able to perform some sort of action in response to someone visiting the URL. – philnash Dec 20 '18 at 00:51
  • The bot will be hosted on our client's site. We're thinking that maybe we can send each user a unique, shortened URL that goes to the webpage with the bot, then make a post in our database with both the unique URL and the user's phone number. Then, when the user clicks the link to go to the bot, we can reference the unique URL with document.referrer, find the posted URL in the database that is already associated with the phone number, and then post additional information the user submits, like email, monthly income, etc. – mdb Jan 02 '19 at 21:49
  • Can I require node modules in a custom function in twilio? I'm trying to use axios and node-url-shortener, but I also saw this webpage: https://support.twilio.com/hc/en-us/articles/115007737928-Building-apps-with-Twilio-Functions Wondering if the allowed node modules are limited to twilio, got, lodash, and xmldom – mdb Jan 03 '19 at 23:36
  • You can require node modules, yeah. I think that support article is a little out of date, the most up to date documentation is here: https://www.twilio.com/docs/runtime/functions/packages. – philnash Jan 03 '19 at 23:49
  • Alright, I'm very close. The last piece I'm missing is referencing the user's phone number within the custom function. I've seen a blog post [here](https://www.twilio.com/blog/2017/10/how-to-use-twilio-functions-with-the-phone-verification-api.html) which uses event.country_code and event.phone_number to verify a number, but it looks like those are supplied parameters in JSON. Is there a way for me to assign the phone number of an incoming message to a variable in a custom function? – mdb Jan 04 '19 at 03:48
  • If you include the phone number in the URL parameters of the Function (`xyz.twil.io/function?phone_number=${phoneNumber}`) then it will be accessible as a property on the `event` object. – philnash Jan 04 '19 at 03:50
  • So in this case, the function is being called within our Twilio studio in response to an incoming text message. I can see how I could add the phone number in if I were to manually call the function with parameters in the url, but is it possible to have the incoming number passed in as a parameter when the function is called in the studio flow? – mdb Jan 04 '19 at 04:05
  • The Run Function widget allows you to add parameters. You want to add the number that sent the initial incoming text message, which is `{{trigger.message.From}}`. – philnash Jan 04 '19 at 04:09
  • Gotcha, I missed that part of the Studio docs! Thank you for all of your help. You're the man. – mdb Jan 04 '19 at 04:43
  • No problem! If this all helped then I'd appreciate if you marked the answer as correct. It helps others see that your issue was solved too. Cheers! – philnash Jan 04 '19 at 04:44
  • Done! and I got a little bit ahead of myself - one last thing. My event object is empty, and even though I have set the parameter of phoneNumber equal to {{trigger.message.From}}, event.phoneNumber is null. Any ideas? – mdb Jan 04 '19 at 04:47
  • What does the whole `event` object look like? Is this in the case that the flow was triggered by an incoming SMS message? – philnash Jan 04 '19 at 04:50
  • Yes it is still the same case. I'm testing the function by texting our twilio number. when I console.log(event), the result is an empty object. Just an empty set of curly brackets. console.log(event.phoneNumber) returns null – mdb Jan 04 '19 at 04:52
  • Are you able to hardcode a parameter that gets fed into the function? Also, have you made sure you've published the flow after editing it? – philnash Jan 04 '19 at 04:54
  • well I wouldn't be a junior dev without making dumb mistakes like not publishing the lastest version... That fixed it and everything is working as intended. Thanks again. – mdb Jan 04 '19 at 04:56
  • Not quite sure what you mean there. What do you have? Would it be better to open a new question and put the code you have already? – philnash Jan 09 '19 at 22:58
  • Figured it out, had an issue with a callback. Thanks – mdb Jan 09 '19 at 23:53