Skip to content

Instantly share code, notes, and snippets.

@jmadden
Last active June 29, 2017 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmadden/774e7dee3ac86116c465059005ead7a5 to your computer and use it in GitHub Desktop.
Save jmadden/774e7dee3ac86116c465059005ead7a5 to your computer and use it in GitHub Desktop.
<?php
use Twilio\Twiml;
class TwimlWrap
{
/** @var TwilioTwiml */
protected $twiml;
public function __construct()
{
$this->twiml = new Twiml();
}
public function say($message, array $attributes = [])
{
$this->twiml->say($message, $attributes);
}
public function gather($verb, $noun, $gatherOptions = [], $verbOptions = [])
{
$gather = $this->twiml->gather($gatherOptions);
$gather->$verb($noun, $verbOptions);
}
public function renderTwiml()
{
print $this->twiml;
}
}
// Instantiate the TwimlWrap class and pass in necessary paramaters for Gather.
$foo = new TwimlWrap();
$foo->gather("Say","Hello World!", ['input' => 'speech dtmf', 'timeout' => 3,
'numDigits' => 1], ['voice' => 'woman', 'language' => 'fr'] );
// Outputs Twiml.
$foo->renderTwiml();
/* This is what the Twiml output looks like:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather input="speech dtmf" timeout="3" numDigits="1">
<Say voice="woman" language="fr">Hello World!</Say>
</Gather>
</Response>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment