Skip to content

Instantly share code, notes, and snippets.

@mheadd
Created October 23, 2015 17:10
Show Gist options
  • Save mheadd/9337390b834b746bc1ce to your computer and use it in GitHub Desktop.
Save mheadd/9337390b834b746bc1ce to your computer and use it in GitHub Desktop.
A simple Tropo app to lookup permit status using an Open Permit API
<?php
// Open permit API
define("URL_BASE", "http://mdc.openpermit.org/op/permits");
// Simple utility method to make API call.
function getPermitData($num) {
$url = URL_BASE . "?number=" . $num;
$permit_data = file_get_contents($url);
return json_decode($permit_data);
}
function formatOutput($text, $channel) {
if ($channel == "VOICE") {
return implode(" ", str_split($text));
}
else {
return substr($text,0,4) . "-" . substr($text,4,3) . "-" . substr($text,7,3);
}
}
// SMS
if($currentCall->initialText) {
$permit_number = $currentCall->initialText;
$permit_data = getPermitData($permit_number);
}
// Phone
else {
$permit = ask("Please enter your 10 digit permit number.", array("choices" => "[10 DIGITS]", "mode" => "dtmf", "attempts" => 3, "timeout" => 7));
$permit_number = $permit->value;
$permit_data = getPermitData($permit_number);
}
// Render output to user
if(count($permit_data) > 0) {
say('The current status of permit number ' . formatOutput($permit_number, $currentCall->channel) . ' is ' . $permit_data[0]->statusCurrent);
}
else {
say('No permit found with number: ' . $currentCall->initialText);
}
// Be nice.
if($currentCall->channel == "VOICE") {
say('Thank you.');
}
hangup();
@mheadd
Copy link
Author

mheadd commented Oct 23, 2015

Test this application by calling (407) 545-6917, or by texting a permit number to this phone number.

fullsizerender

@mheadd
Copy link
Author

mheadd commented Oct 23, 2015

Can also link this up to a QR Code to allow someone to scan a posted permit and check the status via SMS.

qr-code-permit-status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment