login | register
Thu 08 of Jan, 2009 [23:41 UTC]

voip-info.org

History

Asterisk cmd Read

Created by: oej,Last modification on Tue 06 of Jan, 2009 [16:43 UTC] by elizabethgreene

Synopsis

Read a variable in the form for DTMF tones as pressed by the caller

Description

As of Asterisk 1.0:
 Read(variable[|filename][|maxdigits][|option])
As of Asterisk 1.2:
 Read(variable[|filename][|maxdigits][|option][|attempts][|timeout])
As of Asterisk 1.4:
 Read(variable[,filename][,maxdigits][,option][,attempts][,timeout])

Reads a #-terminated string o
f digits a certain number of times from the user in to the given variable.
  • variable: variable where the user's response will be stored.
  • filename: file to play before reading digits.
  • maxdigits: maximum acceptable number of digits. Stops reading after maxdigits have been entered (without requiring the user press the '#' key). Defaults to 0 - no limit - wait for the user press the '#' key. Any value below 0 means the same. Max accepted value is 255.
  • option: may be 'skip' to return immediately if the line is not up, or 'noanswer' to read digits even if the line is not up.
  • attempts: if greater than 1, that many attempts will be made in the event no data is entered.
  • timeout: Timeout in seconds. If greater than 0, that value will override the default timeout.

Read should disconnect if the function fails or errors out.


; The Following Example uses Read and Say digits to read 3 digits from user, saying each one as user types.
Asterisk 1.2:
exten => s,1,Gotoif($[ "${LEN(${extensao})}" < "3"]?3:100)
exten => s,n,NoOp(executando - ${extensao} - )
exten => s,n,Read(digito||1)
exten => s,n,SayDigits(${digito})
exten => s,n,Set(extensao=${extensao}${digito})
exten => s,n,GoTo(s,1)
exten => s,100,GoTo(from-pstn,s,1)
exten => h,1,hangup()

Asterisk 1.4, 1.6:
exten => s,1,Gotoif($[ "${LEN(${extensao})}" < "3"]?3:100)
exten => s,n,NoOp(executando - ${extensao} - )
exten => s,n,Read(digito,,1)
exten => s,n,SayDigits(${digito})
exten => s,n,Set(extensao=${extensao}${digito})
exten => s,n,GoTo(s,1)


Note:
Pipe characters ( | ) have been changed to commas in Asterisk 1.6.
In Asterisk 1.4, either pipes OR commas will work. Using commas will ease future upgrades.

'#' is the End-Of-Input Key. It is NOT possible to accept '#' with Read()

Warning:
In Asterisk 1.4: the "filename" field does not accept concatenation (file1&file2&file...).

Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ


Comments

Comments Filter
222

333Multiple sound files issue

by baji, Sunday 22 of June, 2008 [03:01:29 UTC]
Its too bad that Read cannot combine multiple sound files like Playback() and Background() can.

For a dialplan with static sound file names you can use - sox file1 file2 file3 file4 file1234 - to combine sound files 1,2,3&4 into file1234. it doesn't work when the sound filename is dynamically determined.

I use Read() way more frequently than Playback or Background.
222

3331.6 Change

by dennisd, Sunday 30 of March, 2008 [21:51:09 UTC]
In 1.6 it seems that the separator has changed from | to ,
222

333Cannot combine multiple sound files

by opus61856, Friday 21 of September, 2007 [20:45:42 UTC]
Unlike the Background command, the Read command does not allow multiple sound files to be concatenated together (via the &) and played consecutively.
222

333No Timeout

by opus61856, Friday 31 of August, 2007 [15:42:57 UTC]
Read command does not execute timeout code (ie t,1,NoOp). If you want to know if a timeout occured exam the variable to see if it's empty.