Dial plan not working in asterisk server - asterisk

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

Related

Asterisk 11 match destination extension in macro

Long story short: Fanvil phones don't allow you to change microphone volume (that is too low).
I've created this custom macro, but cannot match the case the phone (exten 131) is receiving a call, it work only when it make a call:
[macro-fanvil]
exten => s,1,NoOp(catch: callerid: ${CALLERID(num)} - exten ${EXTEN}- ${CHANNEL})
;exten => _131,n,Goto(receive)
exten => s,n,GotoIf($[${EXTEN} = 131]?receive)
exten => s,n,GotoIf($[${CALLERID(num)} = 131]?:iscalling)
exten => s,n(iscalling),NoOp(alzachiamante: ${CALLERID(num)} - ${CHANNEL})
exten => s,n,Set(VOLUME(RX)=10)
exten => s,n,MacroExit
exten => s,n(receive),NoOp(alzaricevente: ${CALLERID(num)} - ${CHANNEL})
exten => s,n,Answer()
exten => s,n,Set(VOLUME(TX)=10)
exten => s,n,MacroExit
This is from console:
-- Executing [s#macro-fanvil:1] NoOp("SIP/195-00000096", "macro-fanvil: callerid: 195 - exten s- SIP/195-00000096") in new stack
-- Executing [s#macro-fanvil:2] GotoIf("SIP/195-00000096", "0?receive") in new stack
-- Executing [s#macro-fanvil:3] GotoIf("SIP/195-00000096", "0?:iscalling") in new stack
-- Goto (macro-fanvil,s,4)
Executing [s#macro-fanvil:4] NoOp("SIP/195-00000096", "alzachiamante: 195 - SIP/195-00000096") in new stack
-- Executing [s#macro-fanvil:5] Set("SIP/195-00000096", "VOLUME(RX)=10") in new stack
-- Executing [s#macro-fanvil:6] MacroExit("SIP/195-00000096", "") in new stack
It seems that ${EXTEN} is always the one that is calling, how can I catch the event of the 131 is the destination of the call?
As you can see ${EXTEN} inside a Macro is always s.
-- Executing [s#macro-fanvil:1] NoOp("SIP/195-00000096", "macro-fanvil: callerid: 195 - exten s- SIP/195-00000096") in new stack
You have to tell the Macro the ${EXTEN} when you calling it.
This is normally done with...
https://wiki.asterisk.org/wiki/display/AST/Macros
...at...
Calling Macro with arguments
...where the Argument from the calling Channel/Context is outputed in: Verbose()
Long story short: You have to change your Macro to check the Argument
[macro-fanvil]
exten => s,1,NoOp(catch: callerid: ${CALLERID(num)} - exten ${ARG1}- ${CHANNEL})
;exten => _131,n,Goto(receive)
exten => s,n,GotoIf($[${ARG1} = 131]?receive)
exten => s,n,GotoIf($[${CALLERID(num)} = 131]?:iscalling)
exten => s,n(iscalling),NoOp(alzachiamante: ${CALLERID(num)} - ${CHANNEL})
exten => s,n,Set(VOLUME(RX)=10)
exten => s,n,MacroExit
exten => s,n(receive),NoOp(alzaricevente: ${CALLERID(num)} - ${CHANNEL})
exten => s,n,Answer()
exten => s,n,Set(VOLUME(TX)=10)
exten => s,n,MacroExit
...and call it with Argument: Macro(fanvil,s,1,(${EXTEN}))

MYSQL() function not working in asterisk dialplan

exten => 8367,1,MYSQL(connect connid SERVERIP cron 1234 asterisk)
exten => 8367,n,MYSQL(Query resultid ${connid} select\ comments\ from\
vicidial_list\ where\ list_id=\5555\ and\ phone_number=\${EXTEN:2}\
order\ by\ lead_id\ desc\ limit\ 1\)
exten => 8367,n,MYSQL(Fetch vdp_tmp ${resultid} comments)
exten => 8367,n,MYSQL(Clear ${resultid})
exten => 8367,n,MYSQL(Disconnect ${connid}))
exten => 8367,n,NoOp(${comments})
exten => 8367,n,Platback(/tmp/${comments})
exten => 8367,n,Hangup()
## THIS IS NOT WORKING IN ASTERISK 1.8.32 PLEASE SUGEST ME I AM GETTING ERROR AS
##WARNING[25354]: pbx.c:4706 pbx_extension_helper: No application 'MYSQL' for extension (default, 8367, 4)
Use func_odbc or REALTIME
MYSQL function outdated in 1.4. You can compile it upto 14.*, but by default it turned off.
Anyway func_odbc work simpler and not require check for connection.

Asterisk, blacklist a number by country code or area code

I have a problem lately, of getting crank calls at all hours of the day and night from overseas countries. I am trying to blacklist entire countries, by country code. After googling around I have come up with the following solution, but don't think it is working... as I have tried substituting my own area code and that doesn't work.
Does the coding look correct?
Also, I don't fully understand the [+]?1? part, and would appreciate a breakdown.
FYI, I do have a working blacklist by number set-up, so I know the [blacklisted] context part works.
extentions.conf:
;; same => n,Set(regx=^[+]?1?(215|609)[0-9]{7}$) ;; my test
same => n,Set(regx=^[+]?1?(252|96|27)[0-9]{9}$)
same => n,GotoIf($[${REGEX(“${regx}” ${CALLERID(num)})} = 1]?blacklisted,s,1)
[blacklisted]
exten => s,1,Answer
exten => s,n,Hangup
Examples of numbers I am trying to block:
+252616251444
+252616531860
+27612238445
+96893327281
The test number I am trying to block is 1-609-123-4567.
Here is my extension.conf:
[from-Provider]
exten => _X.,1,Set(CALLERID(num)=${CALLERID(num):1})
exten => 17025551234,1,Zapateller(nocallerid)
exten => _XX./_+252X.,n,Goto(blacklisted,s,1)
exten => _XX./_+1609X.,n,Goto(blacklisted,s,1)
same => n,GotoIf(${BLACKLIST()}?blacklisted,s,1)
same => n,Dial(SIP/home&IAX2/droid&SIP/office)
same => n,Hangup()
[blacklisted]
exten => s,1,Answer
exten => s,n,Hangup
This is the result of a call that should go through. It gets blocked and spits out this output until the caller hangs up.
CLI output:
== Using SIP RTP CoS mark 5
-- Executing [17025551234#from-Provider:1] Zapateller("SIP/Provider_did10-00000080", "nocallerid") in new stack
-- Auto fallthrough, channel 'SIP/Provider_did10-00000080' status is 'UNKNOWN'
== Using SIP RTP CoS mark 5
-- Executing [17025551234#from-Provider:1] Zapateller("SIP/Provider_did9-00000081", "nocallerid") in new stack
-- Auto fallthrough, channel 'SIP/Provider_did9-00000081' status is 'UNKNOWN'
...
-- Executing [17025551234#from-Provider:1] Zapateller("SIP/Provider_did9-00000088", "nocallerid") in new stack
== Spawn extension (from-Provider, 17025551234, 1) exited non-zero on 'SIP/Provider_did9-00000088'
EDIT (with noop added for callerid)
I replaced the dialplan with yours verbatim. The problem is no calls get through.
I think I see my problem. I need to include exten => 17025551234,1,Zapateller(nocallerid) because that is my DID. I don't know where to place that.
Here is the CLI output. It is the same whether it's a call that should go through or should be blocked...
== Using SIP RTP CoS mark 5
-- Executing [17025551234#from-Provider:1] Set("SIP/Provider_did10-000000ec", "CALLERID(num)=16175551234") in new stack
-- Auto fallthrough, channel 'SIP/Provider_did10-000000ec' status is 'UNKNOWN'
== Using SIP RTP CoS mark 5
-- Executing [17025551234#from-Provider:1] Set("SIP/Provider_did9-000000ed", "CALLERID(num)=16175551234") in new stack
-- Auto fallthrough, channel 'SIP/Provider_did9-000000ed' status is 'UNKNOWN'
== Using SIP RTP CoS mark 5
-- Executing [17025551234#from-Provider:1] Set("SIP/Provider_did9-000000ee", "CALLERID(num)=16175551234") in new stack
-- Auto fallthrough, channel 'SIP/Provider_did9-000000ee' status is 'UNKNOWN'
EDIT (extensions.conf):
[globals]
[default]
exten => 1001,1,Progress()
exten => 1001,n,Answer()
exten => 1001,n,Playback(hello-world)
exten => 1001,n,Hangup()
[internal]
exten => 100,1,Dial(SIP/home)
same => n,Hangup()
exten => home,1,Dial(SIP/home)
same => n,Hangup()
exten => 103,1,Dial(SIP/office)
same => n,Hangup()
include => default
include => iax2
[iax2]
exten => 10,1,Dial(SIP/home)
same => n,Hangup()
exten => 11,1,Dial(IAX2/droid)
same => n,Hangup()
exten => 12,1,Dial(SIP/home&IAX2/droid)
same => n,Hangup()
exten => 20,1,Dial(IAX2/clive)
same => n,Hangup()
include => default
[from-Provider]
exten => _X.,1,Set(CALLERID(num)=${CALLERID(num):1})
exten => 17025551234,1,Zapateller(nocallerid)
same => n,Noop(CALLERID=${CALLERID(all)})
same => n,GotoIf(${BLACKLIST()}?blacklisted,s,1)
same => n,Dial(SIP/home&IAX2/droid&SIP/office)
same => n,Hangup()
exten => 442035551234,1,Zapateller(nocallerid)
same => n,Set(regx=^[+]?1?(252|96|27)[0-9]{9}$)
same => n,GotoIf($[${REGEX("${regx}" ${CALLERID(num)})} = 1]?blacklisted,s,1)
same => n,GotoIf(${BLACKLIST()}?blacklisted,s,1)
same => n,Dial(SIP/home&IAX2/droid&SIP/office)
same => n,Hangup()
[blacklisted]
exten => s,1,Answer
exten => s,n,Hangup
I have two DIDs. One in the USA 17025551234, and one in the UK 442035551234. I have no trunk lines.
EDIT (CLI output using ESYSCODER's context)
I have replaced the entire [from-Provider] context with your context exactly as you posted it. Then I dialed my DID number 17025551234from a number that should not be rejected 17025550000 (obviously I am changing the numbers for privacy concerns).
The CLI output is as follows:
com1*CLI>
-- Executing [17025551234#from-Provider:1] Set("SIP/Provider_did9-00000012", "CALLERID(num)=17025550000") in new stack
-- Auto fallthrough, channel 'SIP/Provider_did9-00000012' status is 'UNKNOWN'
== Using SIP RTP CoS mark 5
-- Executing [17025551234#from-Provider:1] Set("SIP/Provider_did10-00000013", "CALLERID(num)=17025550000") in new stack
-- Auto fallthrough, channel 'SIP/Provider_did10-00000013' status is 'UNKNOWN'
== Using SIP RTP CoS mark 5
-- Executing [17025551234#from-Provider:1] Set("SIP/Provider_did10-00000014", "CALLERID(num)=17025550000") in new stack
-- Auto fallthrough, channel 'SIP/Provider_did10-00000014' status is 'UNKNOWN'
== Using SIP RTP CoS mark 5
-- Executing [17025551234#from-Provider:1] Set("SIP/Provider_did9-00000015", "CALLERID(num)=17025550000") in new stack
-- Auto fallthrough, channel 'SIP/Provider_did9-00000015' status is 'UNKNOWN'
== Using SIP RTP CoS mark 5
-- Executing [17025551234#from-Provider:1] Set("SIP/Provider_did9-00000016", "CALLERID(num)=17025550000") in new stack
-- Auto fallthrough, channel 'SIP/Provider_did9-00000016' status is 'UNKNOWN'
== Using SIP RTP CoS mark 5
-- Executing [17025551234#from-Provider:1] Set("SIP/Provider_did10-00000017", "CALLERID(num)=17025550000") in new stack
-- Auto fallthrough, channel 'SIP/Provider_did10-00000017' status is 'UNKNOWN'
com1*CLI>
What confuses me is that I must have the exten => 17025551234,1,Zapateller(nocallerid) line in order for the the DID 17025551234 to pick up. Where should that fit into the dialplan/context that you are suggestiong. Or am I missing something. Is there another way to answer when my DID number is ringing me? Sorry if I'm being thick here... I may be missing one simple point.
EDIT (priority change)
With the following context the caller gets a message, "The number you have dialed is not in service"...
[from-didforsale]
exten => _XX./_1609123456X,1,Goto(blacklisted,s,1)
exten => _XX.,n,GotoIf(${BLACKLIST()}?blacklisted,s,1)
exten => _XX.,n,Noop(CALLERID=${CALLERID(all)})
exten => _XX.,n,Dial(SIP/home&IAX2/droid&SIP/office)
exten => _XX.,n,Hangup()
and this is the CLI output:
== Using SIP RTP CoS mark 5
[Nov 24 09:08:13] NOTICE[2957]: chan_sip.c:23613 handle_request_invite: Call from 'didforsale_did9' (209.216.15.70:5060) to extension '13022323111' rejected because extension not found in context 'from-didforsale'.
I get the exact same thing with the line commented out ;;exten => _XX./_1609123456X,1,Goto(blacklisted,s,1)
Isn't the dialplan sequence:
1. get caller ID
2. pick up incoming DID extension (I may have the wrong terminology)
3. check caller ID for blacklist
?
You can match caller id doing something like this:
exten => s/_+252X.,n,Goto(blacklisted,s,1)
exten => s/_+1609X.,n,Goto(blacklisted,s,1)
or
exten => _XX./_+252X.,n,Goto(blacklisted,s,1)
exten => _XX./_+1609X.,n,Goto(blacklisted,s,1)
More on pattern matching:
https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching
EDIT
Example to block 1-609-123-456X, where X is any digit:
[from-Provider]
exten => _XX.,1,Set(CALLERID(num)=${CALLERID(num):1})
exten => _XX./_1609123456X,n,Goto(blacklisted,s,1)
exten => _XX.,n,GotoIf(${BLACKLIST()}?blacklisted,s,1)
exten => _XX.,n,Noop(CALLERID=${CALLERID(all)})
exten => _XX.,n,Dial(SIP/home&IAX2/droid&SIP/office)
exten => _XX.,n,Hangup()
[blacklisted]
exten => s,1,Answer
exten => s,n,Hangup
You can add also other patterns like:
_252X. (for numbers starting with 252
_96X. (for numbers starting with 96
If this will not work please add whole CLI log. Noop will show us what callerid is looking like in your PBX.
EDIT 2:
Both lines should have priority 1.
[from-didforsale]
exten => _XX./_1609123456X,1,Goto(blacklisted,s,1)
exten => _XX.,1,GotoIf(${BLACKLIST()}?blacklisted,s,1)
exten => _XX.,n,Noop(CALLERID=${CALLERID(all)})
exten => _XX.,n,Dial(SIP/home&IAX2/droid&SIP/office)
exten => _XX.,n,Hangup()

Initiate call from extension

It is possible to initiate call from extension? My extension is look like the following:
[read_text]
exten => s,1,Answer( )
exten => s,n,Dial(SIP/1,G(99))
exten => s,n,Dial(SIP/2,G(99))
exten => s,n,Goto(1)
exten => s,100,System(echo '${text}' | /usr/bin/espeak --stdout |sox -t wav - -r 8000 /tmp/voice.wav)
exten => s,n,Playback(/tmp/voice)
exten => s,n,System(rm /tmp/voice.wav)
exten => s,n,Hangup( )
So if SIP/1 or SIP/2 answers, It plays text and hangup, if nobody answer it continues to Dial
I tried to make call file, but it requires some channel to be setup, I tried to use Local, but unsuccess.
I also found that there are queues, but can't find a way to initiate call to queue from call file. I'm very new to asterisk.
What your trying to do can get pretty messy from the dialplan. Try something along these lines:
[call_read_text]
exten => s,1,Dial(SIP/1,gG(read_text,s,1))
exten => s,n,Dial(SIP/2,gG(read_text,s,1))
exten => s,n,Goto(1)
[read_text]
exten => s,1,System(echo '${text}' | /usr/bin/espeak --stdout |sox -t wav - -r 8000 /tmp/voice.wav)
exten => s,n,Playback(/tmp/voice)
exten => s,n,System(rm /tmp/voice.wav)
exten => s,n,Hangup()
Dont answer the call before you start!
g will continue in the dialplan if the call isn't answered, and call the next extension
G() will jump to read_text,s,1 if the call IS answered, and end the hunt
You can jumpstart all this with a call file, by connecting the first context with the second (will happen on answer).
Something along these lines:
Channel: Local/s#call_read_text
Context: read_text
Extension: s
Priority: 1
More on call files here: http://www.voip-info.org/wiki/view/Asterisk+auto-dial+out. Use Set: foo=bar in the call file to set ${text}

Replace characters in Asterisk Dialplan

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.

Resources