2

I want to create a new outbound call to a phone number via the API that should be handled by a TwiML App.

To do this, I provide the ApplicationSid parameter instead of the Url parameter as documented here

But I cannot find a way to pass any custom parameters as the only way to add custom parameters when creating a call to a phone number is to add them as query parameters to the URL as described here.

I could query the TwiML App from the API, read the configured Webhook URLs, add my custom Parameters as Query and pass them to Url, StatusCallback and FallbackUrl when creating the Call but that seems redundant and overcomplicated.

Another solution would be to store the custom parameters in a local database with the CallSid as key, but I would like to avoid having local state.

Is there no way to simply tell the API to add some parameters to the Url when calling the webhooks of the TwiML App (as mentioned here)?

Lukas Zech
  • 505
  • 6
  • 7
  • Twilio developer evangelist here. I cannot find a way to do this, outside of just sending the `Url` parameter directly. I will check to see if anyone else knows if this can be done or if there is a workaround. – philnash Oct 05 '21 at 01:43

2 Answers2

2

Twilio developer evangelist here.

I'm afraid there is no good way to pass parameters when calling using a TwiML app. Your options are, as you described, send URLs with the query parameters in the API request instead of sending a TwiML App SID or store the parameters locally against the CallSid as a sort of session store.

philnash
  • 70,667
  • 10
  • 60
  • 88
1

This is really easy to do. You need to provide customer parameters in the call. Like this...

        var params = {
            myOutboundPhone: "+15554448888",
            myOutboundName: "Joe Q Customer"
            };   
        device.connect(
            {
                params
            }).then((call) => {
                call.on('accept', (acceptedCall) => {
                    console.log('in call accept');
                    console.log('myOutboundPhone = ' + acceptedCall.customParameters.get('myOutboundPhone'));
                    console.log('myOutboundName = ' + acceptedCall.customParameters.get('myOutboundName'));
                });
            });

Your console log will look like this...

in call accept
myOutboundPhone = +15554448888
myOutboundName = Joe Q Customer

Then in your voice callback from the TwiML app...

public function getVoiceXML(Request $request) : Response
{
    error_log('in getVoiceXML');
    error_log(json_encode($request->query->all()));
    // ...
    return $response;
}

Will log this...

[Web Server ] in getVoiceXML
[Web Server ]  {"AccountSid":"ACxxxx","ApiVersion":"2010-04-01","ApplicationSid":"APxxx","CallSid":"CAxxxx","CallStatus":"ringing","Called":"","Caller":"client:xxx","Direction":"inbound","From":"client:xxx","To":"","myOutboundName":"Joe Q Customer","myOutboundPhone":"+15554448888"}
AQuirky
  • 4,691
  • 2
  • 32
  • 51
  • You are using the JS Client of the Voice SDK which uses WebSocket connections between two software clients My question was about the Call API used to call real phone numbers via SIP or carrier networks. – Lukas Zech Sep 13 '22 at 08:03