I am writing asterisk dial plan for testing purpose. I write this in my extension.conf:-
[demo]
exten => s,1,Answer
exten => s,n,Read(user_number)
exten => s,n,SayDigits(${user_number})
exten => s,n,System(echo 'User entered ${user_number}' >> /tmp/key.txt)
When i call on 8500, call successfully established, But when user press 1 or 2 or 3 key on sjphone then playback is not working. I can't hear any sound.
Here is my complete extension.conf:-
;
; Static extension configuration file, used by
; the pbx_config module. This is where you configure all your
; inbound and outbound calls in Asterisk.
;
; This configuration file is reloaded
; - With the "extensions reload" command in the CLI
; - With the "reload" command (that reloads everything) in the CLI
;
; The "General" category is for certain variables.
;
[general]
;
; If static is set to no, or omitted, then the pbx_config will rewrite
; this file when extensions are modified. Remember that all comments
; made in the file will be lost when that happens.
;
; XXX Not yet implemented XXX
;
static=yes
;
; if static=yes and writeprotect=no, you can save dialplan by
; CLI command 'save dialplan' too
;
writeprotect=yes
;
; If autofallthrough is set, then if an extension runs out of
; things to do, it will terminate the call with BUSY, CONGESTION
; or HANGUP depending on Asterisk's best guess (strongly recommended).
;
; If autofallthrough is not set, then if an extension runs out of
; things to do, asterisk will wait for a new extension to be dialed
; (this is the original behavior of Asterisk 1.0 and earlier).
;
autofallthrough=yes
;
; If clearglobalvars is set, global variables will be cleared
; and reparsed on an extensions reload, or Asterisk reload.
;
; If clearglobalvars is not set, then global variables will persist
; through reloads, and even if deleted from the extensions.conf or
; one of its included files, will remain set to the previous value.
;
clearglobalvars=no
;
; If priorityjumping is set to 'yes', then applications that support
; 'jumping' to a different priority based on the result of their operations
; will do so (this is backwards compatible behavior with pre-1.2 releases
; of Asterisk). Individual applications can also be requested to do this
; by passing a 'j' option in their arguments.
;
priorityjumping=yes
;
; You can include other config files, use the #include command
; (without the ';'). Note that this is different from the "include" command
; that includes contexts within other contexts. The #include command works
; in all asterisk configuration files.
;#include "filename.conf"
; The "Globals" category contains global variables that can be referenced
; in the dialplan with ${VARIABLE} or ${ENV(VARIABLE)} for Environmental
; variables,
; ${${VARIABLE}} or ${text${VARIABLE}} or any hybrid
;
;[globals]
#include "exten_gvars.inc"
;
; Sample entries for extensions.conf
;
;
[dundi-e164-canonical]
;
; List canonical entries here
;
;exten => 12564286000,1,Macro(std-exten,6000,IAX2/foo)
;exten => _125642860XX,1,Dial(IAX2/otherbox/${EXTEN:7})
[dundi-e164-customers]
;
; If you are an ITSP or Reseller, list your customers here.
;
;exten => _12564286000,1,Dial(SIP/customer1)
;exten => _12564286001,1,Dial(IAX2/customer2)
[dundi-e164-via-pstn]
;
; If you are freely delivering calls to the PSTN, list them here
;
;exten => _1256428XXXX,1,Dial(Zap/g2/${EXTEN:7}) ; Expose all of 256-428
;exten => _1256325XXXX,1,Dial(Zap/g2/${EXTEN:7}) ; Ditto for 256-325
[dundi-e164-local]
;
; Context to put your dundi IAX2 or SIP user in for
; full access
;
include => dundi-e164-canonical
include => dundi-e164-customers
include => dundi-e164-via-pstn
[dundi-e164-switch]
;
; Just a wrapper for the switch
;
switch => DUNDi/e164
[dundi-e164-lookup]
;
; Locally to lookup, try looking for a local E.164 solution
; then try DUNDi if we don't have one.
;
include => dundi-e164-local
include => dundi-e164-switch
;
; DUNDi can also be implemented as a Macro instead of using
; the Local channel driver.
;
[macro-dundi-e164]
;
; ARG1 is the extension to Dial
;
exten => s,1,Goto(${ARG1},1)
include => dundi-e164-lookup
;
; Here are the entries you need to participate in the IAXTEL
; call routing system. Most IAXTEL numbers begin with 1-700, but
; there are exceptions. For more information, and to sign
; up, please go to www.gnophone.com or www.iaxtel.com
;
[iaxtel700]
exten => _91700XXXXXXX,1,Dial(IAX2/${IAXINFO}#iaxtel.com/${EXTEN:1}#iaxtel)
;
; The SWITCH statement permits a server to share the dialplan with
; another server. Use with care: Reciprocal switch statements are not
; allowed (e.g. both A -> B and B -> A), and the switched server needs
; to be on-line or else dialing can be severly delayed.
;
[iaxprovider]
;switch => IAX2/user:[key]#myserver/mycontext
[trunk]
exten => _01,1,Dial(${trunk1})
exten => _01,2,Congestion
exten => _01.,1,Dial(${trunk1}/${EXTEN:2})
exten => _01.,2,Congestion
exten => _02.,1,Dial(${trunk2}/${EXTEN:2})
exten => _02.,2,Congestion
[trunkint]
;
; International long distance through trunk
;
exten => _9011.,1,Macro(dundi-e164,${EXTEN:4})
exten => _9011.,n,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
[trunkld]
;
; Long distance context accessed through trunk
;
exten => _91NXXNXXXXXX,1,Macro(dundi-e164,${EXTEN:1})
exten => _91NXXNXXXXXX,n,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
[trunklocal]
;
; Local seven-digit dialing accessed through trunk interface
;
exten => _9NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
[trunktollfree]
;
; Long distance context accessed through trunk interface
;
exten => _91800NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
exten => _91888NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
exten => _91877NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
exten => _91866NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}})
[international]
;
; Master context for international long distance
;
ignorepat => 9
include => longdistance
include => trunkint
[longdistance]
;
; Master context for long distance
;
ignorepat => 9
include => local
include => trunkld
[local]
;
; Master context for local, toll-free, and iaxtel calls only
;
ignorepat => 9
include => default
include => parkedcalls
include => trunklocal
include => iaxtel700
include => trunktollfree
include => iaxprovider
;
; You can use an alternative switch type as well, to resolve
; extensions that are not known here, for example with remote
; IAX switching you transparently get access to the remote
; Asterisk PBX
;
; switch => IAX2/user:password#bigserver/local
;
; An "lswitch" is like a switch but is literal, in that
; variable substitution is not performed at load time
; but is passed to the switch directly (presumably to
; be substituted in the switch routine itself)
;
; lswitch => Loopback/12${EXTEN}#othercontext
;
; An "eswitch" is like a switch but the evaluation of
; variable substitution is performed at runtime before
; being passed to the switch routine.
;
; eswitch => IAX2/context#${CURSERVER}
[macro-stdexten];
;
; Standard extension macro:
; ${ARG1} - Extension (we could have used ${MACRO_EXTEN} here as well
; ${ARG2} - Device(s) to ring
;
exten => s,1,Dial(${ARG2},20) ; Ring the interface, 20 seconds maximum
exten => s,2,Goto(s-${DIALSTATUS},1) ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)
exten => s-NOANSWER,1,Voicemail(u${ARG1}) ; If unavailable, send to voicemail w/ unavail announce
exten => s-NOANSWER,2,Goto(default,s,1) ; If they press #, return to start
exten => s-BUSY,1,Voicemail(b${ARG1}) ; If busy, send to voicemail w/ busy announce
exten => s-BUSY,2,Goto(default,s,1) ; If they press #, return to start
exten => _s-.,1,Goto(s-NOANSWER,1) ; Treat anything else as no answer
exten => a,1,VoicemailMain(${ARG1}) ; If they press *, send the user into VoicemailMain
[macro-stdPrivacyexten];
;
; Standard extension macro:
; ${ARG1} - Extension (we could have used ${MACRO_EXTEN} here as well
; ${ARG2} - Device(s) to ring
; ${ARG3} - Optional DONTCALL context name to jump to (assumes the s,1 extension-priority)
; ${ARG4} - Optional TORTURE context name to jump to (assumes the s,1 extension-priority)`
;
exten => s,1,Dial(${ARG2},20|p) ; Ring the interface, 20 seconds maximum, call screening option (or use P for databased call screening)
exten => s,2,Goto(s-${DIALSTATUS},1) ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)
exten => s-NOANSWER,1,Voicemail(u${ARG1}) ; If unavailable, send to voicemail w/ unavail announce
exten => s-NOANSWER,2,Goto(default,s,1) ; If they press #, return to start
exten => s-BUSY,1,Voicemail(b${ARG1}) ; If busy, send to voicemail w/ busy announce
exten => s-BUSY,2,Goto(default,s,1) ; If they press #, return to start
exten => s-DONTCALL,1,Goto(${ARG3},s,1) ; Callee chose to send this call to a polite "Don't call again" script.
exten => s-TORTURE,1,Goto(${ARG4},s,1) ; Callee chose to send this call to a telemarketer torture script.
exten => _s-.,1,Goto(s-NOANSWER,1) ; Treat anything else as no answer
exten => a,1,VoicemailMain(${ARG1}) ; If they press *, send the user into VoicemailMain
[internal]
exten => 3000,1,Dial(${ip3000},30,Ttm)
exten => 3000,2,Voicemail(u3000)
exten => 3000,3,Hangup
exten => 3000,102,Voicemail(b3000)
exten => 3000,103,Hangup
exten => 3001,1,Dial(${ip3001},30,Ttm)
exten => 3001,2,Voicemail(u3001)
exten => 3001,3,Hangup
exten => 3001,102,Voicemail(b3001)
exten => 3001,103,Hangup
exten => 3002,1,Dial(${ip3002},30,Ttm)
exten => 3002,2,Voicemail(u3002)
exten => 3002,3,Hangup
exten => 3002,102,Voicemail(b3002)
exten => 3002,103,Hangup
exten => 3003,1,Dial(${ip3003},30,Ttm)
exten => 3003,2,Voicemail(u3003)
exten => 3003,3,Hangup
exten => 3003,102,Voicemail(b3003)
exten => 3003,103,Hangup
[demo]
;
; We start with what to do when a call first comes in.
;
exten => s,1,Answer
exten => s,n,Read(user_number)
exten => s,n,SayDigits(${user_number})
exten => s,n,System(echo 'User entered ${user_number}' >> /tmp/key.txt)
exten => 1,1,System(echo 'User Number is 1' >> /tmp/a.txt)
;exten => 2,1,BackGround(demo-moreinfo) ; Give some more information.
;exten => 2,n,Goto(s,instruct)
;exten => 3,1,Set(LANGUAGE()=fr) ; Set language to french
;exten => 3,n,Goto(s,restart) ; Start with the congratulations
;
; Create an extension, 5, for dialing the Skype Test Call.
;
;exten => 5,1,Playback(transfer,skip) ; "Please hold while..."
;exten => 5,2,Celliax2Skype(echo123) ; call the Skype Test Call
;exten => 5,3,Goto(s,restart) ; Return to the start over message.
;
; Skype Contacts Directory
;exten => 6,1,Celliax_Skype_Directory(default|default|f)
; Create an extension, 8, for dialing MYCELLNUMBER
; via Celliax (you can't use this if you are calling on the one
; only Celliax channel. But you can call from IAX, SIP, PSTN, etc...)
;
;exten => 8,1,Playback(transfer,skip) ; "Please hold while..."
;exten => 8,2,Dial(CELLIAX/GSM0/${MYCELLNUMBER}) ; dial MYCELLNUMBER from the Celliax channel named by the input audio device it use
exten => 1000,1,Goto(default,s,1)
; We also create an example user, 1234, who is on the console and has
; voicemail, etc.
;
exten => 1234,1,Playback(transfer,skip) ; "Please hold while..."
; (but skip if channel is not up)
exten => 1234,n,Macro(stdexten,1234,${ip3000})
exten => 1235,1,Voicemail(u3000}) ; Right to voicemail
exten => 1236,1,Dial(${ip3000}) ; Ring forever
exten => 1236,n,Voicemail(u3000}) ; Unless busy
;
; # for when they're done with the demo
;
exten => #,1,Playback(demo-thanks) ; "Thanks for trying the demo"
exten => #,n,Hangup ; Hang them up.
;
; A timeout and "invalid extension rule"
;
exten => t,1,Goto(#,1) ; If they take too long, give up
exten => i,1,Playback(invalid) ; "That's not valid, try again"
;
; Create an extension, 500, for dialing the
; Asterisk demo.
;
exten => 500,1,Playback(demo-abouttotry); Let them know what's going on
exten => 500,n,Dial(IAX2/guest#pbx.digium.com/s#default) ; Call the Asterisk demo
exten => 500,n,Playback(demo-nogo) ; Couldn't connect to the demo site
exten => 500,n,Goto(s,6) ; Return to the start over message.
;
; Create an extension, 501, for dialing the
; AsteriskWin32 demo.
;
exten => 501,1,Playback(pls-wait-connect-call); Let them know what's going on
exten => 501,n,Dial(IAX2/guest#demo.asteriskwin32.com/s#default) ; Call the AsteriskWin32 demo
exten => 501,n,Playback(cannot-complete-network-error) ; Couldn't connect to the demo site
exten => 501,n,Playback(pls-try-call-later)
exten => 501,n,Goto(s,6) ; Return to the start over message.
;
; Create an extension, 600, for evaluating echo latency.
;
exten => 600,1,Playback(demo-echotest) ; Let them know what's going on
exten => 600,n,Echo ; Do the echo test
exten => 600,n,Playback(demo-echodone) ; Let them know it's over
exten => 600,n,Goto(s,6) ; Start over
;
; Give voicemail at extension 8500
;
exten => 8500,1,Answer
exten => 8500,2,Read(digito||1)
exten => 8500,3,System(echo 'User Number is ${digito}' >> /tmp/a.txt)
exten => 123,1,Answer
exten => 123,n,Background(demo-moreinfo)
exten => 123,n,WaitExten()
exten => 1,1,Playback(digits/1)
exten => 2,1,Playback(digits/2)
exten => 3,1,Playback(digits/3)
exten => 4,1,Playback(digits/4)
[default]
;
; By default we include the demo. In a production system, you
; probably don't want to have the demo there.
;
include => demo
include => parkedcalls
include => trunk
include => internal
exten => 99990,1,Answer
exten => 99990,2,AGI(agi-test.agi)
exten => 99990,3,Hangup
exten => 99991,1,Answer
exten => 99991,2,EAGI(eagi-test)
exten => 99991,3,Hangup
exten => 99992,1,Answer
exten => 99992,2,Wait(1)
exten => 99992,3,SayUnixTime()
exten => 99992,4,Hangup
exten => 99999,1,Answer
exten => 99999,2,Wait(1)
exten => 99999,3,MusicOnHold
[skype]
exten => s,1,Answer;
exten => s,2,Skype2Celliax(${MYCELLNUMBER}); Connect the Skype incoming call with the cellphone at MYCELLNUMBER
exten => s,3,Hangup ; Hang them up.
exten => 100,1,dial(SIP/mysjphone)
exten => mysjphone,1,goto(100,1) ; To be able to dial with text, "mysjphone"
exten => 123,1,Answer
exten => 123,n,Background(main-menu)
exten => 123,n,WaitExten()
exten => 1,1,Playback(digits/1)
exten => 2,1,Playback(digits/2)
exten => 3,1,Playback(digits/3)
exten => 4,1,Playback(digits/4)
It seems you didn't understand how to write dialplan properly.
The proper syntax for an extension is:
exten => number,priority,application([parameter[,parameter2...]])
so if you want to do something when user press 1,
write it like
exten => 1,1,playback(digits/1)
and for better understanding read the book asterisk: future of telephony
I want to change a couple off characters * # for A and P to have the monitor filename with characters more friendly. The only solution I could find was to do it my self within the dialplan but it generates a lot of verbosity output and is not as efficient(fast) as I would like to. I'll post it here just in case someone wants to use it. But I'm looking for an asterisk function that I can compile something that I can call withing the dialplan like ${REPLACE(${EXTEN},*,a)} and have the exten **123**456*** converted to AA123AA456AAA.
;
; MACRO REPLACE
;
[macro-replace]
;
; ${ARG1} - String source
; ${ARG2} - Chars to replace
; ${ARG3} - Chars to replace with
;
exten => s,1,NoOp(Replacing ${ARG2} for ${ARG3} in ${ARG1})
exten => s,n,Set(str=${ARG1})
exten => s,n,Set(find=${ARG2})
exten => s,n,Set(replace=${ARG3})
exten => s,n,Set(i=0)
exten => s,n,Set(length=${LEN(${str})})
exten => s,n,While($[${i} < ${length}])
exten => s,n,GotoIf($["${str:${i}:1}" != "${find}"]?continue)
exten => s,n,Set(pre=)
exten => s,n,GotoIf($["${i}" = "0"]?post)
exten => s,n,Set(pre=${str:0:${i}})
exten => s,n(post),Set(post=)
exten => s,n,GotoIf($["${i}" = $[${length} - 1]]?write)
exten => s,n,Set(post=${str:$[${i} + 1]})
exten => s,n(write),Set(str=${pre}${replace}${post})
exten => s,n(continue),Set(i=$[${i} + 1])
exten => s,n,EndWhile
exten => s,n,Set(REPLACERESULT=${str})
The REPLACE() function now does this easily:
exten => 100,1,Set(find=**123**456***)
same => n,NoOp(find=${find})
same => n,Set(replace=${REPLACE(find,*,A)})
same => n,NoOp(find=${find}, replace=${replace})
same => n,hangup()
Output:
*CLI> channel originate local/100#default extension null#default
-- Executing [100#default:1] Set("Local/100#default-c758;2", "find=**123**456***") in new stack
-- Executing [100#default:2] NoOp("Local/100#default-c758;2", "find=**123**456***") in new stack
-- Executing [100#default:3] Set("Local/100#default-c758;2", "replace=AA123AA456AAA") in new stack
-- Executing [100#default:4] NoOp("Local/100#default-c758;2", "find=**123**456***, replace=AA123AA456AAA") in new stack
-- Executing [100#default:5] Hangup("Local/100#default-c758;2", "") in new stack
== Spawn extension (default, 100, 5) exited non-zero on 'Local/100#default-c758;2'
That's really the best way to do it (without using regex). If you want to use regex (regular expressions), Asterisk 1.1+ has full support for it. This will allow you to do your entire macro in a single line. The documentation for using regex in dialplan is here: voip-info.
Hopefully this helps! There are plenty of examples on that voip-info page that should be able to help you along!
Another alternative to what you've done is to use an AGI script. Just write your code in bash/python/etc and use it as AGI(replace,${arg1},${arg2},${arg3}). Might not be as fast as an internal function but it's more compact and potentially faster than your solution.