* @copyright (c) 2025, Robert Strutts * @license MIT */ namespace Project\controllers\app; use CodeHydrater\bootstrap\registry as Reg; /** * Description of twilio_ctrl * * Twilio Setup, REQUIRES off_twilio.php to be turned on... * Then define the sid and token * * @link https://github.com/twilio/twilio-php * @link https://www.twilio.com/docs/messaging/quickstart * @link https://www.twilio.com/docs/voice/twiml * */ class twilio_ctrl { private function get_caller() { /** Get Callers Phone Number, if plus-sign (+) not found add it */ $caller_number = (isset($_REQUEST['From'])) ? $_REQUEST['From'] : false; if ($caller_number !== false) { $plus = substr($caller_number, 0, 1); $caller_number = ($plus !== '+') ? "+" . $caller_number : $caller_number; } return $caller_number; } public function index() { header("content-type: text/xml"); $response = Reg::get('di')->get_service('twilio_voice'); $caller_number = $this->get_caller(); // If the user entered digits, process their request if (array_key_exists('Digits', $_POST)) { switch ($_POST['Digits']) { case 1: $response->say('One moment and you will be connnected to Sales!'); // Do Sales Stuff break; case 2: $response->say('Please hold for support!'); // Do Support Stuff break; default: $response->say('Sorry, I don\'t understand that choice.'); } } else { // If no input was sent, use the verb to collect user input $gather = $response->gather(array('numDigits' => 1)); // use the verb to request input from the user $gather->say('For sales, press 1. For support, press 2.'); // If the user doesn't enter input, loop $response->redirect('/app/twilio/index'); } echo $response; } public function send_sms(): string { $twilio = Reg::get('di')->get_service('twilio_sms'); // Example: Send an SMS Text message to Cell Phone $message = $twilio->messages->create( '+15558675309', // To number GOES HERE [ 'from' => '+15017122661', // YOUR Twilio number HERE 'body' => 'Hello from Twilio!' ] ); echo $message->body; } }