Created
April 27, 2012 22:52
-
-
Save TMcManus/2514061 to your computer and use it in GitHub Desktop.
<Gather> a birthday with Twilio
This file contains hidden or 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 | |
$db = new PDO('sqlite:database.sqlite'); | |
// Create the SQLite table. | |
$db->exec('CREATE TABLE gather_date (id INTEGER PRIMARY KEY, call_sid TEXT(32), year TEXT(4), month TEXT(2), day TEXT(2));'); | |
// Populate it with some data | |
$db->exec("INSERT INTO gather_date (call_sid, year, month, day) VALUES ('fhsdhfiuh', '2010', '09', '01');"); | |
if (file_exists('database.sqlite')) | |
{ | |
echo 'Database and tables created.'; | |
} | |
else { | |
echo 'Database was not created. Please check to make sure this directory is writeable.'; | |
} | |
?> |
This file contains hidden or 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 | |
// Collect the Call SID and the month from Twilio's Request | |
$call_sid = $_REQUEST['CallSid']; | |
$day = $_REQUEST['Digits']; | |
// UPDATE day in the database row that matches the Call SID | |
$db = new PDO('sqlite:database.sqlite'); | |
$db->exec("UPDATE gather_date SET day={$day} WHERE call_sid='{$call_sid}';"); | |
// Retrive the entire record from the database | |
$stmt = $db->prepare("SELECT year, month, day FROM gather_date WHERE call_sid='{$call_sid}';"); | |
$stmt->execute(); | |
$result = $stmt->fetch(PDO::FETCH_ASSOC); | |
// Make date readable | |
$birthday_date_object = mktime(0, 0, 0, intval($result['day']), intval($result['month']), intval($result['year'])); | |
$brithday = date('F, jS Y', $birthday_date_object); | |
header('Content-type: text/xml'); | |
echo '<?xml version="1.0" encoding="UTF-8"?>'; | |
?> | |
<Response> | |
<Say>You were born on <?php echo($birthday); ?>, but you don't look a day over 30.</Say> | |
</Response> |
This file contains hidden or 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 | |
// Collect the Call SID and the month from Twilio's Request | |
$call_sid = $_REQUEST['CallSid']; | |
$month = $_REQUEST['Digits']; | |
// UPDATE month in the database row that matches the Call SID | |
$db = new PDO('sqlite:database.sqlite'); | |
$db->exec("UPDATE gather_date SET month={$month} WHERE call_sid='{$call_sid}';"); | |
header('Content-type: text/xml'); | |
echo '<?xml version="1.0" encoding="UTF-8"?>'; | |
?> | |
<Response> | |
<Gather action="final.php" timeout="20" numDigits="2"> | |
<Say>Please enter the day you were born, followed by the #.</Say> | |
</Gather> | |
<Say>We didn't receive any input. Goodbye!</Say> | |
</Response> |
This file contains hidden or 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 | |
// Collect the Call SID and the year from Twilio's Request | |
$call_sid = $_REQUEST['CallSid']; | |
$year = $_REQUEST['Digits']; | |
// UPDATE year in the database row that matches the Call SID | |
$db = new PDO('sqlite:database.sqlite'); | |
$db->exec("UPDATE gather_date SET year={$year} WHERE call_sid='{$call_sid}';"); | |
header('Content-type: text/xml'); | |
echo '<?xml version="1.0" encoding="UTF-8"?>'; | |
?> | |
<Response> | |
<Gather action="gather_day.php" timeout="20" numDigits="2"> | |
<Say>Please enter the month you were born, followed by the #.</Say> | |
</Gather> | |
<Say>Month. We didn't receive any input. Goodbye!</Say> | |
</Response> |
This file contains hidden or 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 | |
// Collect the Call SID from Twilio's Request | |
$call_sid = $_REQUEST['CallSid']; | |
// INSERT Call SID, which is the same for each request Twilio makes durring the call | |
$db = new PDO('sqlite:database.sqlite'); | |
$db->exec("INSERT INTO gather_date (call_sid) VALUES ('{$call_sid}');"); | |
header('Content-type: text/xml'); | |
echo '<?xml version="1.0" encoding="UTF-8"?>'; | |
?> | |
<Response> | |
<Gather action="gather_month.php" timeout="20" numDigits="4"> | |
<Say>Please enter the year you were born, followed by the #.</Say> | |
</Gather> | |
<Say>Year. We didn't receive any input. Goodbye!</Say> | |
</Response> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment