英文:
Asterisk, Goto+Hungup
问题
我需要一个扩展,需要播放一个随机音频文件,播放完成后挂断通话。我有以下拨号计划,例如,播放第二个音频,然后播放第三个等等,但应在播放一个音频文件后挂断。
```exten => 123.,7,Goto(${RAND(8,12)})
exten => 123.,8,Playback(/var/lib/asterisk/sounds/customer_Menu1)
exten => 123.,9,Playback(/var/lib/asterisk/sounds/customer_Menu2)
exten => 123.,10,Playback(/var/lib/asterisk/sounds/customer_Menu3); 播放后应挂断
exten => 123.,11,Playback(/var/lib/asterisk/sounds/customer_Menu4)
exten => 123.,12,Playback(/var/lib/asterisk/sounds/customer_Menu5)
exten => 123.,13,Hangup()
exten => 123.,14,Hangup(34)
如何使其工作:拨号、播放一个随机菜单,然后挂断?
<details>
<summary>英文:</summary>
There is an extension, for which I need a random sound file to be played, and once it's played the call should be hung up. I have the below dialplan which plays, for example, the 2nd playback and then 3rd one is played etc., but it should hangup after playing back one sound file
exten => 123.,7,Goto(${RAND(8,12)})
exten => 123.,8,Playback(/var/lib/asterisk/sounds/customer_Menu1)
exten => 123.,9,Playback(/var/lib/asterisk/sounds/customer_Menu2)
exten => 123.,10,Playback(/var/lib/asterisk/sounds/customer_Menu3); after playback it supposed rejected..
exten => 123.,11,Playback(/var/lib/asterisk/sounds/customer_Menu4)
exten => 123.,12,Playback(/var/lib/asterisk/sounds/customer_Menu5)
exten => 123.,13,Hangup()
exten => 123.,14,Hangup(34)
How can I make this work; calling, playing only one random menu and hanging up?
</details>
# 答案1
**得分**: 1
只需给挂断命令添加一个优先级标签,并在播放每个项目后添加一个指向它的[`Goto()`][1]。
另外:
- 如果您想要为分机使用模式匹配(我假设这就是为什么在123后面有一个点),您应该在其前面加上下划线。
- `same`可以用于代替`exten => ...`作为分机的扩展,当您重复相同的内容时。
- `n`可以用于下一个优先级,这样您就不必担心保持所有数字的顺序一致。
现在,如果我们去掉优先级编号,您可以使用什么来替代 `Goto(${RAND(8,12)})`?更多标签:
```none
[mycontext]
exten => _123.,1,NoOp("上下文开始")
; ...
same => n,Goto(menu${RAND(1,5)})
same => n(menu1),Playback(/var/lib/asterisk/sounds/customer_Menu1)
same => n,Goto(goodbye)
same => n(menu2),Playback(/var/lib/asterisk/sounds/customer_Menu2)
same => n,Goto(goodbye)
same => n(menu3),Playback(/var/lib/asterisk/sounds/customer_Menu3)
same => n,Goto(goodbye)
same => n(menu4),Playback(/var/lib/asterisk/sounds/customer_Menu4)
same => n,Goto(goodbye)
same => n(menu5),Playback(/var/lib/asterisk/sounds/customer_Menu5)
same => n(goodbye),Hangup(34)
或者,更简单地,使用RAND()
函数来选择要播放的文件的名称:
[mycontext]
exten => _123.,1,NoOp("上下文开始")
; ...
same => n,Playback(/var/lib/asterisk/sounds/customer_Menu${RAND(1,5)})
same => n,Hangup(34)
英文:
Just give the hangup command a priority label and add a Goto()
pointing to it after playing each item.
Also:
- if you want to use pattern matching for an extension (I assume that's why you have a dot after 123) you should prefix it with an underscore
same
can be used in place ofexten => ...
for the extension when you're repeating the same thingn
can be used for the next priority so you don't have to worry about keeping all the numbers straight
Now if we get rid of the priority numbers, what do you use in place of Goto(${RAND(8,12)})
? More labels:
[mycontext]
exten => _123.,1,NoOp("start of context")
; ...
same => n,Goto(menu${RAND(1,5)})
same => n(menu1),Playback(/var/lib/asterisk/sounds/customer_Menu1)
same => n,Goto(goodbye)
same => n(menu2),Playback(/var/lib/asterisk/sounds/customer_Menu2)
same => n,Goto(goodbye)
same => n(menu3),Playback(/var/lib/asterisk/sounds/customer_Menu3)
same => n,Goto(goodbye)
same => n(menu4),Playback(/var/lib/asterisk/sounds/customer_Menu4)
same => n,Goto(goodbye)
same => n(menu5),Playback(/var/lib/asterisk/sounds/customer_Menu5)
same => n(goodbye),Hangup(34)
Or, more simply, use the RAND()
function to choose the name of the file to play:
[mycontext]
exten => _123.,1,NoOp("start of context")
; ...
same => n,Playback(/var/lib/asterisk/sounds/customer_Menu${RAND(1,5)})
same => n,Hangup(34)
答案2
得分: 0
以下是翻译好的部分:
应该是这样的:
exten => _123.,7,Set(FILES=customer_Menu1:customer_Menu2:customer_Menu3)
same => n,Playback(${CUT(FILES,:,${RANDOM(1,3)}); CUT将获取由冒号分隔的第n个参数
same => n,Hangup(34)
或者像miken32所展示的,如果您的文件始终具有相同的名称。
还有一个好主意是将配置变量,如FILES,放在[general]部分或代码中包含的特殊文件中。
在每个文件之前不需要/var/lib/asterisk/sounds/。只需检查您的/etc/asterisk/asterisk.conf中的声音路径是否为/var/lib/asterisk/sounds(默认设置)。
英文:
Should be something like this:
exten => _123.,7,Set(FILES=customer_Menu1:customer_Menu2:customer_Menu3)
same => n,Playback(${CUT(FILES,:,${RANDOM(1,3)}); CUT will get nth argument delimited by :
same => n,Hangup(34)
Or like miken32 show you if your files are always same name.
Also nice idea is move configure variables like FILES in [general] section or special file included in code.
You DO NOT need /var/lib/asterisk/sounds/ before every file. Just check that in your /etc/asterisk/asterisk.conf sound path is /var/lib/asterisk/sounds(default).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论