Question

I am working on an Asterisk IVR for conducting intra-organization surveys (our employees call in and answer a few questions by pressing keys). The key presses are immediately dumped into a database, and are NOT actually connected to an extension or IVR menu structure. Right now, I'm doing this without any kind of AGI script and would like to keep it that way, if possible.

Example:

[from-internal-custom]
exten => 1234,1,Answer
exten => 1234,2,Wait(1)
exten => 1234,3,Playback(custom/Welcome_message) 
exten => 1234,4,Authenticate(0000) 
exten => 1234,5,Goto(MyCustomApp,s,1)

[MyCustomApp]
exten => s,1,Set(TIMEOUT(digit)=7)
exten => s,n,Set(TIMEOUT(response)=10)
exten => s,n,Playback(custom/QA1) 
exten => s,n,Read(QA1,beep,1,,3,5) 
exten => s,n,SayDigits(${QA1}) 
exten => s,n,MYSQL(Connect connid 127.0.0.1 DB_USER DB_PASS DB_NAME)
exten => s,n,MYSQL(Query r ${connid} Insert Into question_answers SET question_id='0', user_id=${CALLERID(num)}, result=${QA1}) 

[... more questions and finally hangup ...]

The question now is, if the playback for QA1 instructs the caller "Press 1 for yes or 2 for no", but the user presses 3, then 3 is dumped into the database, which is obviously not helpful. How can I limit the allowed keys for each question? I do know about the "i" extension, but I guess this won't get me anywhere. Is there a way to specify precisely which keys are allowed and which not? Preferably without having to wrap my head around AGI? Some questions are yes/no questions, but some other questions have more options ("if x less than 100 press 1, less than 200 press 2, less than 300 press 3" and so on...).

Thanks for your help!

Was it helpful?

Solution 2

This is how i accomplished what i needed (e.g. for a question with the options 1,2,3 and 4):

[...]

exten => s,3,Playback(custom/QA1)
exten => s,4,Read(QA1,beep,1,,3,5)
exten => s,5,SayDigits(${QA1})
exten => s,6,GotoIF($[ "${QA1}" = "1" | "${QA1}" = "2" | "${QA1}" = "3"  | "${QA1}" = "4" ]?s,9:s,7)
exten => s,7,Playback(pbx-invalid)
exten => s,8,Goto(s,3)
exten => s,9,MYSQL(Connect connid 127.0.0.1 USER PASSWORD DB)
exten => s,10,MYSQL(Query r ${connid} Insert Into TABLE_NAME SET question_id='0', user_id='${CALLERID(num)}', result='${QA1}')

[...]

OTHER TIPS

You are dooing it strange. Just use GotoIF to NOT dump anything above 2 to database, and you will be ok.

Also you can use WaitExten&Background

 exten => s,n,Background(message);play message
 exten => s,n,WaitExten(10);wait upto 10 sec for input
 exten => s,n,Noop(no input here)

 exten => 1,1,Noop(1 choice)
 exten => 2,2,Noop(2 choice)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top