main
Robert 4 months ago
parent 21596160e9
commit c9a56b7987
  1. 3
      protected/src/composer.json
  2. 13
      protected/src/configs/off_remove_request_vars.php
  3. 18
      protected/src/configs/off_twilio.php
  4. 8
      protected/src/controllers/app/home_ctrl.php
  5. 76
      protected/src/controllers/app/twilio_ctrl.php
  6. 40
      protected/src/services/on_twilio_setup.php
  7. 7
      protected/src/views/default/app/home_index.php

@ -2,6 +2,7 @@
"require": { "require": {
"twig/twig": "^3.0", "twig/twig": "^3.0",
"liquid/liquid": "^1.4", "liquid/liquid": "^1.4",
"ezyang/htmlpurifier": "^4.18" "ezyang/htmlpurifier": "^4.18",
"twilio/sdk": "^8.7"
} }
} }

@ -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' => '',
]);

@ -19,10 +19,13 @@ class home_ctrl {
private $footer; private $footer;
public function __construct() { public function __construct() {
// FROM on_footer_banner.php in the configs folder... // FROM on_footer_banner.php in the configs folder...
$this->footer = \Project\get_footer(); if (function_exists("\Project\get_footer")) {
$this->footer = \Project\get_footer();
} else {
$this->footer = "";
}
} }
public function index() { public function index() {
$html = new \CodeHydrater\html_document(); $html = new \CodeHydrater\html_document();
$html->set_footer($this->footer); $html->set_footer($this->footer);
@ -76,5 +79,4 @@ class home_ctrl {
echo "PAGE = ". $page; echo "PAGE = ". $page;
} }
public function error_demo() { \CodeHydrater\bootstrap\broken_error(); }
} }

@ -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();
}
}
}

@ -8,6 +8,9 @@ $method_name_demo = "name_demo";
$route_liquid = "app/home"; $route_liquid = "app/home";
$method_liquid = "liquid"; $method_liquid = "liquid";
$route_rss = "app/rss";
$method_rss = "feed.xml";
?> ?>
<div style="max-width: 1200px; margin: 0 auto; padding: 0 20px; background-color: #ffffaa; border-radius: 20px;"> <div style="max-width: 1200px; margin: 0 auto; padding: 0 20px; background-color: #ffffaa; border-radius: 20px;">
@ -20,4 +23,8 @@ $method_liquid = "liquid";
<a href="<?= \CodeHydrater\misc::get_url($route_liquid, $method_liquid) ?>">View Liquid Demo</a> <a href="<?= \CodeHydrater\misc::get_url($route_liquid, $method_liquid) ?>">View Liquid Demo</a>
||
<a href="<?= \CodeHydrater\misc::get_url($route_rss, $method_rss) ?>">View RSS XML feed Demo</a>
</div> </div>
Loading…
Cancel
Save