text
stringlengths
0
152
exten => 102,1,Dial(${UserB_DeskPhone},10)
same => n,Playback(vm-nobodyavail)
same => n,Hangup()
exten => 103,1,Dial(${UserB_SoftPhone})
exten => 110,1,Dial(${UserA_DeskPhone}&${UserA_SoftPhone}&${UserB_SoftPhone})
exten => 200,1,Answer()
Let’s update the test menu as well:
[TestMenu]
exten => start,1,Answer()
same => n,Background(enter-ext-of-person)
same => n,WaitExten(5)
exten => 1,1,Dial(${UserA_DeskPhone},10)
same => n,Playback(vm-nobodyavail)
same => n,Hangup()
exten => 2,1,Dial(${UserA_SoftPhone},10)
same => n,Playback(vm-nobodyavail)
same => n,Hangup()
exten => 3,1,Dial(${UserB_DeskPhone},10)
same => n,Playback(vm-nobodyavail)
same => n,Hangup()
exten => 4,1,Dial(${UserB_SoftPhone},10)
same => n,Playback(vm-nobodyavail)
same => n,Hangup()
exten => i,1,Playback(pbx-invalid)
It rarely makes sense to hardcode data in a dialplan. It’s almost always better to use a
variable.
Make sure you test this out to ensure you don’t have any typos, and also to see what it
looks like when executed on the Asterisk CLI:
Building an Interactive Dialplan
|
99
# asterisk -rvvvvvv
*CLI> dialplan reload
-- Executing [201@sets:1] Goto("PJSIP/0000f30A0A01", "TestMenu,start,1")
-- Goto (TestMenu,start,1)
-- Exec [start@TestMenu:1] Answer("PJSIP/0000f30A0A01", "")
-- Exec [start@TestMenu:2] BackGround("PJSIP/0000f30A0A01", "enter-ext-of-person")
-- <PJSIP/0000f30A0A01> Playing 'enter-ext-of-person.slin' (language 'en')
-- Exec [1@TestMenu:1] Dial("PJSIP/0000f30A0A01", "PJSIP/0000f30A0A01,10")
-- Called PJSIP/0000f30A0A01
-- PJSIP/0000f30A0A01-00000011 is ringing
== Spawn extension (TestMenu, 1, 1) exited non-zero on 'PJSIP/0000f30A0A01'
Variable concatenation
To concatenate variables, simply place them together, like this:
exten => 204,1,Answer()
same => n,Answer()
same => n,Set(ONETWO=12)
same => n,Set(THREEFOUR=34)
same => n,SayDigits(${ONETWO}${THREEFOUR}) ; easy peasy
same => n,Wait(0.2)
same => n,Set(NOTFIVE=${THREEFOUR}${ONETWO}) ; peasy easy
same => n,SayNumber(${NOTFIVE}) ; see what we did here?
same => n,Wait(0.2)
same => n,SayDigits(2${ONETWO}3) ; you can concatenate literals and variables
Inheriting channel variables
Channel variables are always associated with the original channel that set them, and
are no longer available once the channel is transferred.
In order to allow channel variables to follow the channel as it is transferred around
the system, you must employ channel variable inheritance. There are two modifiers
that can allow the channel variable to follow the channel: single underscore and dou‐
ble underscore.
The single underscore (_) causes the channel variable to be inherited by the channel
for a single transfer, after which it is no longer available for additional transfers. If
you use a double underscore (__), the channel variable will be inherited throughout
the life of that channel.
Setting channel variables for inheritance simply requires you to prefix the channel
name with a single or double underscore. The channel variables are then referenced
exactly the same as they would be normally.
Here’s an example of setting a channel variable for single transfer inheritance:
exten => example,1,Set(_MyVariable=thisValue)
Here’s an example of setting a channel variable for infinite transfer inheritance: