Asterisk cmd Read Chinese

Synopsis

讀取用戶輸入的數字(DTMF)按鍵。

語法描述

Asterisk 1.0:
Read(variable[|filename][|maxdigits][|option])
Asterisk 1.2:
Read(variable[|filename][|maxdigits][|option][|attempts][|timeout])
Asterisk 1.4以上:
Read(variable[,filename][,maxdigits][,option][,attempts][,timeout])
Read(變量名稱[,要撥放的提示音檔][,最大數字][,option][,attempts][,時間限制])

讀取用戶輸入的一個以 # 結尾的數字字符串到指定的變量。

  • variable: variable是存儲用戶按鍵的地方.
  • filename: 讀取按鍵之前要播放的文件.
  • maxdigits: 接收按鍵的最大個數. 當收到maxdigits個按鍵後就停止讀取按鍵 (不需要用戶按鍵 '#' ). 默認是 0 - 無限制 - 等待用戶按 '#' 鍵. 任何低於0的值表示0,最大值是255.
  • option: 可用選項有3個(sin), s(skip):表示如果線路沒摘機就立即返回,i(indication):改撥放一聲簡短的提示音,n(noanswer):表示線路沒起來也讀按鍵。
  • attempts: 如果大於1, 在沒有用戶按鍵的情況下會多次重複執行。
  • timeout: 超時時長(秒). 如果大於 0, 這個值就會覆蓋預設的超時時長.

Read 在失敗或報錯的時候會斷開。

Example


;下面的例子使用 Read 和 SayDigits 來讀取3位用戶按鍵,然後說出來。 

Asterisk 1.2:
  ~np~exten => s,1,Gotoif($[ "${LEN(${extensao})}" < "3"]?3:100)~/np~
  exten => s,n,NoOp(Executing - ${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:
  ~np~exten => s,1(start),Gotoif($[ "${LEN(${extensao})}" < "3"]?collect:pstn)~/np~
  exten => s,n,NoOp(Executing - ${extensao} - )
  exten => s,n(collect),Read(digito,,1)
  exten => s,n,SayDigits(${digito})
  exten => s,n,Set(extensao=${extensao}${digito})
  exten => s,n,GoTo(start)
  exten => s,n(pstn),GoTo(from-pstn,s,1)
  exten => h,1,hangup()


; The following example is a work-around that mostly works at catching # as part of the dial string.
  ;Written in 1.8.  Compatibility unknown.
  exten => s,1,Set(wait=2)
  exten => s,n(begin),Playback("please-dial-now")
  exten => s,n,Set(gottries=0)
  exten => s,n,Set(got=)
  exten => s,n(getmore),Set(timer=${EPOCH})
  exten => s,n,Read(get,"silence/1",,,,${wait})
  exten => s,n,Set(timer=$[${EPOCH}-${timer}])
  exten => s,n,GotoIf($[${timer}==$[${wait}+1]]?gotnothing:gotsomething)
  
  ;I double-check the length of get below in case the user happened to enter
  ;digits, but did so in such a manner that the epoch math thinks nothing
  ;was entered.  I suppose the same could happen with pound, but because
  ;pressing pound ends the read (and thus shortens the epoch), It is much
  ;less likely.
  exten => s,n(gotnothing),Set(gottries=$[${gottries}+1]
  exten => s,n,GotoIf($[${LEN(${get})} == 0]?reallynothing:gotdigit)
  exten => s,n(reallynothing),GotoIf($[${gottries}>1]?done:getmore)
  
  exten => s,n(gotsomething),Set(gottries=0)
  exten => s,n,GotoIf($[${LEN(${get})} == 0]?gotpound:gotdigit)
  exten => s,n(gotpound),Set(got=${got}#)
  exten => s,n,Goto(getmore)
  exten => s,n(gotdigit),Set(got=${got}${get})
  exten => s,n,Set(get=)
  exten => s,n,Goto(getmore)
  
  exten => s,n(done),SayDigits(${got})
  exten => s,n,Goto(begin)
  
  ; Doubt we get here:
  exten => i,1,Playback("vm-goodbye")
  exten => i,n,Hangup()
  
  ; here either:
  exten => u,1,Playback("vm-goodbye")
  exten => u,n,Hangup()


豎線符號 ( | ) 在 Asterisk 1.6版本中已經改為逗號( , )。
在Asterisk 1.4,豎線號和逗號都可以用,適用逗號方便以後的升級。
'#' 是輸入結束鍵. Read()不會接收井號鍵。

警告:
在Asterisk 1.4: "filename" 參數不接受串接 (比如:file1&file2&file...)
但可用於 Asterisk 1.8.4 以上的版本


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

Synopsis

讀取用戶輸入的數字(DTMF)按鍵。

語法描述

Asterisk 1.0:
Read(variable[|filename][|maxdigits][|option])
Asterisk 1.2:
Read(variable[|filename][|maxdigits][|option][|attempts][|timeout])
Asterisk 1.4以上:
Read(variable[,filename][,maxdigits][,option][,attempts][,timeout])
Read(變量名稱[,要撥放的提示音檔][,最大數字][,option][,attempts][,時間限制])

讀取用戶輸入的一個以 # 結尾的數字字符串到指定的變量。

  • variable: variable是存儲用戶按鍵的地方.
  • filename: 讀取按鍵之前要播放的文件.
  • maxdigits: 接收按鍵的最大個數. 當收到maxdigits個按鍵後就停止讀取按鍵 (不需要用戶按鍵 '#' ). 默認是 0 - 無限制 - 等待用戶按 '#' 鍵. 任何低於0的值表示0,最大值是255.
  • option: 可用選項有3個(sin), s(skip):表示如果線路沒摘機就立即返回,i(indication):改撥放一聲簡短的提示音,n(noanswer):表示線路沒起來也讀按鍵。
  • attempts: 如果大於1, 在沒有用戶按鍵的情況下會多次重複執行。
  • timeout: 超時時長(秒). 如果大於 0, 這個值就會覆蓋預設的超時時長.

Read 在失敗或報錯的時候會斷開。

Example


;下面的例子使用 Read 和 SayDigits 來讀取3位用戶按鍵,然後說出來。 

Asterisk 1.2:
  ~np~exten => s,1,Gotoif($[ "${LEN(${extensao})}" < "3"]?3:100)~/np~
  exten => s,n,NoOp(Executing - ${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:
  ~np~exten => s,1(start),Gotoif($[ "${LEN(${extensao})}" < "3"]?collect:pstn)~/np~
  exten => s,n,NoOp(Executing - ${extensao} - )
  exten => s,n(collect),Read(digito,,1)
  exten => s,n,SayDigits(${digito})
  exten => s,n,Set(extensao=${extensao}${digito})
  exten => s,n,GoTo(start)
  exten => s,n(pstn),GoTo(from-pstn,s,1)
  exten => h,1,hangup()


; The following example is a work-around that mostly works at catching # as part of the dial string.
  ;Written in 1.8.  Compatibility unknown.
  exten => s,1,Set(wait=2)
  exten => s,n(begin),Playback("please-dial-now")
  exten => s,n,Set(gottries=0)
  exten => s,n,Set(got=)
  exten => s,n(getmore),Set(timer=${EPOCH})
  exten => s,n,Read(get,"silence/1",,,,${wait})
  exten => s,n,Set(timer=$[${EPOCH}-${timer}])
  exten => s,n,GotoIf($[${timer}==$[${wait}+1]]?gotnothing:gotsomething)
  
  ;I double-check the length of get below in case the user happened to enter
  ;digits, but did so in such a manner that the epoch math thinks nothing
  ;was entered.  I suppose the same could happen with pound, but because
  ;pressing pound ends the read (and thus shortens the epoch), It is much
  ;less likely.
  exten => s,n(gotnothing),Set(gottries=$[${gottries}+1]
  exten => s,n,GotoIf($[${LEN(${get})} == 0]?reallynothing:gotdigit)
  exten => s,n(reallynothing),GotoIf($[${gottries}>1]?done:getmore)
  
  exten => s,n(gotsomething),Set(gottries=0)
  exten => s,n,GotoIf($[${LEN(${get})} == 0]?gotpound:gotdigit)
  exten => s,n(gotpound),Set(got=${got}#)
  exten => s,n,Goto(getmore)
  exten => s,n(gotdigit),Set(got=${got}${get})
  exten => s,n,Set(get=)
  exten => s,n,Goto(getmore)
  
  exten => s,n(done),SayDigits(${got})
  exten => s,n,Goto(begin)
  
  ; Doubt we get here:
  exten => i,1,Playback("vm-goodbye")
  exten => i,n,Hangup()
  
  ; here either:
  exten => u,1,Playback("vm-goodbye")
  exten => u,n,Hangup()


豎線符號 ( | ) 在 Asterisk 1.6版本中已經改為逗號( , )。
在Asterisk 1.4,豎線號和逗號都可以用,適用逗號方便以後的升級。
'#' 是輸入結束鍵. Read()不會接收井號鍵。

警告:
在Asterisk 1.4: "filename" 參數不接受串接 (比如:file1&file2&file...)
但可用於 Asterisk 1.8.4 以上的版本


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

Created by: dominic16y, Last modification: Mon 24 of Sep, 2012 (07:57 UTC)
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+