Tim Strimple joined us at the LA Holiday Hackathon to get in on the competition of building Tropo applications for prizes and won a $50 Tropo Production credit for his Tropo SMS and Wolfram Alpha mashup!

You can ask the application virtually any question via SMS using the following phone number 661-206-2681 and it responds to your inquiry via SMS using Wolfram Alpha’s search results. Here’s a video of Tim demonstrating his application in action!

Here’s the code behind Tim’s Tropo SMS Wolfram Alpha mashup! It’s written in PHP and uses the Tropo Scripting API.

<?php  

function CheckForShortcut($request)
{
    if(stripos($request, "siri") !== false)
    {
        return "I don't like to talk about her.";
    }

    if(stripos($request, "remind") !== false)
    {
        return "I am not your personal assistant.";
    }

    if(stripos($request, "tropo") !== false)
    {
        return "Tropo is great, I love it!";
    }

	return false;
}

function ParseResponse($response)
{	
	//	Replace with real XML parsing
	$min = strpos($response, "</plaintext>");    
	$startPos = strpos($response, "<plaintext>", $min)   11;
    $endPos = strpos($response, "</plaintext>", $startPos);
	$length =  $endPos - $startPos;

	if($min > 0)
	{
		return substr($response, $startPos, $length);	
	}
	else
	{
		return "Go ask Siri...";
	}
}

function GetResults($request)
{
    $shortcut = CheckForShortcut($request);

    if($shortcut)
    {
        return $shortcut;
    }

    $request = str_replace (" ", " ",$request);
	$wolframApiKey = "XXXXXX-XXXXXXXXXX";
    $url = "http://api.wolframalpha.com/v2/query?appid=" . $wolframApiKey . "&input=" . $request;
    $response = file_get_contents($url);

	return ParseResponse($response);
}

if($currentCall->channel == "TEXT")
{
    $result = GetResults($currentCall->initialText);
    say($result);
}
else
{
    say("I do not support voice currently. Try sending me a text message instead.");
}
?>

Happy Hacking!

©2011 The Tropo Blog. All Rights Reserved.

.

Related posts:

  1. LA Holiday Hackathon :: Results
  2. Text2Play Makes ProgrammableWeb’s Mashup of the Day!
  3. Info Balloon: Multi-language Location-based Tropo Mashup

Originally from All Voxeo Blogs Feed