parent
21596160e9
commit
c9a56b7987
@ -0,0 +1,13 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
declare(strict_types=1); |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Robert Strutts <Bob_586@Yahoo.com> |
||||||
|
* @copyright (c) 2025, Robert Strutts |
||||||
|
* @license MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
unset($_REQUEST); // Request is dangerious as order of Vars is not Known |
||||||
|
unset($_GET); // Super Globals are not Filtered, so unset them |
||||||
|
unset($_POST); |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
declare(strict_types=1); |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Robert Strutts <Bob_586@Yahoo.com> |
||||||
|
* @copyright (c) 2025, Robert Strutts |
||||||
|
* @license MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
use CodeHydrater\bootstrap\configure as Config; |
||||||
|
|
||||||
|
// Your Twilio credentials |
||||||
|
Config::set('twilio', [ |
||||||
|
'sid' => '', |
||||||
|
'token' => '', |
||||||
|
]); |
||||||
|
|
||||||
@ -0,0 +1,76 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
declare(strict_types=1); |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Robert Strutts <Bob_586@Yahoo.com> |
||||||
|
* @copyright (c) 2025, Robert Strutts |
||||||
|
* @license MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace Project\controllers\app; |
||||||
|
|
||||||
|
/** |
||||||
|
* 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 |
||||||
|
* |
||||||
|
* |
||||||
|
*/ |
||||||
|
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 = \CodeHydrater\twilio_setup::init_voice(); |
||||||
|
$the_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('You selected sales. Good for you!'); |
||||||
|
break; |
||||||
|
case 2: |
||||||
|
$response->say('You need support. We will help!'); |
||||||
|
break; |
||||||
|
default: |
||||||
|
$response->say('Sorry, I don\'t understand that choice.'); |
||||||
|
} |
||||||
|
} else { |
||||||
|
// If no input was sent, use the <Gather> verb to collect user input |
||||||
|
$gather = $response->gather(array('numDigits' => 1)); |
||||||
|
// use the <Say> 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 = \CodeHydrater\twilio_setup::init_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; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,40 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
declare(strict_types=1); |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Robert Strutts <Bob_586@Yahoo.com> |
||||||
|
* @copyright (c) 2025, Robert Strutts |
||||||
|
* @license MIT |
||||||
|
*/ |
||||||
|
namespace CodeHydrater; |
||||||
|
|
||||||
|
use CodeHydrater\bootstrap\registry as Reg; |
||||||
|
use CodeHydrater\bootstrap\configure as Config; |
||||||
|
|
||||||
|
final class twilio_setup { |
||||||
|
const VENDOR = CodeHydrater_PROJECT . 'vendor/twilio/sdk/src/Twilio/'; |
||||||
|
|
||||||
|
public static function init_sms() { |
||||||
|
if (! Reg::get('loader')->is_loaded('Twilio')) { |
||||||
|
Reg::get('loader')->add_namespace('Twilio', self::VENDOR); |
||||||
|
} |
||||||
|
$sid = Config::get('twilio', 'sid') ?? false; |
||||||
|
if ($sid === false) { |
||||||
|
throw new \Exception("Twilio SID not defined"); |
||||||
|
} |
||||||
|
$token = Config::get('twilio', 'token') ?? false; |
||||||
|
if ($token === false) { |
||||||
|
throw new \Exception("Twilio TOKEN not defined"); |
||||||
|
} |
||||||
|
return new \Twilio\Rest\Client($sid, $token); |
||||||
|
} |
||||||
|
|
||||||
|
public static function init_voice() { |
||||||
|
if (! Reg::get('loader')->is_loaded('Twilio')) { |
||||||
|
Reg::get('loader')->add_namespace('Twilio', self::VENDOR); |
||||||
|
return new \Twilio\TwiML\VoiceResponse(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue