Specifying DID for outbound calls

Home » Asterisk Users » Specifying DID for outbound calls
Asterisk Users 19 Comments

The host I am working with has two accounts from the same DID
provider. Incoming calls work correctly and dial the appropriate
extensions. This also allows incoming calls to be billed appropriately to the
individual DID accounts.

Outgoing calls from either extension default to the first DID, i.e.
calls from either extension have the same callerID. How can an
extension specify separate outgoing contexts so the correct number is
associated with it, also allowing the SIP provider to recognize the
difference for billing purposes, or is there a better way?

In short I’m looking to associate an outgoing call from an extension
with a specific number.

Here’s the sip.conf for both accounts as they are using IP routing,
I’m assuming I do not have to perform auth based to separate the two
accounts for outgoing calls:

[vitel-inbound]
type=friend
dtmfmode=auto
host=inbound18.vitelity.net
context=inbound
allow=all
insecure=very

[vitel-outbound]
type=friend
dtmfmode=auto
host=outbound.vitelity.net
context=outbound
insecure=very
allow=all

Thanks

19 thoughts on - Specifying DID for outbound calls

  • The outgoing caller-id is probably just the extension number, so the
    provider is setting it to a default (usually the main billing number). You
    can set what Asterisk sends as the outbound Caller-ID in the outbound
    context before the Dial statement. Make sure your provider will honor what
    you set, as many filter what you can send to only the DIDs they provide for
    you.

    Take a look here for more information on setting the caller-id in the
    dialplan:

    http://www.voip-info.org/wiki/view/Asterisk+func+callerid

    -Jonathan

  • Thanks for the heads up, I have been setting the caller-ID but the
    trouble I’m running into is specifying the which number to call out
    as. How can an extension specify a different number? See below for my
    current extension.conf, thanks.

    [default]
    exten => 201,1,Dial(SIP/201@,30)
    exten => 201,n,Voicemail(201@default)
    exten => 201,n,Hangup

    exten => 202,1,Dial(SIP/202,30)
    exten => 202,n,Voicemail(202@default)
    exten => 202,n,Hangup

    include => inbound
    include => outgoing

    [inbound]
    exten => 3012323434,1,Goto(default,201,1)
    exten => 3013232322,1,Goto(default,202,1)

    [outgoing]

    exten => _1NXXNXXXXXX,1,Set(CALLERID(num)=3012323434)
    exten => _1NXXNXXXXXX,n,Set(CALLERID(name)=”User1″)
    exten => _1NXXNXXXXXX,n,Dial(SIP/${EXTEN}@vitel-outbound)

    [outgoing2]

    exten => _1NXXNXXXXXX,1,Set(CALLERID(num)=3013232322)
    exten => _1NXXNXXXXXX,n,Set(CALLERID(name)=”User2″)
    exten => _1NXXNXXXXXX,n,Dial(SIP/${EXTEN}@vitel-outbound)

  • Hi Stephen,

    You can check the channel-name to see which extension is making the
    call and set the CallerID accordingly. The channel-name will be
    something like “SIP/201-abc23ef34” or “SIP/User1-def34abc51”. The 201
    or User1 part depends on how you put the username in sip.conf You can
    use the CUT function to get the calling extension and then jump to the
    correct CallerID. I’ve used something like this:

    [outgoing]
    exten => _1NXXNXXXXXX,1,Set(Outgoing=${CUT(CHANNEL,/,2)})
    exten => _1NXXNXXXXXX,n,Set(Outgoing=${CUT(Outgoing,-,1)})
    exten => _1NXXNXXXXXX,n,GotoIf($[“${Outgoing}” = “User2”]?20:10)
    exten => _1NXXNXXXXXX,10,Set(CALLERID(num)=3012323434)
    exten => _1NXXNXXXXXX,n,Set(CALLERID(name)=”User1″)
    exten => _1NXXNXXXXXX,n,Dial(SIP/${EXTEN}@vitel-outbound)
    exten => _1NXXNXXXXXX,n,Goto(h,1)
    exten => _1NXXNXXXXXX,20,Set(CALLERID(num)=3013232322)
    exten => _1NXXNXXXXXX,n,Set(CALLERID(name)=”User2″)
    exten => _1NXXNXXXXXX,n,Dial(SIP/${EXTEN}@vitel-outbound)
    exten => _1NXXNXXXXXX,n,Goto(h,1)

    But in my case I had two different domains. E.g.
    Dial(SIP/${EXTEN}@provider-ID1) and Dial(SIP/${EXTEN}@provider-ID2)
    instead of setting the CallerID.

    Not that the Cut doesn’t work correctly if you use a minus-sign in the username.

    Best regards,
    Jeroen Eeuwes

  • I think I’d probably replace the two outgoing contexts with one, using a
    GotoIf to distinguish between the two phones (branching into your
    current code).

    Alternatively you could give them each a custom context (say phone1 and
    phone2); phone1 would include incoming and outgoing1, phone2 would
    include incoming and outgoing2.

  • Thanks Jeroen, though it is still not firing correct, I have provided
    a little more information.

    Here are the channel-names:

    SIP/201-0000000a

    SIP/101-00000012

    Here is the extension information from the sip.conf:

    [101]
    type=friend
    username=101
    secret=0000
    mailbox=101
    callerid=”User One” <101>
    host=dynamic
    nat=yes
    dtmfmode=rfc2833
    canreinvite=no
    reinvite=no
    qualify=yes

    [201]
    type=friend
    username=201
    secret=0000
    mailbox=201
    callerid=”User Two” <201>
    host=dynamic
    nat=yes
    dtmfmode=rfc2833
    canreinvite=no
    reinvite=no
    qualify=yes

    Here is the updated outgoing context that you provided with a few updates.

    [outgoing]
    exten => _1NXXNXXXXXX,1,Set(Outgoing=${CUT(CHANNEL,/,2)})
    exten => _1NXXNXXXXXX,n,Set(Outgoing=${CUT(Outgoing,-,1)})
    exten => _1NXXNXXXXXX,n,GotoIf($[“${Outgoing}” = “User Two”]?20:10)
    exten => _1NXXNXXXXXX,10,Set(CALLERID(num)=3012323434)
    exten => _1NXXNXXXXXX,n,Set(CALLERID(name)=”User One”)
    exten => _1NXXNXXXXXX,n,Dial(SIP/${EXTEN}@vitel-outbound)
    exten => _1NXXNXXXXXX,n,Goto(h,1)
    exten => _1NXXNXXXXXX,20,Set(CALLERID(num)=3013232322)
    exten => _1NXXNXXXXXX,n,Set(CALLERID(name)=”User Two”)
    exten => _1NXXNXXXXXX,n,Dial(SIP/${EXTEN}@vitel-outbound)
    exten => _1NXXNXXXXXX,n,Goto(h,1)

    Based on the information above, what should be altered to correctly
    associated the number with the relevant extension?

    Thanks

  • On Sun, Dec 19, 2010 at 1:52 PM, William Stillwell
    wrote:
    href=”mailto:asterisk-users-bounces@lists.digium.com”>asterisk-users-bounces@lists.digium.com

    You’re setting a callerid in sip.conf, so in extensions.conf why not:
    if callerid(num) = 201, set callerid(num) = 3012323434 (or whatever)?

    sean

  • William, I’m not familiar with AGI scripts, it might be a little
    overkill for what I am trying to accomplish.

  • Joshua, that seems reasonable. I have two “best practice” questions
    before moving further if anyone would like to chime in.

    First, when using multiple accounts from the same DID provider, is it
    ideal to use IP based routing using one context as I currently am or
    have a separate contexts for each account in the sip.conf?

    Secondly, it never crossed my mind that the caller-ID was being set in
    the sip.conf and extensions.conf. I guess the extension.conf takes
    precedence. At this point is was not my intention to use the sip.conf
    and I can easily remove it and set the variable in the extension.conf.
    I am just not familiar with what is ideal.

    Most of my configuration has come from snippets I’ve found per example.

    Thanks

  • So I should have multiple incoming and outgoing contexts? Vitelity
    will allow me to use IP routing or user/pass auth, the latter would
    allow me to specify the outgoing context, this would also guarantee
    the correct account is billed and not alone rely on caller-ID.

    Thanks for being responsive, I do not work with Asterisk much,
    actually I do not touch it unless I need to add more functionality
    outside of regular patching so my fu is not strong in this area 😉

  • I believe I have made a little headway. I have two outgoing DID
    contexts and have changed the GotoIf statement to the extension name.
    User One acts as expected and User two now displays unknown when
    calling so I believe it is trying to to goto 20 but it’s not quite
    making it. Any tips? Thanks

    [outgoing]
    exten => _1NXXNXXXXXX,1,Set(Outgoing=${CUT(CHANNEL,/,2)})
    exten => _1NXXNXXXXXX,n,Set(Outgoing=${CUT(Outgoing,-,1)})
    exten => _1NXXNXXXXXX,n,GotoIf($[“${Outgoing}” = “201”]?20:10)
    exten => _1NXXNXXXXXX,10,Set(CALLERID(all)=”User One” <3012323434>)
    exten => _1NXXNXXXXXX,n,Dial(SIP/${EXTEN}@vitel-outbound)
    exten => _1NXXNXXXXXX,n,Goto(h,1)
    exten => _1NXXNXXXXXX,20,Set(CALLERID(num)=”User Two” <3013232322>)
    exten => _1NXXNXXXXXX,n,Dial(SIP/${EXTEN}@vitel-outbound2)
    exten => _1NXXNXXXXXX,n,Goto(h,1)

  • This should either be CALLERID(all) or just set the number on the line
    above. As a side note, I prefer to use labels an not line numbers.
    Less to change later…

    I’ll also give a +1 to using setvar. It allows you to abstract the
    dial plan much more. I use this feature a lot in both static and
    Realtime configurations. For example (not tested, but based on live
    production code):

    sip.conf:
    [101]

    setvar=EXTERNAL_CALLERID=”User One <3012323434>”

    [201]

    setvar=EXTERNAL_CALLERID=”User Two <3013232322>”

    extensions.conf:
    [outgoing]
    exten => _1NXXNXXXXXX,1,Verbose(1, Someone is making a call out)
    exten => _1NXXNXXXXXX,n,ExecIf($[${EXISTS(${EXTERNAL_CALLERID})}]?Set(CALLERID(all)=${EXTERNAL_CALLERID}))
    exten => _1NXXNXXXXXX,n,Dial(SIP/${EXTEN}@vitel-outbound)

    But then I am sure there are 100 other ways to do this same thing.

    -Jonathan