Last active
June 29, 2017 00:37
-
-
Save jmadden/774e7dee3ac86116c465059005ead7a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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