3

enter image description hereI am setting up a Twilio Flex acct and am wanting when a caller calls and lets say says or presses # 2 I want to ultimately take the callers phone number from the caller id and do a post to an external webpage. I am looking for documentation on this. Anyone have any suggestions?

The Twilio Studio flow I am having issues with it enter image description here enter image description here

Jayreis
  • 253
  • 1
  • 7
  • 28

1 Answers1

0

Twilio developer evangelist here.

By default, incoming calls to a Flex number are directed through a Twilio Studio flow. The default flow passes the caller straight through to get assigned to an agent in Flex, but you can add other widgets to ask for input or direct the call any way you want.

One of the available Studio widgets is the Make HTTP Request widget which allows you to make an HTTP request to a URL of your choice. You can add data to the body of the request using the widget. To get the phone number of the caller you can use the variables set by the inbound trigger. In the case of the phone number of the caller, you need {{trigger.call.From}}.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Thank you @philnash I have the Make HTTP Request Widget working to take the caller id and run a query on a database. However how do I take the json that is on the external page and have flex voice/say it back to the caller? The Json is basically the result of a query. – Jayreis Sep 17 '21 at 03:25
  • You can use the response of the Make HTTP Request widget later in the flow, with liquid tags, like this: `{{widgets.WIDGET_NAME.parsed.PROPERTY}}`. See the variable examples at the bottom of this page: https://www.twilio.com/docs/studio/widget-library/http-request – philnash Sep 17 '21 at 03:56
  • So if the name of my Make http request widget is QueryOrderStatus and the json that the page generates is [{"0":"5555555555","name":"5555555555","1":"1","status":"1"}] and I want to get the value of 5555555555 iI would use a say/play widget and in the text to say box i have Thank you from calling from {{widgets.QueryOrderStatus.parsed.name}} however it doesn't say the 5555555555 part ?? – Jayreis Sep 17 '21 at 04:23
  • If your result is an array, then you will need to index into the array. I think you might be able to do that with `{{widgets.QueryOrderStatus.parsed.0.name}}` though it would be easier if you could just return an object instead of an array. – philnash Sep 17 '21 at 04:25
  • well now it just says "widgets dot QueryOrderStatus dot parsed dot zero dot name" instead of actually getting the 5555555555 which I know is in the array – Jayreis Sep 17 '21 at 04:29
  • Ah, sorry! It does need to be an object, not an array. The docs say: "Note that, although an array is valid JSON, if your request returns an array of objects, it will not be parsed.". – philnash Sep 17 '21 at 04:30
  • If you can't change your endpoint to return an object instead of an array. You could build a Twilio Function that makes the request, then returns the first object from the array. – philnash Sep 17 '21 at 04:36
  • well the endpoint is a php page just doing a mysqli query on a database and returning values of the matching row. So I need the mysql query results to be a json object? or ? I have a screenshot of my endpoint in the OP – Jayreis Sep 17 '21 at 04:39
  • However you do it, you need your endpoint (or something in the middle) to return `{"0":"5555555555","name":"5555555555","1":"1","status":"1"}` to your widget instead of `[{"0":"5555555555","name":"5555555555","1":"1","status":"1"}]`. I'm not good enough at PHP to know how to update your snippet to return the object instead of the list. – philnash Sep 17 '21 at 04:51
  • Thank you Philnash. I used some php to strip the square brackets in the json so now it looks like {"0":"5555555555","name":"5555555555","1":"1","status":"1"} but still not working so guess I will go back to the drawing board. – Jayreis Sep 17 '21 at 05:06
  • Now you should be able to get the value with `{{widgets.QueryOrderStatus.parsed.name}}`. Is that not working? – philnash Sep 17 '21 at 05:08
  • Hold on, you shouldn't have to strip the square brackets from a string. Why not JSON encode the first element of the array, like: `echo json_encode($myArray[0]);` – philnash Sep 17 '21 at 05:09
  • So my page echo's this out {"0":"5555555555","name":"5555555555","1":"1","status":"1"} In Twilio Flex my say/play widget has Thank you from calling from {{widgets.QueryOrderStatus.parsed.name}} So I removed the zero but it still just verbalizes the string so says "widgets dot query ..... instead of saying the 5555555555 any suggestions? – Jayreis Sep 17 '21 at 14:12
  • Can you show me a screenshot of the overall Studio Flow, and also the say/play widget config where you reference the other widget? – philnash Sep 20 '21 at 23:49
  • I just added two new screenshots to my OP @philnash – Jayreis Sep 21 '21 at 00:59
  • I just tried to replicate that Studio flow and found the the result from the HTTP request was read out as expected. Have you ensured that you have published the Studio flow after making changes? – philnash Sep 21 '21 at 01:37