Asterisk bash script read digit

Hello

My goal is to listen to announcements according to a verification code entered on incoming calls.

I did something for that below. My problem is not being able to listen to announcements after verification. What I want to do is to listen to a different announcement if it is true and not an announcement. Bash script verifies. If it is true, it writes 0 if it is not 1.

If it says 1, listen to announcement A. If it says 0, I want to listen to the B announcement. Bash script writes 0 or 1 in a text file.

How can I do that ?

exten => XXXXXXX,1,Goto(s,1)
exten => s,1,Answer()
exten => s,2,Playback(/var/lib/asterisk/ivr/ob1)
exten => s,4,Read(digits)
exten => s,5,System(/app/digist.sh ${digit} > /tmp/log1.log)
exten => s,6,Hangup()

I’m not sure I’m following what you want to do…

You play ob1.
You read a ‘#’ terminated string of digits into a variable named digits.
You execute a Bash script, passing a variable named digit (not digits?) and write the output to a log file.
You hang up.

How do you think your script is telling Asterisk if digit is something or not?

Where in your dialplan do you do anything to listen to announcement A or B?

this shoud be Read(digits,/var/lib/asterisk/ivr/ob1) then you dont need

exten => s,2,Playback(/var/lib/asterisk/ivr/ob1)

Wouldn’t read() behave more like background()?

Won’t digit entry interrupt the playback in read()?

Yes it will interrupt it depending on the maxdigits option you set for the app, if not the timeout option will take place

Very different, one simple match entered digit as an extension in a context, the other save the digit as variable,

The OP used playback() and you suggested that if he used read() correctly, he wouldn’t need playback(). I was merely pointing out that the caller experience would be different since an entry interrupts read() like it does background(), not that background() could replace read().

I do see some issues in your dialplan and I would place ob1 audio in Read itself but if I understand your question correctly then basically you can do something like this.

exten => s,5,System(/app/digist.sh ${digit} > /tmp/log1.log)
exten => s,6,ExecIf($["${digit}" = "1"]?Playback(YOUR_ANNOUNCEMENT_A):ExecIf($["${digit}" = "0"]?Playback(YOUR_ANNOUNCEMENT_B):NoOp()))
exten => s,7,Hangup()

There is no priority 3, in the original dial so Read, and the folllowing priorities, will never be executed.

Hello

Very thanks.
But I do not know what the households to enter are. I have not tried as follows.
X = unknown key (11 digit)

How can I do it ?
exten => s,6,ExecIf(["{digit}" = “XXXXXXXXXXX”]?Playback(YOUR_ANNOUNCEMENT_A)

Let’s forget about posting dialplan snippets with obvious errors or implementation details for awhile.

Let’s work on a clear statement of your goal.

My interpretation of your goal is:

  1. Play a file saying ‘Please enter your 11 digit verification code.’

  2. Allow the caller to enter an 11 digit verification code.

  3. If they entered less than 11 digits or more than 11 digits, play an error message and go to step 1.

  4. Pass the verification code to an external script to validate the code and return the name of an ‘announcement’ file to play.

  5. Play the announcement.

  6. Hang up.

Please correct any misinterpretations.

yes, almost right.

thanks.

Pray tell, what is wrong?

(Thinking to myself I should have taken up dentistry…)

Correct. Can you help me ?

Yes. Please read:

  1. https://wiki.asterisk.org/wiki/display/AST/Contexts%2C+Extensions%2C+and+Priorities

  2. https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+Application_Read

  3. https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+Function_LEN

  4. https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+Application_GotoIf

  5. https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+Application_AGI

And then take a crack at writing your dialplan.

Then, if you need help, please post your dialplan using 'dialplan show ’ and ‘preformatted text’ tags followed by a console log (with debug and verbose set to least 3) in preformatted text tags.