Archive for the ‘IM’ Category

Tutorial: Using Loops & Functions in your Tropo applications

Monday, April 26th, 2010

Hello,

This afternoon I got a ticket over here at the Fortress of Solitude, err I mean Voxeo Support that I thought I would share with the class. This developer opened a ticket asking how to implement control document execution in his applications. In short he was looking to prompt his callers, in a loop, and stay in said loop until the user explicitly opts to hung up, or proceed with the call. This developer was stuck on whether or not he would have to explicitly repeat the ask() with each iteration.

The developer was also wondering how he could alternate prompts in hopes of giving his application a more natural feel for his users. I could immediately see how implementing this could be confusing for some of our developers, and also how this could be helpful on any channel not just Voice (SMS, Instant Message, Twitter,ect). This being the case I thought this most certainly warranted a blog posting to shared the example with our developers in hopes it may prove helpful; And now for our feature presentation….

<?php
answer();

//Global options for ask, declare once, use many =)
$globalOptions = array(
  "choices"     => "one( 1, one), two( 2, two),exit(3,exit)", 
  "repeat"      => 3,
  "onBadChoice" => create_function( '$event', 'say("I am sorry, I did not understand what you said.");' ),
  "onTimeout"   => create_function( '$event', 'say("I am sorry.  I didn\'t hear anything.");' )
	);

$promptArray = array(
    "Hello, to select the first option please press or say one, for the second option please press or say two.  To exit the application please say exit or just press 3",
    "For option one press or say one, or for option two press or say two"
   );
$promptIteratorVariable = 0;
/**
 * whichPromptToSay
 *
 * @return Array element of  our array ($promptArray) depending on count of $promptIteratorVariable
 */

function whichPromptToSay(){
	global $promptArray;
	if ($promptIteratorVariable==0){
		$promptIteratorVariable++;
		return $promptArray[0];
	}else{
		return $promptArray[1];
	}
}

/**
 * whichVerbToSay()
 *
 * @return element of our verb array
 */
$verbArray = array("selected","chose","picked","opted for");

function whichVerbToSay(){
	return $verbArray[rand(0,(count($verbArray)-1))];
}

//We will continue our loop until false, but first we need to set to true
$continueLoop = true;

while($continueLoop){
$result = ask(whichPromptToSay(),$globalOptions);
	if($result->name=='choice'){
		if ($result->value=="one"){
			say( "You " . whichVerbToSay() . " option one");
		}elseif ($result->value=="two"){
			say( "You " . whichVerbToSay() . " option two");
		}elseif ($result->value=="exit"){
			say( "peace out");
				$continueLoop = false;
		}
	}
}
hangup();
?>

The thing to take home from this example is that you can make use of functions to add a bit of flair to your applications, as well as loops to control application execution. These two techniques will hopefully not only help you have cleaner code, but also help you provide a better, more natural, user experience for your callers! If there are any questions on anything presented here please don’t hesitate to let us know, as our team is most certainly standing by to offer any help our developers may require!

Regards,

John Dyer
Customer Engineer
Voxeo Support

Add SMS and IM to any existing Tropo application in Ruby, python, PHP, JavaScript or Groovy… today!

Tuesday, August 25th, 2009

As part of our Prophecy 10 announcement today, you can now immediately start to add SMS and instant messaging to your existing (or new) Tropo applications. When you login to Tropo and look at the settings for one of your applications, you will see that you now have new settings:

troposmsim.jpg

All you need to do is follow the links and instructions and… ta da… you now have a single “communications app” that is communicating with users through voice, SMS, and IM. (And yes, you could of course create a “SMS-only” or “IM-only” app that purely interacts with users via those mediums.)

Please do check it out… try it out (perhaps with the sample apps available at docs.tropo.com)… and let us know what you think. And if you come up with a great sample app using the IM or SMS side of things, we’d love to hear about it and potentially point it out to others.

Technorati Tags: , , , , , , , ,