Need extensions tweak help

Hi all,

I’ve set up an asterisk server (running 11.12.x version) to connect to google voice via xmpp and be able to make/receive calls via motif. Everything works well for a single user.

In sip.conf, I have n peer defined as [101].
In motif.conf, I have [google] channel defined which places all calls under the [incoming-motif] context.
In xmpp.conf, I have [google] connection defined which establishes the connection to talk.google.com
in extensions.conf, I have [incoming-motif] which basically does some magic with the callerid and rings a defined peer extension [101].
Outbound calls also work well.

How do I make it so that if I want to add another google voice account (lets call it [gv2]) and a sip peer account association, if dialed from that particular peer (say from [103]), that it uses the 2nd google voice account to connect place the call. Receiving the calls is easier. I’d like to be able to do it so that in the future, if I add other peers and google voice account’s, I’d have to implement minimal changes.

Such as
if dialed from 101 -> Dialplan should look like …Dial(Motif/google/...)
if dialed from 103 -> Dialplan should look like …Dial(Motif/gv2/...)
if dialed from 106 -> Dialplan should look like …Dial(Motif/gv6/...)

Is there a way to set a variable so that instead of having multiple Dial(Motif/<google_connection>/…)
I could simply do something like this:

exten => _+1NXXNXXXXXX,1,Dial(Motif/${WHICH_GV_ACCOUNT}/${EXTEN}@voice.google.com,,r)

Any help will be appreciated.

Thanks.

You can declare the variables in you extensions.conf. And then you could use some kind of Gotoif logic for switch google voice account.

[globals]
gv1=Motif/google
gv2=Motif/google

exten => _1XXXXXXXXXX,1,Dial(${gv1}/${EXTEN}@voice.google.com,r)


[quote=“ambiorixg12”]You can declare the variables in you extensions.conf. And then you could use some kind of Gotoif logic for switch google voice account.

[globals]
gv1=Motif/google
gv2=Motif/google

exten => _1XXXXXXXXXX,1,Dial(${gv1}/${EXTEN}@voice.google.com,r)

------------------------------------------------------------------------------------------[/quote]
Something along these lines is exactly what I’m looking for. However, I wanted to understand the “switch” or “goto” statements which would make it easy for me to replace the Dial(Motif/google..) to Dial(${which_gv}/..)

I’m pasting a copy of my extensions file with the necessary information

[code][default]
exten => s,1,Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})})
exten => s,n,Dial(SIP/101&SIP/102&SIP/103,10)
exten => s,n, Hangup
exten => 101, 1, Dial(SIP/101, 10)
exten => 102, 1, Dial(SIP/102, 10)
exten => 103, 1, Dial(SIP/103, 10)

;SIP/101 and 102 are associated with motif/google and incoming-motif
;SIP/103 is associated with motif/gv2 and incoming-gv
; how do i use a single global variable to switch between them accordingly

[incoming-motif]
exten => s,1,NoOp()
same => n,Set(crazygooglecid=${CALLERID(name)})
same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
same => n,Set(CALLERID(num)=${stripcrazysuffix})
same => n,Set(CALLERID(name)=${stripcrazysuffix})
same => n,Dial(SIP/101&SIP/102,20,D(:1))

[incoming-gv]
exten => s,1,NoOp()
same => n,Set(crazygooglecid=${CALLERID(name)})
same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
same => n,Set(CALLERID(num)=${stripcrazysuffix})
same => n,Set(CALLERID(name)=${stripcrazysuffix})
same => n,Dial(SIP/103,20,D(:1))

[outbound]
include => seven-digit
include => local-devices
include => talk-numeric-outbound
include => dial-uri

[local-devices]
exten => _1, 1, Dial(SIP/101,10)
exten => 101, 1, Dial(SIP/101,10)
exten => _2, 1, Dial(SIP/102,10)
exten => 102, 1, Dial(SIP/102,10)
exten => _3, 1, Dial(SIP/103,10)
exten => 103, 1, Dial(SIP/103,10)

[seven-digit]
exten => _NXXXXXX,1,Set(CALLERID(dnid)=1347${CALLERID(dnid)})
exten => _NXXXXXX,n,Goto(1347${EXTEN},1)
exten => _NXXNXXXXXX,1,Set(CALLERID(dnid)=1${CALLERID(dnid)})
exten => _NXXNXXXXXX,n,Goto(1${EXTEN},1)

[talk-numeric-outbound]
;;; how to check if i am calling from 101 or 102 or 103 and route using proper google voice channel
exten => _1NXXNXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,r)
exten => _+1NXXNXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,r)

[dial-uri]
exten => _[a-z].,1,Dial(SIP/${EXTEN}@${SIPDOMAIN},120,tr)
exten => _[A-Z].,1,Dial(SIP/${EXTEN}@${SIPDOMAIN},120,tr)
exten => _X.,1,Dial(SIP/${EXTEN}@${SIPDOMAIN},120,tr)
[/code]

Not tested, but this must work. Edit it to your enviroment

exten => 123,1,GotoIf($[${CALLERID(num)} = 100]?gv1:gv2)
exten => 123,n(gv1),Dial(${gv1}/${EXTEN}@voice.google.com,r)
exten => 123,n,Hangup()
exten => 123,n(gv2),Dial(${gv2}/${EXTEN}@voice.google.com,r)
exten => 123,n,Hangup()

Okay it turns out this is making my extensions very complicated…
here is what my extensions.conf file looks like now after setting up my mappings. it works, however, is there any optimized way of doing this?

I’d like to shift all the gv1,gv2,gvcall into a single subroutine irrespective of the extension because it has to be performed no matter what. In fact, if at a later point of time, i decided to add more GV accounts and more GV/Motif -> SIP mappings, I’d like to make that change in one place (and not all over the file).

Also, I send my outgoing toll-free calls to a different carrier (arctele). So I still need the tollfree calling to logic to stay agnostic of the per-google voice account / sip mapping “line” or “channel” switching logic.

sip accounts
101 -> actual softphone (my phone)
102 -> fax machine (may be off but is barely dialling out (my phone)
103 -> used by 2nd gv account (other’s phone)

[code][general]
static=yes
writeprotect=no
clearglobalvars=no

[globals]
CONSOLE=Console/dsp ; Console interface for demo
IAXINFO=guest ; IAXtel username/password
TRUNK=Zap/G2 ; Trunk interface
TRUNKMSD=1 ; MSD digits to strip (usually 1 or 0)
GvChannel=

[home-context]
exten => 101,1,Dial(SIP/101,60)
exten => 102,1,Dial(SIP/102,60)
exten => 103,1,Dial(SIP/103,60)

[seven-digit]
exten => _NXXXXXX,1,Set(CALLERID(dnid)=1347${CALLERID(dnid)})
exten => _NXXXXXX,n,Goto(1347${EXTEN},1)
exten => _NXXNXXXXXX,1,Set(CALLERID(dnid)=1${CALLERID(dnid)})
exten => _NXXNXXXXXX,n,Goto(1${EXTEN},1)

[talk-numeric-outbound]
exten => _1NXXNXXXXXX,1,GotoIf($["${CALLERID(num)}" = “101”]?gv1)
exten => _1NXXNXXXXXX,n,GotoIf($["${CALLERID(num)}" = “103”]?gv2)
exten => _1NXXNXXXXXX,n(gv1),Set(GvChannel=Motif/me)
exten => _1NXXNXXXXXX,n,Goto(gvcall)
exten => _1NXXNXXXXXX,n(gv2),Set(GvChannel=Motif/others)
exten => _1NXXNXXXXXX,n(gvcall),Dial(${GvChannel}/${EXTEN}@voice.google.com,r)
exten => _+1NXXNXXXXXX,1,GotoIf($["${CALLERID(num)}" = “101”]?gv1)
exten => _+1NXXNXXXXXX,n,GotoIf($["${CALLERID(num)}" = “103”]?gv2)
exten => _+1NXXNXXXXXX,n(gv1),Set(GvChannel=Motif/me)
exten => _+1NXXNXXXXXX,n,Goto(gvcall)
exten => _+1NXXNXXXXXX,n(gv2),Set(GvChannel=Motif/others)
exten => _+1NXXNXXXXXX,n(gvcall),Dial(${GvChannel}/${EXTEN}@voice.google.com,r)

[talk-numeric-outbound-india]
exten => _01191NXXXXXXXXX,1,GotoIf($["${CALLERID(num)}" = “101”]?gv1)
exten => _01191NXXXXXXXXX,n,GotoIf($["${CALLERID(num)}" = “103”]?gv2)
exten => _01191NXXXXXXXXX,n(gv1),Set(GvChannel=Motif/me)
exten => _01191NXXXXXXXXX,n,Goto(gvcall)
exten => _01191NXXXXXXXXX,n(gv2),Set(GvChannel=Motif/others)
exten => _01191NXXXXXXXXX,n(gvcall),Dial(${GvChannel}/${EXTEN}@voice.google.com,r)
exten => _+91NXXXXXXXXX,1,GotoIf($["${CALLERID(num)}" = “101”]?gv1)
exten => _+91NXXXXXXXXX,n,GotoIf($["${CALLERID(num)}" = “103”]?gv2)
exten => _+91NXXXXXXXXX,n(gv1),Set(GvChannel=Motif/me)
exten => _+91NXXXXXXXXX,n,Goto(gvcall)
exten => _+91NXXXXXXXXX,n(gv2),Set(GvChannel=Motif/others)
exten => _+91NXXXXXXXXX,n(gvcall),Dial(${GvChannel}/${EXTEN}@voice.google.com,r)

[talk-numeric-outbound-germany]
exten => _01149NXXXXXXXXX,1,GotoIf($["${CALLERID(num)}" = “101”]?gv1)
exten => _01149NXXXXXXXXX,n,GotoIf($["${CALLERID(num)}" = “103”]?gv2)
exten => _01149NXXXXXXXXX,n(gv1),Set(GvChannel=Motif/me)
exten => _01149NXXXXXXXXX,n,Goto(gvcall)
exten => _01149NXXXXXXXXX,n(gv2),Set(GvChannel=Motif/others)
exten => _01149NXXXXXXXXX,n(gvcall),Dial(${GvChannel}/${EXTEN}@voice.google.com,r)
exten => _+49NXXXXXXXXX,1,GotoIf($["${CALLERID(num)}" = “101”]?gv1)
exten => _+49NXXXXXXXXX,n,GotoIf($["${CALLERID(num)}" = “103”]?gv2)
exten => _+49NXXXXXXXXX,n(gv1),Set(GvChannel=Motif/me)
exten => _+49NXXXXXXXXX,n,Goto(gvcall)
exten => _+49NXXXXXXXXX,n(gv2),Set(GvChannel=Motif/others)
exten => _+49NXXXXXXXXX,n(gvcall),Dial(${GvChannel}/${EXTEN}@voice.google.com,r)

[talk-gmail-outbound]
exten => _[a-z].@gmail.com,1,Dial(Motif/me/${EXTEN}@gmail.com,r)
exten => _[A-Z].@gmail.com,1,Dial(Motif/me/${EXTEN}@gmail.com,r)

[dial-uri]
exten => _[a-z].,1,Dial(SIP/${EXTEN}@${SIPDOMAIN},120,tr)
exten => _[A-Z].,1,Dial(SIP/${EXTEN}@${SIPDOMAIN},120,tr)
exten => _X.,1,Dial(SIP/${EXTEN}@${SIPDOMAIN},120,tr)

[me-motif]
exten => s,1,NoOp()
same => n,Set(crazygooglecid=${CALLERID(name)})
same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
same => n,Set(CALLERID(num)=${stripcrazysuffix})
same => n,Set(CALLERID(name)=${stripcrazysuffix})
same => n,Dial(SIP/101&SIP/102,20,D(:1))

[others-motif]
exten => s,1,NoOp()
same => n,Set(crazygooglecid=${CALLERID(name)})
same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
same => n,Set(CALLERID(num)=${stripcrazysuffix})
same => n,Set(CALLERID(name)=${stripcrazysuffix})
same => n,Dial(SIP/103,20,D(:1))

[outbound]
include => home-context
include => tollfree-arctele
include => seven-digit
include => talk-numeric-outbound
include => talk-numeric-outbound-india
include => talk-numeric-outbound-germany
include => talk-gmail-outbound
include => dial-uri

[tollfree-arctele]
exten => _411, 1, Dial(SIP/18882472425@tf.arctele.com:5060)
exten => _1800NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1822NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1833NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1844NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1855NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1866NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1877NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1888NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)

[/code]

so basically I need to perform a lookup as to where to send the call if the context ever goes beyond [tollfree-arctele].

Any advice?

regards,
cchhat01

One easy thing you could do is add a variable to each of your sip peers to define which trunk to use

So

[100]
type=friend
callerid=Staff 1 <5205551212>
… other settings for the peer
setvar=__TRUNK=google1

[101]
type=friend
callerid=Staff 2 <5205552345>
… other settings for the peer
setvar=__TRUNK=google2

And then in your outbound dialing you dial the number as
exten => _+1NXXNXXXXXX,1,Dial(Motif/${TRUNK}/${EXTEN}@voice.google.com,r)

[quote=“johnkiniston”]One easy thing you could do is add a variable to each of your sip peers to define which trunk to use

So

[100]
type=friend
callerid=Staff 1 <5205551212>
… other settings for the peer
setvar=__TRUNK=google1

[101]
type=friend
callerid=Staff 2 <5205552345>
… other settings for the peer
setvar=__TRUNK=google2

And then in your outbound dialing you dial the number as
exten => _+1NXXNXXXXXX,1,Dial(Motif/${TRUNK}/${EXTEN}@voice.google.com,r)[/quote]

This. This would have saved me the trouble. This is exactly what I was looking for. Something sweet and simple. Except, I didn’t see it in time and I started looking at macros. I wrote a macro which goes to work and decides which trunk to use. :frowning:

I think your solution is much more elegant. I suppose the use of __TRUNK rather than just TRUNK makes it visible as a global?

I’m making my solution visible to others as well in case someone else comes looking for answer to the same question that I had.

Thanks for the help.

PS here’s my extensions.conf

[code][general]
static=yes
writeprotect=no
clearglobalvars=no

[globals]
CONSOLE=Console/dsp ; Console interface for demo
IAXINFO=guest ; IAXtel username/password
TRUNK=Zap/G2 ; Trunk interface
TRUNKMSD=1 ; MSD digits to strip (usually 1 or 0)

[home-context]
exten => 101,1,Dial(SIP/101,60)
exten => 102,1,Dial(SIP/102,60)
exten => 103,1,Dial(SIP/103,60)

[seven-digit]
exten => _NXXXXXX,1,Set(CALLERID(dnid)=1347${CALLERID(dnid)})
exten => _NXXXXXX,n,Goto(1347${EXTEN},1)
exten => _NXXNXXXXXX,1,Set(CALLERID(dnid)=1${CALLERID(dnid)})
exten => _NXXNXXXXXX,n,Goto(1${EXTEN},1)

[talk-numeric-outbound]
exten => _1NXXNXXXXXX,1,Macro(gvdialout)
exten => _+1NXXNXXXXXX,1,Macro(gvdialout)

[talk-numeric-outbound-india]
exten => _01191NXXXXXXXXX,1,Macro(gvdialout)
exten => _+91NXXXXXXXXX,1,Macro(gvdialout)

[talk-numeric-outbound-germany]
exten => _01149NXXXXXXXXX,1,Macro(gvdialout)
exten => _+49NXXXXXXXXX,1,Macro(gvdialout)

[talk-gmail-outbound]
exten => _[a-z].@gmail.com,1,Dial(Motif/google/${EXTEN}@gmail.com,r)
exten => _[A-Z].@gmail.com,1,Dial(Motif/google/${EXTEN}@gmail.com,r)
;exten => _[a-z].@gmail.com,1,Dial(Motif/google/${EXTEN}@gmail.com,r)
;exten => _[A-Z].@gmail.com,1,Dial(Motif/google/${EXTEN}@gmail.com,r)

[dial-uri]
exten => _[a-z].,1,Dial(SIP/${EXTEN}@${SIPDOMAIN},120,tr)
exten => _[A-Z].,1,Dial(SIP/${EXTEN}@${SIPDOMAIN},120,tr)
exten => _X.,1,Dial(SIP/${EXTEN}@${SIPDOMAIN},120,tr)

[me-motif]
exten => s,1,NoOp()
same => n,Set(crazygooglecid=${CALLERID(name)})
same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
same => n,Set(CALLERID(num)=${stripcrazysuffix})
same => n,Set(CALLERID(name)=${stripcrazysuffix})
same => n,Dial(SIP/101&SIP/102,20,D(:1))

[other-motif]
exten => s,1,NoOp()
same => n,Set(crazygooglecid=${CALLERID(name)})
same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
same => n,Set(CALLERID(num)=${stripcrazysuffix})
same => n,Set(CALLERID(name)=${stripcrazysuffix})
same => n,Dial(SIP/103,20,D(:1))

[macro-gvdialout]
exten => s,1,GotoIf($["${CALLERID(num)}" = “101”]?gv1)
same => n,GotoIf($["${CALLERID(num)}" = “103”]?gv2)
same => n(gv1),Set(gvchannel=Motif/me)
same => n,Goto(gvcall)
same => n(gv2),Set(gvchannel=Motif/other)
same => n(gvcall),Dial(${gvchannel}/${MACRO_EXTEN}@voice.google.com,r)
same => n,Hangup()
same => n,MacroExit

[outbound]
include => home-context
include => tollfree-arctele
include => seven-digit
include => talk-numeric-outbound
include => talk-numeric-outbound-india
include => talk-numeric-outbound-germany
include => talk-gmail-outbound
include => dial-uri

[tollfree-arctele]
exten => _411, 1, Dial(SIP/18882472425@tf.arctele.com:5060)
exten => _1800NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1822NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1833NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1844NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1855NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1866NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1877NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
exten => _1888NXXXXXX,1,Dial(SIP/${EXTEN}@tf.arctele.com:5060)
[/code]

The two Underscores are for channel inheritance

wiki.asterisk.org/wiki/display/ … nheritance

The great thing about Asterisk is there is always more than one way to do something, If your solution works for you then there is nothing wrong about it vs my solution.

I would however recommend rewriting your macro as a subroutine instead due to Macro being deprecated.

You could easily write it this way:

[sub-gvdialout]
exten => _X.,1,NoOP()
same => n,ExecIf($["${CALLERID(num)}" = “101”]?Set(gvchannel=Motif/me))
same => n,ExecIf($["${CALLERID(num)}" = “103”]?Set(gvchannel=Motif/other))
same => n,GotoIf($[${ISNULL(${gvchannel})}]?Error)
same => n,Dial(${gvchannel}/${EXTEN}@voice.google.com,r)
same => n,Hangup()
same => n,Return()
same => n(Error),NoOP()
same => n,Verbose(1,No Channel found to dial ${EXTEN})
same => n,Playtones(congestion)
same => n,Congestion(12)
same => n,Return()