简体   繁体   中英

Setting up Twilio CallBack

To fellow Twilio users,

we have set up a Twilio trial account.

Our question is can we define/set up a CALLBACK URL in Twilio App Dashboard ( or any other settings panel) to satisfy the following use case:

1.  From browser/apps / mobile device
,  user dials  310-333-1234 6789 (Twilio phone # / accesscode)


2.  Twilio receives this call

3.  Twilio captures accesscode (6789) trailing the phone number
     and passes to CALLBACK URL

I understand Twilio MakeCall API allows you to specify CallBackURL:

where parmeters :

sendDigits=6789
StatusCallBack=My_CallBack_URL
StatusCallBackMethod=Post

But what we want is to set up CALLBACK URL so physical incoming calls (not calls made with API) and their accesscode would always be passed to this CALLBACK URL.

I'm Megan from Twilio. Not sure what language you're working with and I typically write Python, but I'll share an example in PHP below.

It looks like what you're trying to do here involves the Twiml <Gather> verb, where in the following example you would set http://example.com/complex_gather.xml as the URL in your Voice Request URL configuration of your Twilio number per Carter's suggestion in the comments. The <action> verb then allows you to redirect the caller to your custom Voice Request URL after they input the access code.

<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/complex_gather.xml -->
<Response>
    <Gather numDigits="4" action="/customVoiceUrl" method="GET">
        <Say>
            Please enter your access code.
        </Say>
    </Gather>
    <Say>We didn't receive any input. Goodbye!</Say>
</Response>

And an example page for the customVoiceUrl:

<?php
// page located at http://example.com/customVoiceUrl
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<Response><Say>You entered " . $_REQUEST['Digits'] . "</Say></Response>";
?>

Same issue described above was happening to me. It was happening because the url contained a query parameter that had an apostraphe in the value eg the url had an apostraphe that was encoded with %27 https://www.example.com?name=O%27Malley

The fix for me was to double encode the query parameters before sending the request to twilio. eg https://www.example.com?name=O%2527Malley And then make sure to do an extra decoding on the callback query params on my backend

If the signature generated by Twilio decodes special charecters including those in the url as query parameter values, the library should do decoding along with parsing on validate https://github.com/twilio/twilio-ruby/blob/main/lib/twilio-ruby/security/request_validator.rb#L27

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM