The OpenVBX + SimpleGeo Weather Plugin

OpenVBX plugins can be rich applications with robust functionality but they can also be almost amazingly simple and still pack quite a punch.  OpenVBX takes care of so much of the heavy lifting for building phone apps that you can build phone interfaces that talk to APIs with only a few lines of code.

The SimpleGeo Weather Phone

The SimpleGeo Weather plugin is an example of a very simple plugin that gives callers the weather conditions in a certain area in only a few lines of code.  SimpleGeo has a Context API that provides weather, demographics, or neighborhood data for a specific location.  It also provides map boundaries, congressional districts, sports venues and more.

What we’re using it for here is the weather.  To keep it simple, we’ll stick to the most general overview of the weather (think “cloudy”) but it gives you high and low temperatures, wind speed and direction, humidity and more.

How it Works

First, the code for the plugin is here:  so download that to your plugins directory and follow along.  It uses a slightly modified helper library that has an extra function in it for the weather interface.

The first file of interest is ui.php because it defines the User Interface.

<?php $address = AppletInstance::getValue('address', 'New York, NY'); ?>
<div>
<h2>Enter city and state here and your callers will here the current conditions there.</h2>
<p>This is brought to you by the SimpleGeo API</p>
<div><input name="address" value="<?php echo $address; ?>"></div>
</div>

and this is what it looks like when you drag it into the call flow:

By creating an input element named “address” we can refer back to the value that was entered in the form later by calling the AppletInstance::getValue() function.  Now when someone drags our applet into a call flow and creates an instance of it they can configure it with the city and state it should use to look up the weather.

The next file is twiml.php and it does all the interfacing with Twilio and it’s also pretty straightforward

<?php

   $plugin = OpenVBX::$currentPlugin;
   $info = $plugin->getInfo();
   $path = $info['plugin_path'];

   include($path . "/php-simplegeo/SimpleGeo.php");

   $client = new SimpleGeo('xxxx','xxxx');

   $address = AppletInstance::getValue('address', 'New York, NY');
   $weather = $client->WeatherAddress($address);
   $condition = $weather['weather']['conditions'];

   $response = new Response();
   $response->addSay("The weather in ${address} is ${condition}");
   $response->Respond();
?>

There’s that AppletInstance::getValue() function again and a call to the SimpleGeo API.

Try It

You can try this out right now! Call (651) 433 6297 and follow the prompts to hear the weather in Atlanta, New York, Kansas City or Austin.

What else can it do?

Since Twilio gives you the city, state and zip of the phone number that’s calling your application it could default to using that if you don’t configure an address ahead of time.  It could also prompt the user for a zip code and then give them the weather.

You could even use weather data to alter the behavior of your phone system.  For example, it’s very hot outside so your phone system reminds people to drink plenty of water while they’re waiting on hold.

The great thing about OpenVBX plugins is that you can so quickly integrate the behavior of your phone system with data from other APIs like Foursquare, SimpleGeo, Twitter, FaceBook and thousands more.

Post a Comment

Your email is never shared. Required fields are marked *

*
*