[ N O C T E R N I T Y ] Contributing to the general pollution of the internet


Playing with Asterisk (3/?) – A menu (sort of)

I wanted to try adding something that sort of feels like a menu to the dial plan. I am not sure that I will actually use one in the final setup, but it wasn't that much effort anyway.

A menu (or something with similar functionality) can be implemented using either Background() or WaitExten(). Or both, actually. Since I don't have anything to play as a prompt, I chose to do with the latter only. After all, this is only a test.

First, I replaced the previous test with the following:


exten => 8378,1,Answer()
        exten => 8378,n,Set(TESTCOUNT=0)
        exten => 8378,n,Goto(numbers,0,1)

This will cause Asterisk to answer calls to 8378 ("test"), set a channel-specific variable called TESTCOUNT to zero, and jump to extension 0 of the numbers section in the dial plan. The idea is to accumulate the digits typed by the user, and then to have Asterisk say that number. So, for each possible digit, the section will contain something like this:


exten => 0,1,Set(TESTCOUNT=$[ ${TESTCOUNT} * 10 ])
        exten => 0,n,WaitExten()
exten => 1,1,Set(TESTCOUNT=$[ ${TESTCOUNT} * 10 + 1 ])
        exten => 1,n,WaitExten()
; ... Same thing for 2 - 9 here ...

Finally, pressing the star key will cause the system to say the number (using SayNumber()) that was typed and to hangup.

    exten => *,1,SayNumber(${TESTCOUNT})
	    exten => *,n,Hangup()

Posted by Emmanuel Benoît

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment


No trackbacks yet.