Related
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}))
Please can you tell me where I am wrong, I am new on Asterisk.
I am trying to detect voicemail on outgoing call (remote provider)
exten => _011225XXXXXXXX,1,Dial(SIP/${EXTEN}#dinstar)
exten => _011225XXXXXXXX,n,AMD()
exten => _011225XXXXXXXX,n,GotoIf($["${AMDSTATUS}" = "HUMAN"]? human:machine)
exten => _011225XXXXXXXX,n(machine),WaitForSilence(2000)
exten => _011225XXXXXXXX,n,Playback(asterisk-friend)
exten => _011225XXXXXXXX,n,Hangup()
exten => _011225XXXXXXXX,n(human),Verbose(3, We've got a human on the line!)
exten => _011225XXXXXXXX,n,Playback(transfer)
exten => _011225XXXXXXXX,n,Dial(SIP/${EXTEN}#dinstar)
exten => _011225XXXXXXXX,n,Playback(im-sorry)
exten => _011225XXXXXXXX,n,Hangup()
Cli print
CLI> == Using SIP RTP CoS mark 5
-- Executing [01122548484444#LocalSets:1] Dial("SIP/mor-00000002", "SIP/01122548484444#dinstar") in new stack
== Using SIP RTP CoS mark 5
-- Called SIP/01122548484444#dinstar
-- SIP/dinstar-00000003 is making progress passing it to SIP/mor-00000002
-- SIP/dinstar-00000003 answered SIP/mor-00000002
-- Remotely bridging SIP/mor-00000002 and SIP/dinstar-00000003
== Spawn extension (LocalSets, 01122548484444, 1) exited non-zero on 'SIP/mor-00000002'
Asterisk AMD in this example will start like you asked - after dial command compleated.
If you want use AMD for provisioning dial answer you should use it in on-answer macro(M param in dial command).
If you want use AMD to detect what happens and route calls, you should implement AMD on other end of call/add that to your dialling core. For examples see vicidial.org or other dialler.
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()
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}
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.