Read() in Asterisk

I have been trying to learn how “read()” works.
In the instruction, it mentioned like this: The parameter “option” got two options :
skip - if this one is specified, the application will return immediately, if the line is not up.
noanswer - if this one is specified, then the application will read the digits even if the line is not up

I did not understand the words “if the line is not up”. If someones have got some user cases like in which case we have line up, and “skip” is supposed to be used and which case the noanswer is supposed to be used

And also some questions regarding the attempts parameters, it mentioned “attempts - here you can specify the desired number of attempts, the user has in case of no data is entered.” if you someones got some example regarding the attempts parameters as well?

Not up, in simple phone terms means that the phone is still on hook. More complex systems can allow audio to be sent before that point and some may even allow incoming audio, which is what noanswer is about. skip is probably about dialplan that may be used before or after answer.

Can you explain what you don’t understand about attempts? You should try using it first.

if (chan->_state != AST_STATE_UP) { if (ast_test_flag(&flags, OPT_SKIP)) { /* At the user's option, skip if the line is not up */ pbx_builtin_setvar_helper(chan, arglist.variable, ""); pbx_builtin_setvar_helper(chan, "READSTATUS", "SKIPPED"); return 0; } else if (!ast_test_flag(&flags, OPT_NOANSWER)) { /* Otherwise answer unless we're supposed to read while on-hook */ res = ast_answer(chan); } }

Thanks for your help, I tried to implement a testing dial plan like this

exten => 203,1,Answer()
exten => 203,n,Background(welcome)
exten => 203,n,Read(digito,20,skip,2,5)
exten => 203,n,SayDigits(${digito})
exten => 203,n,Hangup()

-- Executing [203@myphones:1] Answer("SIP/2000-00000422", "") in new stack
-- Executing [203@myphones:2] BackGround("SIP/2000-00000422", "welcome") in new stack
-- Executing [203@myphones:3] Read("SIP/2000-00000422", "digito,,20,skip,2,5") in new stack
-- Accepting a maximum of 20 digits.
-- User entered nothing, 1 chance left
-- User entered nothing.
-- Executing [203@myphones:4] SayDigits("SIP/2000-00000422", "") in new stack
-- Executing [203@myphones:5] Hangup("SIP/2000-00000422", "") in new stack

== Spawn extension (myphones, 203, 5) exited non-zero on ‘SIP/2000-00000422’

if I reach 203 extension, like the dial plan mentioned, I would have 5 sec to send DTMF to Asterisk. If I understood correctly. If I set attempted number to “2”, after first 5 sec. Asterisk would have another 5 sec. for user to send DTMF signaling.

But I still did not quite clear regarding “skip” and “noanswer”

I think attempts will make a lot more sense if you specificy a filename.

Yes, thanks for your hint, true. I did test that the file will play back twice if attemp set to 2.

by the way, I am thinking that if it possible that make the Read() working like this.

Read(digito,SayDigits(${CALLERID(num)}),20,skip,2,5) …

It means that if I dialed into Asterisk, asterisk would read my caller ID after that read me back the DTMF signaling.

I did a test, like Read(digito,SayDigits(${CALLERID(num)}),20,skip,2,5) or even Read(digito,SayDigits(111),20,skip,2,5). they would not work. If someone have idea that how I could implement a dynamic response message when using Read function.


You can’t use an application as an argument of Read() it must be a filename.
In your case Read is trying to play the file SayDigits(XXXXXXXXX) which doesn’t exist anywhere.
So you have to enter a filename (without extension) existing in folder /var/lib/asterisk/sounds/.
Like this: