jetli87
asked on
Asterisk 1.8.6 setting outbound callerid based on caller
Hi Gurus,
I'm an asterisk programming novice and I need help with finding the correct syntax to match and set an outgoing call from a specific user from a specific SIP Trunk and set as a specific caller id, i.e.:
User A from SIP Trunk A @ exten 202 ==> dialing out ==> set callerid = 3101234567
User B from SIP Trunk B @ exten 202 ==> dialing out ==> set callerid = 3101235555
The problem is that the calls are originating from another PBX, i.e. MS Lync, via a SIP Trunk.
So my thinking is, I need to find out the outgoing SIP info of the caller, if it matches, set the caller id via:
Set(CALLERID(num)=13101234 567)
So I'm not sure if i need to use a marco or gotoif or what...Please help.
I'm an asterisk programming novice and I need help with finding the correct syntax to match and set an outgoing call from a specific user from a specific SIP Trunk and set as a specific caller id, i.e.:
User A from SIP Trunk A @ exten 202 ==> dialing out ==> set callerid = 3101234567
User B from SIP Trunk B @ exten 202 ==> dialing out ==> set callerid = 3101235555
The problem is that the calls are originating from another PBX, i.e. MS Lync, via a SIP Trunk.
So my thinking is, I need to find out the outgoing SIP info of the caller, if it matches, set the caller id via:
Set(CALLERID(num)=13101234
So I'm not sure if i need to use a marco or gotoif or what...Please help.
ASKER
COOL!!! i was hoping it'd be mr. grblades.
thanks for the reply.
I tried the above sample per below, "224" is my extension that's set on the Microsoft Lync Server, "lync-dial" is the context for the sip trunk "Lync_Trunk"
exten => _+1NXXNXXXXXX,1,ExecIf($[" ${CALLERID (num)}" = "224"]?Set(CALLERID(num)=1 7145551234 ))
exten => _+1NXXNXXXXXX,n,Goto(commo n,${EXTEN} ,1)
and i get the below when trying to dial out from CLI output...It seems that it's pulling callerid based on outbound number I'm dialing...Any other suggestions? is it possible to identify the sip user making the outbound call and matched based on that?
thanks for the reply.
I tried the above sample per below, "224" is my extension that's set on the Microsoft Lync Server, "lync-dial" is the context for the sip trunk "Lync_Trunk"
exten => _+1NXXNXXXXXX,1,ExecIf($["
exten => _+1NXXNXXXXXX,n,Goto(commo
and i get the below when trying to dial out from CLI output...It seems that it's pulling callerid based on outbound number I'm dialing...Any other suggestions? is it possible to identify the sip user making the outbound call and matched based on that?
-- Executing [+17142271234@lync-dial:1] ExecIf("SIP/Lync_Trunk-00000811", "0?Set(CALLERID(num)=17145551234)") in new stack
-- Executing [+17142271234@lync-dial:2] Goto("SIP/Lync_Trunk-00000811", "common,+17142271234,1") in new stack
-- Goto (common,+17142272327,1)
ASKER
I should note that asterisk is sending the outbound call to a PRI line, if that matters.
All those +1xxxx number you can see in the output will be the number you dialled. The ExecIf CLI output only shows the result of the comparison and not what it actually compared (the 0 in the 0?Set part meaning the condition did not match).
Try adding an extra line as shown below so you can see the supplied callerid in the CLI output.
exten => _+1NXXNXXXXXX,1,NoOp(Calle rid number of incoming call from trunk is ${CALLERID(num)})
exten => _+1NXXNXXXXXX,n,ExecIf($[" ${CALLERID (num)}" = "224"]?Set(CALLERID(num)=1 7145551234 ))
exten => _+1NXXNXXXXXX,n,Goto(commo n,${EXTEN} ,1)
Try adding an extra line as shown below so you can see the supplied callerid in the CLI output.
exten => _+1NXXNXXXXXX,1,NoOp(Calle
exten => _+1NXXNXXXXXX,n,ExecIf($["
exten => _+1NXXNXXXXXX,n,Goto(commo
ASKER
ok so i think the issue was that my callerid has a "+" in front of it...So i revised as below, but outbound calls aren't passing to context common properly:
here's my code:
exten => _+1NXXNXXXXXX,1,NoOp(Calle rid number of incoming call from trunk is ${CALLERID(num)})
exten => _+1NXXNXXXXXX,1,ExecIf($[" ${CALLERID (num)}" = "+224"]?Set(CALLERID(num)= 1714555123 4))
exten => _+1NXXNXXXXXX,n,Goto(commo n,${EXTEN} ,1)
[common]
exten => s,n,Dial(${TRUNK}/${EXTEN: 1})
exten => s,n,Congestion
CLI output below:
here's my code:
exten => _+1NXXNXXXXXX,1,NoOp(Calle
exten => _+1NXXNXXXXXX,1,ExecIf($["
exten => _+1NXXNXXXXXX,n,Goto(commo
[common]
exten => s,n,Dial(${TRUNK}/${EXTEN:
exten => s,n,Congestion
CLI output below:
-- Executing [+17142272327@lync-dial:1] NoOp("SIP/Lync_Trunk-00000839", "Callerid number of incoming call from trunk is +224") in new stack
-- Executing [+17142272327@lync-dial:2] Goto("SIP/Lync_Trunk-00000839", "common,+17142272327,1") in new stack
-- Goto (common,+17142272327,1)
[Nov 10 10:56:38] WARNING[21922]: pbx.c:4972 __ast_pbx_run: Channel 'SIP/Lync_Trunk-00000839' sent into invalid extension '+17142272327' in context 'common', but no invalid handler
2nd line in the dialplan is wrong. The 1 should be changed to an 'n' as you have tried making two entries with priority 1 so the second gets lost.
The other problem is that in the common extension you are only matching the 's' extension but you are going to an extension which matches the number to be dialled. So try the following :-
exten => _+1NXXNXXXXXX,1,NoOp(Calle rid number of incoming call from trunk is ${CALLERID(num)})
exten => _+1NXXNXXXXXX,n,ExecIf($[" ${CALLERID (num)}" = "+224"]?Set(CALLERID(num)= 1714555123 4))
exten => _+1NXXNXXXXXX,n,Goto(commo n,${EXTEN} ,1)
[common]
exten => _+1NXXNXXXXXX,n,Dial(${TRU NK}/${EXTE N:1})
exten => _+1NXXNXXXXXX,n,Congestion
The other problem is that in the common extension you are only matching the 's' extension but you are going to an extension which matches the number to be dialled. So try the following :-
exten => _+1NXXNXXXXXX,1,NoOp(Calle
exten => _+1NXXNXXXXXX,n,ExecIf($["
exten => _+1NXXNXXXXXX,n,Goto(commo
[common]
exten => _+1NXXNXXXXXX,n,Dial(${TRU
exten => _+1NXXNXXXXXX,n,Congestion
ASKER
oppp, wasn't verifying the syntax properly...My apologies.
i tried your code and got the following:
i tried your code and got the following:
-- Executing [+17142272327@lync-dial:1] NoOp("SIP/Lync_Trunk-0000084d", "Callerid number of incoming call from trunk is +224") in new stack
-- Executing [+17142272327@lync-dial:2] ExecIf("SIP/Lync_Trunk-0000084d", "1?Set(CALLERID(num)=17145551234)") in new stack
-- Executing [+17142272327@lync-dial:3] Goto("SIP/Lync_Trunk-0000084d", "common,+17142272327,1") in new stack
-- Goto (common,+17142272327,1)
[Nov 10 11:18:25] WARNING[22014]: pbx.c:4972 __ast_pbx_run: Channel 'SIP/Lync_Trunk-0000084d' sent into invalid extension '+17142272327' in context 'common', but no invalid handler
ASKER
this is how my context "lync-dial"
[lync-dial]
exten => _+1NXXNXXXXXX,1,Set(CALLERID(num)=3102472235)
exten => _+1NXXNXXXXXX,n,Dial(${TRUNK}/${EXTEN:1})
exten => _+1NXXNXXXXXX,n,Congestion
[common]
exten => _+1NXXNXXXXXX,n,Dial(${TRUNK}/${EXTEN:1})
exten => _+1NXXNXXXXXX,n,Congestion
The first entry in a context should specify priority 1 and then the rest can be n (which is really just an abbreviation of writing the last priority+1)
[common]
exten => _+1NXXNXXXXXX,n,Dial(${TRU NK}/${EXTE N:1})
[common]
exten => _+1NXXNXXXXXX,n,Dial(${TRU
ASKER
god!!! so stupid...I just copied and pasted your syntax without reviewing.
It works like a charm!
What should i use if i want to set non-matched outbound callers to a default callerid?
is the below correct?
It works like a charm!
What should i use if i want to set non-matched outbound callers to a default callerid?
is the below correct?
exten => _+1NXXNXXXXXX,1,NoOp(Callerid number of incoming call from trunk is ${CALLERID(num)})
exten => _+1NXXNXXXXXX,n,ExecIf($["${CALLERID(num)}" = "+224"]?Set(CALLERID(num)=17145551234))
exten => _+1NXXNXXXXXX,n,Set(CALLERID(num)=17148889999)
exten => _+1NXXNXXXXXX,n,Goto(common,${EXTEN},1)
ASKER
actually, that wouldn't work...It just overriding the syntax from above...Nevermind my stupidity.
You are not far off. You just need to set the callerid before the execif comparison but first need to make a copy of the original callerid value and use that in the comparison.
exten => _+1NXXNXXXXXX,1,NoOp(Callerid number of incoming call from trunk is ${CALLERID(num)})
exten => _+1NXXNXXXXXX,n,Set(ORIGCID=${CALLERID(num)})
exten => _+1NXXNXXXXXX,n,Set(CALLERID(num)=17148889999)
exten => _+1NXXNXXXXXX,n,ExecIf($["${ORIGCID}" = "+224"]?Set(CALLERID(num)=17145551234))
exten => _+1NXXNXXXXXX,n,Goto(common,${EXTEN},1)
ASKER
Can you post a sample? I assume you just copy the original value of the callerid and then match from a list and if it doesn't match, set to a default callerid?
I understand the logic, but it's more advanced then my novice asterisk coding can handle.
I understand the logic, but it's more advanced then my novice asterisk coding can handle.
I did it for you in the code snippet in my previous post.
ASKER
Hmmmm, sorry checking from my phone and didn't see the code...will check when I get to my pc shortly.
ASKER
Beatiful!
my last question in regards to the your syntax, if i wanted to set callerid name,i.e. (CALLERID(Name)), how do i append that code for line 3 and 4?
i.e. if it doesn't match, name = Company and number = 17148889999, but if it does matcn, then name = JoeSmith and number= 17145551234
my last question in regards to the your syntax, if i wanted to set callerid name,i.e. (CALLERID(Name)), how do i append that code for line 3 and 4?
i.e. if it doesn't match, name = Company and number = 17148889999, but if it does matcn, then name = JoeSmith and number= 17145551234
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Grblades! As always, you're the man when it comes to asterisk!
ASKER
Hi Grblades,
i got a pretty simple one for you...If/when you can...Thanks:
https://www.experts-exchange.com/questions/27445573/Asterisk-1-8-6-Block-outbound-callerID-for-PRI.html
i got a pretty simple one for you...If/when you can...Thanks:
https://www.experts-exchange.com/questions/27445573/Asterisk-1-8-6-Block-outbound-callerID-for-PRI.html
ASKER
Hi Grblades,
I got another simple one:
https://www.experts-exchange.com/questions/27451983/Asterisk-Dial-Plan-Syntax-Removing-and-digits.html
I got another simple one:
https://www.experts-exchange.com/questions/27451983/Asterisk-Dial-Plan-Syntax-Removing-and-digits.html
So in sip.conf where you have the configuration for trunk a you would have a line such as "CONTEXT=from-trunka". Then in the config for trunk b you would have "CONTEXT=from-trunkb".
Then in extensions.conf
[from-trunka]
exten => _X.,1,ExecIf($["${CALLERID
exten => _X.,n,Goto(common,${EXTEN}
[from-trunkb]
exten => _X.,1,ExecIf($["${CALLERID
exten => _X.,n,Goto(common,${EXTEN}
[common]
exten => _X.,1,Dial(DAHDI/g0/${EXTE