-
-
Save jmadden/7fa317ea2e6bb782803b7b8876cf1836 to your computer and use it in GitHub Desktop.
| <?php | |
| // Get the PHP helper library from https://twilio.com/docs/libraries/php | |
| require_once '/path/to/vendor/autoload.php'; // Loads the library | |
| use Twilio\Rest\Client; | |
| // Your Account Sid and Auth Token from twilio.com/user/account | |
| $sid = "YOU_ACCOUNT_SID"; | |
| $token = "YOUR_AUTH_TOKEN"; | |
| $client = new Client($sid, $token); | |
| $to = "+14155551212"; | |
| $from = "+14158675310"; | |
| $call = $client->calls->create( | |
| $to, | |
| $from, | |
| array( | |
| "url" => "/2-call-answered-gather.php" | |
| ) | |
| ); |
| <?php | |
| // Create a route that will handle Twilio webhook requests, sent as an | |
| // HTTP POST to /voice in our application | |
| require_once '/path/to/vendor/autoload.php'; | |
| use Twilio\Twiml; | |
| // Use the Twilio PHP SDK to build an XML response | |
| $response = new Twiml(); | |
| // Use the <Gather> verb to collect user input | |
| $gather = $response->gather(array('numDigits' => 1, 'action' => '/3-gather.php')); | |
| // use the <Say> verb to request input from the user | |
| $gather->say('Press 1 to take a survey. Press 2 to hear a joke.'); | |
| // If the user doesn't enter input, loop | |
| $response->redirect('/2-call-answered.php'); | |
| // Render the response as XML in reply to the webhook request | |
| header('Content-Type: text/xml'); | |
| echo $response; |
| <?php | |
| // Create a route that will handle Twilio Gather verb action requests, | |
| // sent as an HTTP POST to /gather in our application | |
| require_once '/path/to/vendor/autoload.php'; | |
| use Twilio\Twiml; | |
| // Use the Twilio PHP SDK to build an XML response | |
| $response = new Twiml(); | |
| // If the user entered digits, process their request | |
| if (array_key_exists('Digits', $_POST)) { | |
| switch ($_POST['Digits']) { | |
| case 1: | |
| $response->say('You selected to take the survey. Thank you!'); | |
| break; | |
| case 2: | |
| $response->say('You selected to her a joke! Why did the robot cross the road? Because it was carbon bonded to the chicken!'); | |
| break; | |
| default: | |
| $response->say('Sorry, I don\'t understand that choice.'); | |
| $response->redirect('/2-call-answered.php'); | |
| } | |
| } else { | |
| // If no input was sent, redirect to the /voice route | |
| $response->redirect('/2-call-answered.php'); | |
| } | |
| // Render the response as XML in reply to the webhook request | |
| header('Content-Type: text/xml'); | |
| echo $response; |
Happy to hear it was helpful 👍 @alexsdesign
PHP Fatal error: Uncaught Twilio\Exceptions\RestException: [HTTP 400] Unable to create record: Url is not a valid URL: /2-call-answered.php in D:\Progamming\project\p38\vendor\twilio\sdk\src\Twilio\Version.php:88
Stack trace:
#0 D:\Progamming\project\p38\vendor\twilio\sdk\src\Twilio\Version.php(223): Twilio\Version->exception()
#1 D:\Progamming\project\p38\vendor\twilio\sdk\src\Twilio\Rest\Api\V2010\Account\CallList.php(94): Twilio\Version->create()
#2 D:\Progamming\project\p38\1-outbound-call.php(18): Twilio\Rest\Api\V2010\Account\CallList->create()
#3 {main}
PHP Fatal error: Uncaught Twilio\Exceptions\RestException: [HTTP 400] Unable to create record: Url is not a valid URL: /2-call-answered.php in D:\Progamming\project\p38\vendor\twilio\sdk\src\Twilio\Version.php:88 Stack trace: #0 D:\Progamming\project\p38\vendor\twilio\sdk\src\Twilio\Version.php(223): Twilio\Version->exception() #1 D:\Progamming\project\p38\vendor\twilio\sdk\src\Twilio\Rest\Api\V2010\Account\CallList.php(94): Twilio\Version->create() #2 D:\Progamming\project\p38\1-outbound-call.php(18): Twilio\Rest\Api\V2010\Account\CallList->create() #3 {main}
Add the URL to Twilio incoming webhook.
Just want to say a massive thank you.
Finding your code has helped me massively to get started with gathering DTMF and outbound calls :D