Asterisk Numbers Guessing Game Howto

  1. First, we have to grab the sound files

     guessit.tgz
     ** note, lost backups, no file. You can create your own :)
    
  2. Now, we copy these to our asterisk sounds directory

     # mv guessit.tgz /var/lib/asterisk/sounds/
    
  3. Now we must untar the sound files into the guessit directory

     # cd /var/lib/asterisk/sounds# tar xzvf guessit_sounds.tgz
    
  4. You should have files like the following

     # cd guessit
     # ls  
     goodbye.gsm input-number.gsm input_number.gsm intro.gsm less.gsm more.gsm playagain.gsm suityourself.gsm thatsnotanumber.gsm win.gsm
    
  5. Now we have to add the game extension to asterisk’s extensions.conf, or other files if you are using includes. Here it is in one simple block.

     ; go to the game extension  
     exten => 8006,1,Wait(1)  
     exten => 8006,n,Goto(guessgame,s,1)
    
     [timehang]  
     ; if they take too long say it's invalid
    
     exten => t,1,Playback(goodbye)  
     exten => t,2,Hangup  
     exten => i,1,Playback(invalid)
    
     [guessgame]  
     include => timehang  
     exten => s,1,Playback(guessit/intro)  
     exten => s,2,Set(GUESS="")  
     exten => s,3,Set(GUESS=$[${EPOCH} % 9])  
     exten => s,4,Read(NUMBER,guessit/input_number,1)  
     exten => s,5,Set(TIMEOUT(digit)=3)  
     exten => s,6,Set(TIMEOUT(response)=5)  
     exten => s,7,GotoIf($["${NUMBER}" = "${GUESS}"]?19:8)  
     exten => s,8,GotoIf($["${NUMBER}" > "${GUESS}"]?13:9)  
     exten => s,9,GotoIf($["${NUMBER}" < "${GUESS}"]?15:10)  
     exten => s,10,GotoIf($["${NUMBER}" = "*"]?17:17)  
     exten => s,11,GotoIf($["${NUMBER}" = "#"]?17:17)  
     exten => s,12,Goto(s,4)  
     exten => s,13,PlayBack(guessit/less)  
     exten => s,14,Goto(s,4)  
     exten => s,15,PlayBack(guessit/more)  
     exten => s,16,Goto(s,4)  
     exten => s,17,PlayBack(guessit/thatsnotanumber)  
     exten => s,18,Goto(s,4)  
     exten => s,19,PlayBack(guessit/win)  
     exten => s,20,Wait(.5)  
     exten => s,21,Background(guessit/playagain)  
     exten => 1,1,Goto(guessgame,s,1)  
     exten => 2,1,Playback(goodbye)  
     exten => 2,2,Hangup
    
  6. That’s it. Reload Asterisk, and dial 8006 and you should be able to start the game!

  7. Have fun!

Comments

Comment by Someone on 2006-12-04 17:52:58 -0500

At step 6, no need to restart, a reload will do
You know, this is not Windows πŸ˜‰

Comment by Matt Gibson on 2006-12-04 20:12:05 -0500

Hi Someone,

Thanks for the note. I meant reload, not restart. The howto has been updated to reflect the proper wording πŸ™‚

Good catch!

Comment by Steve Murphy on 2006-12-05 15:57:00 -0500

Hello–

I suppose this is grossly obsessive-compulsive, but I took a few minutes and translated the above extensions.conf into AEL.

β€”- cut here β€”β€”β€”file=guessit.aelβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
macro guessgame()
{
while (1)
{
Playback(guessit/intro);
set(GUESS="");
GUESS=${EPOCH}%9;
Set(TIMEOUT(digit)=3);
Set(TIMEOUT(response)=5);
while (1)
{
Read(NUMBER,guessit/input_number,1);
Verbose(Got ${NUMBER} from Read);
if( “${NUMBER}” = “*” || “${NUMBER}” = “#” || “${NUMBER}” = “”)
{
Playback(guessit/thatsnotanumber);
}
else if ("${NUMBER}" = “${GUESS}”)
{
Playback(guessit/win);
break; // the only way out of this loop!
}
else if ("${NUMBER}" > “${GUESS}”)
{
Playback(guessit/less);
}
else if ("${NUMBER}" {
&guessgame();
}

In the above, dialing 779 will trigger the game.

All these instructions apply to 1.4 and trunk versions of Asterisk. For those running 1.2, I suggest making a 1.2 patch, and installing AEL2. It most likely will not work on the original AEL code that comes with 1.2.

I wrote the code as an example, it has no goto’s. It implements the game as nested loops. I will also post it on the voip-info asterisk wiki in the AEL examples page.

There are some slight variations from the original code

murf

Comment by flewid on 2006-12-05 16:02:40 -0500

Awesome. Thanks!