My colleague, Phil, wrote a neat little mashup with Yelp - the business review site. His took a business' phone number as input and then came back and told you the average review as well as the number of reviews. So when he was walking around, he could look at a place's phone number and quickly find out if it was any good. I thought this was cool, but wanted to create something for a different situation.
What if I was in an unfamiliar location? Wouldn't it be cool if I could find a couple places near by where I could relax and have a drink and watch the game? So I created this slightly complex mashup that takes input of a Zip code, and will come back with a list of 3 nearby bars. If you want, it'll even connect you to them right away in case you need directions.
How:
IfByPhone: I needed 2 different Survos. The first just gathers the Zip code and posts it to my web page. The second takes back all the information I gathered and repeats it back to the caller. It will read off the 3 bars, tell you their phone number and then offer you the ability to transfer to it if you'd like.
Yelp: Yelp provides a way for you to input a latitude and longitude and get search results based on a search term (in our case, 'bars'). It accepts calls via HTTP and responds in JSON. (link)
Yahoo: Provides a free API that accepts a Zip and reponds with a latitude and longitude. (link)
Code:
// this is a standard cleaning routine. It strips characters that our Survo's don't like automagically.
include("ibpcleanforvoice.include.php");
// CAPTURE THE BUSINESS PHONE NUMBER SENT FROM IFBYPHONE $zip = $_REQUEST['zip'];
// this is the ID of the Survo that will accept the results from the Yelp call $valid_business_survo = "XXXX";
$record = $obj->Result[0]; $lat = $obj->Result->Latitude; $long = $obj->Result->Longitude; -- The above code translates the Zip from the input to a lat & long --
$obj = json_decode($text); -- This code gets the results from Yelp and puts them into $obj. In order to control the call using IfByPhone, I need to create an XML stream that includes the next step (the Valid Business Survo ID), and what parameters I am going to need. Below I am constructing that XML response --
echo $xml_return; -- The XML is created and I echo the results. IfByPhone then routes the call to the Survo I have already set up, and uses Text To Speech to read that data to the caller. --