/** * Process a new call * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function newCall(Request $request) { $response = new Twiml(); $callerIdNumber = config('services.twilio')['number']; $dial = $response->dial(['callerId' => $callerIdNumber]); $phoneNumberToDial = $request->input('phoneNumber'); if (isset($phoneNumberToDial)) { $dial->number($phoneNumberToDial); } else { $dial->client('support_agent'); } return $response; }
/** * Responds with a <Dial> to the caller's planet * * @return \Illuminate\Http\Response */ public function showExtensionConnection(Request $request) { $selectedOption = $request->input('Digits'); try { $agent = $this->_getAgentForDigit($selectedOption); } catch (ModelNotFoundException $e) { return redirect()->route('main-menu-redirect'); } $numberToDial = $agent->phone_number; $response = new Twiml(); $response->say("You'll be connected shortly to your planet. " . $this->_thankYouMessage, ['voice' => 'alice', 'language' => 'en-GB']); $dialCommand = $response->dial(['action' => route('agent-voicemail', ['agent' => $agent->id], false), 'method' => 'POST']); $dialCommand->number($numberToDial, ['url' => route('screen-call', [], false)]); return $response; }
/** * Endpoint which store a new lead with its lead source and forward the call * * @param Request $request Input data * @return Response Twiml to redirect call to the forwarding number */ public function store(Request $request) { $leadSource = LeadSource::where(['number' => $request->input('To')])->first(); $lead = new Lead(); $lead->leadSource()->associate($leadSource->id); $lead->city = $this->_normalizeName($request->input('FromCity')); $lead->state = $this->_normalizeName($request->input('FromState')); $lead->caller_number = $request->input('From'); $lead->caller_name = $request->input('CallerName'); $lead->call_sid = $request->input('CallSid'); $lead->save(); $forwardMessage = new Twiml(); $forwardMessage->dial($leadSource->forwarding_number); return response($forwardMessage, 201)->header('Content-Type', 'application/xml'); }
/** * Replies with a call connect xml * * @return \Illuminate\Http\Response */ public function showConnect(Request $request) { $muted = false; $moderator = false; $digits = $request->input('Digits'); if ($digits === '1') { $muted = true; } if ($digits === '3') { $moderator = true; } $response = new Twiml(); $response->say('You have joined the conference.', ['voice' => 'alice', 'language' => 'en-GB']); $dial = $response->dial(); $dial->conference('RapidResponseRoom', ['startConferenceOnEnter' => $moderator, 'endConferenceOnExit' => $moderator, 'muted' => $muted, 'waitUrl' => 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient']); return response($response)->header('Content-Type', 'application/xml'); }
/** * Responds with a <Dial> to the caller's planet * * @return \Illuminate\Http\Response */ public function showPlanetConnection(Request $request) { $response = new Twiml(); $response->say($this->_thankYouMessage, ['voice' => 'Alice', 'language' => 'en-GB']); $response->say("You'll be connected shortly to your planet", ['voice' => 'Alice', 'language' => 'en-GB']); $planetNumbers = ['2' => '+12024173378', '3' => '+12027336386', '4' => '+12027336637']; $selectedOption = $request->input('Digits'); $planetNumberExists = isset($planetNumbers[$selectedOption]); if ($planetNumberExists) { $selectedNumber = $planetNumbers[$selectedOption]; $response->dial($selectedNumber); return $response; } else { $errorResponse = new Twiml(); $errorResponse->say('Returning to the main menu', ['voice' => 'Alice', 'language' => 'en-GB']); $errorResponse->redirect(route('welcome', [], false)); return $errorResponse; } }
<?php // NOTE: This example uses the next generation Twilio helper library - for more // information on how to download and install this version, visit // https://www.twilio.com/docs/libraries/php require_once '/path/to/vendor/autoload.php'; use Twilio\Twiml; $response = new Twiml(); $response->say("You will now be connected to the first caller in the queue."); $dial = $response->dial(); $dial->queue("Queue Demo"); $response->redirect(); echo $response;
<?php // NOTE: This example uses the next generation Twilio helper library - for more // information on how to download and install this version, visit // https://www.twilio.com/docs/libraries/php require_once '/path/to/vendor/autoload.php'; use Twilio\Twiml; $response = new Twiml(); $response->dial()->queue('Queue Demo'); echo $response;
<?php // Get the PHP helper library from twilio.com/docs/php/install // this line loads the library require 'vendor/autoload.php'; use Twilio\Twiml; $response = new Twiml(); // get the phone number from the page request parameters, if given if (isset($_REQUEST['To'])) { $number = htmlspecialchars($_REQUEST['To']); $dial = $response->dial(array('callerId' => '+15017250604')); // wrap the phone number or client name in the appropriate TwiML verb // by checking if the number given has only digits and format symbols if (preg_match("/^[\\d\\+\\-\\(\\) ]+\$/", $number)) { $dial->number($number); } else { $dial->client($number); } } else { $response->say("Thanks for calling!"); } echo $response;