Multiple webook endpoints for incoming messages - twilio

I'm using the following guide to handle incoming messages:
https://www.twilio.com/docs/sms/tutorials/how-to-receive-and-reply-node-js
I added the endpoint for my prod environment to the "A message comes in" webook, which is working when I test in prod, but I want to test incoming messages from my dev environment too. Is there a way to add a second endpoint for this twilio phone number's webhook, or will I need to add another twilio phone number?

You will need to add another Twilio number, since each Twilio number can only have one webhook for "A message comes in...".
You create your own Proxy routing logic, which intelligently delivers the webhook to specific URL/destination based on some criteria in your logic. Your proxy routing logic would then be the destination for the "A message comes in...". This proxy routing logic could be done using a Twilio Function as an example.

Related

Twilio Advanced Opt-in not sending

I'm building a text service with Twilio and configured and enabled the Advanced Opt-out / Opt-in settings in my messaging service.
When testing the opt-in with my custom keyword I get this back instead my custom message
Thanks for the message. Configure your number's SMS URL to change this message. Reply HELP for help . Reply STOP to unsubscribe. Msg&Data rates may apply.
The screenshot shows my custom keyword and message. I'm using a toll-free number.
Any ideas as to why its not automatically sending the custom opt-in message?
When you receive opt-in messages to your number the webhook request is still sent to the URL you configure for your number. It looks like you haven't configured that URL for your number yet, as that is the default response for a new number.
Head to the Twilio console to configure your number and update the URL for when a message comes in. You can set it to your own application's URL if you have built that out yet, or if you are still working on that you could use a TwiMLBin with an empty <Response> which doesn't respond if you don't have an application yet.

Is it possible to access the Twilio destination number in a Twilio function called by Twilio Autopilot?

Using Twilio Autopilot, I see in the documentation that you can get the caller/originator from the UserIdentifier in a Twilio Function. Is it possible to get the phone number the destination (one of my twilio numbers) messaged or dialed which kicked off the autopilot session?
My use case is to respond from the function with a greeting with different company names (bots would be identical except for company name. ie. "Thanks for contacting COMPANY NAME 1." or "Thanks for contacting COMPANY NAME 2." etc. (In this case each company has their own distinct phone #).
My fallback is to create a bot for each company name that answers/greets, then redirects to the common workflow main task.
Thoughts?
It looks like Inbound Context could be used to place this information in Autopilots Memory. The Autopilot Request documentation doesn't seem to call out the To parameter. You could always capture the Autopilot Request and verify the parameters it is sending your application, to verify this is the case.

How do I call a number with Twilio Studio flow REST API execution

The purpose is simply to call a number (my number) and have a message start playing.
I have created a Studio Flow like so:
And published that flow.
I've also bought a phone number and it is activated for voice & messaging. I can receive a test voice call with code and using TwiML).
In the settings of my phone number I have the following:
Accept: Voice Calls
Configure with: .. Studio ..
A call comes in: Studio Flow (and selected the correct flow)
I then proceed to use Postman to try and trigger my Flow using a POST request with the following parameters:
And the following body parameters where the To number is my number which is verified in my trial account, and the from is the number i purchased in twilio:
After clicking on Send in postman I receive a 200 OK message, but I am not receiving a call on my phone. What step am I missing?
Twilio developer evangelist here.
The variable you are using as the number to dial out from Studio is {{contact.channel.address}} but the contact variable refers to "data about the current contact engaging with your flow, such as their phone number".
Since you have triggered the flow with a REST API call there is not a contact that is currently engaging with the flow, so this won't give you the number you want.
You are, however, sending in some parameters from your HTTP request from Postman, notably a To parameter. Your data that you send to the flow endpoint like this will be available under the trigger context variable.
So, you should update your widget to use {{trigger.To}} instead (and you probably don't need From, as that is the number associated with the flow, or Body).
Let me know how you get on with that.

Twilio Browser client Available or not

I am facing a problem with Twilio to detect the Twilio Browser client Available or not.
If Twilio client is not available then need to send the voicemail otherwise I am using to accept the call.
Twilio.Device.incoming(function (conn);
Thanks.
Sounds like you need agent presence. There are a couple ways to go about this. One (Recommended) is to use Twilio TaskRouter. https://www.twilio.com/taskrouter. This will handle agent presence for you (online, offline, busy, etc..) and much more
Your other option is to use a service like PubNub http://www.pubnub.com/ and bind the clint so you can get state information (online, offline, busy, etc..). This is more wok since you have to handle state yourself.
The following steps can be followed to achieve this
 1. Set a valid url to the action attribute of the Dial verb of the client
  Eg., The TwiMl to dial the client must be
  <Response>
   <Dial action="myapp/statusCallBack">
    <Client>jenny</Client>
   </Dial>
  </Response>
 2. If the client jenny is available, the connection object can be received via
  Twilio.Device.incoming(function (conn){conn.accept();});
 3. If the client jenny is unavailable, Twilio will request to the statusCallBack url with the parameter 'DialCallStatus=no-answer'. Now the following
  twiml can be returned to say Unavailable message.
  <Response>
   <Say>
    Please leave your name and number along with a short message.
   </Say>
   <Record maxLength="3600" action="myapp/recordedUrl">
   </Record>
  </Response>
 4. Now the voicemail url can be stored when the "myapp/recordedUrl" is called once the caller recorded the voicemail. For more info on record verb, visit this site
 Note that the voice mail is recorded on two cases, if the client is unavailable or the client does not accept the call.

Using Twilio to respond to an SMS with a http redirect to an external webapp

so, when i send a text message to twilio number, i want it to trigger a specific event in the webapp via http POST. For example, by making a http call to the webapp URL (http://webapp.com/triggerA) which it process to trigger an event A in the webapp.
Can I do this with twilio? If,so is there a sample piece of code which I can refer.
From what I understand from your question, I think you can do the following.
With Twilio, when you login into here
https://www.twilio.com/user/account/phone-numbers/incoming
You will find a list of your incoming numbers, I am assuming that you have already purchased a number. Once you click on a number in the list, you will find a page that where you can view and set various properties for the number you are looking at.
You will see a header called Messaging. Under that menu you will see a request Url.
you can set this to http://webapp.com/triggera as per your example. you can also choose whether you would like to use a http post or a http get request type.
the link below, will help you further for handling the data that Twilio passes your application.
https://www.twilio.com/docs/api/twiml/sms/twilio_request
Louis

Resources