星号,Goto+挂断

huangapple go评论46阅读模式
英文:

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&#39;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 of exten =&gt; ... for the extension when you're repeating the same thing
  • n 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 =&gt; _123.,1,NoOp(&quot;start of context&quot;)
 ; ...
 same =&gt; n,Goto(menu${RAND(1,5)}) 
 same =&gt; n(menu1),Playback(/var/lib/asterisk/sounds/customer_Menu1)
 same =&gt; n,Goto(goodbye)
 same =&gt; n(menu2),Playback(/var/lib/asterisk/sounds/customer_Menu2) 
 same =&gt; n,Goto(goodbye)
 same =&gt; n(menu3),Playback(/var/lib/asterisk/sounds/customer_Menu3)
 same =&gt; n,Goto(goodbye)
 same =&gt; n(menu4),Playback(/var/lib/asterisk/sounds/customer_Menu4) 
 same =&gt; n,Goto(goodbye)
 same =&gt; n(menu5),Playback(/var/lib/asterisk/sounds/customer_Menu5) 
 same =&gt; n(goodbye),Hangup(34)

Or, more simply, use the RAND() function to choose the name of the file to play:

[mycontext]
exten =&gt; _123.,1,NoOp(&quot;start of context&quot;)
 ; ...
 same =&gt; n,Playback(/var/lib/asterisk/sounds/customer_Menu${RAND(1,5)})
 same =&gt; n,Hangup(34)

答案2

得分: 0

以下是翻译好的部分:

应该是这样的:

exten =&gt; _123.,7,Set(FILES=customer_Menu1:customer_Menu2:customer_Menu3)
same =&gt; n,Playback(${CUT(FILES,:,${RANDOM(1,3)}); CUT将获取由冒号分隔的第n个参数
same =&gt; n,Hangup(34)

或者像miken32所展示的,如果您的文件始终具有相同的名称。
还有一个好主意是将配置变量,如FILES,放在[general]部分或代码中包含的特殊文件中。

在每个文件之前不需要/var/lib/asterisk/sounds/。只需检查您的/etc/asterisk/asterisk.conf中的声音路径是否为/var/lib/asterisk/sounds(默认设置)。

英文:

Should be something like this:

exten =&gt; _123.,7,Set(FILES=customer_Menu1:customer_Menu2:customer_Menu3)
same =&gt; n,Playback(${CUT(FILES,:,${RANDOM(1,3)}); CUT will get nth argument delimited by :
same =&gt; 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).

huangapple
  • 本文由 发表于 2023年2月8日 22:39:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75387377.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定