Solution for Twilio Programmable Voice and Webhook configuration for specifying url in CallResource.Create()
is Given Below:
I’m new to Twilio and I’m trying to figure out how to build something like this:
- my application places a phone call using my Twilio number to a user’s mobile phone.
- the application uses
CallResource.Createto initate the call and provide Twiml
- I use a URL to return Twiml by passing in a url to
- the Twiml should say the choices to the user, then collect information from the them (using Say then Gather) for two possible responses, and return that collected information back to my application.
What I’m REALLY confused about is whether or not I need to specify a webhook that is the same path as the url I’m passing to
CallResource.Create() to retrieve the Twiml.
But, for what I need to build, a user is not calling my Twilio number, my application is using my Twilio number to call a user on their mobile phone.
In the docs, it says:
If you specify a URL parameter in your request, Twilio will make its HTTP request to this URL to retrieve TwiML to handle the call. This request from Twilio is identical to the request Twilio sends when receiving an inbound call.
If it’s identical to an incoming call, then do I need a webhook configured or not?
Twilio developer evangelist here.
When you create an outbound call using the Twilio REST API when the callee answers their phone Twilio will make a webhook (HTTP) request to the URL you provide in the request in order to find out what to do next with the call. In this case you want to return TwiML to Say then Gather, as you described.
If you are not planning to receive incoming calls on your Twilio phone number, then you do not need to provide a webhook URL for inbound calls. You may want to provide a simple TwiML response (using a TwiML Bin) that tells the caller that your number does not accept incoming calls and then hangs up. Or that just rejects inbound calls. But the inbound webhook is not related to the outbound URL.
When the documentation says that the “request from Twilio is identical to the request Twilio sends when receiving an inbound call” it is saying that the format of the request and the parameters are identical (though the content of the parameters will be different for different calls).