Multiple trunk dialing?

We recently switched from Vonage to running our own Asterisk server with one trunk. This worked great after a learning curve for myself (I had to set it up), and we have multiple extensions and such which all work. Now we added a second trunk. I added the trunk to my sip.conf, but I am not sure how to make it work. The original trunk is configured as “line1” and the new one is “line2”. I currently dial as follows.

; USA / Canada
exten => _1NXXNXXXXXX,1,Log(NOTICE, Dialing out from ${CALLERID(all)} to ${EXTEN} through Nextiva)
exten => _1NXXNXXXXXX,2,Dial(SIP/line1/${EXTEN},120)
exten => _1NXXNXXXXXX,n,Playtones(congestion)
exten => _1NXXNXXXXXX,n,Hangup()

; 10 Digits dialing
exten => _NXXNXXXXXX,1,Log(NOTICE, Dialing out from ${CALLERID(all)} to 1${EXTEN} through Nextiva)
exten => _NXXNXXXXXX,2,Dial(SIP/line1/1${EXTEN},120)
exten => _NXXNXXXXXX,n,Playtones(congestion)
exten => _NXXNXXXXXX,n,Hangup()

; 7 Digits local
exten => _NXXXXXX,1,Log(NOTICE, Dialing out from ${CALLERID(all)} to 1910${EXTEN} through Nextiva)
exten => _NXXXXXX,2,Dial(SIP/line1/1910${EXTEN},120)
exten => _NXXXXXX,n,Playtones(congestion)
exten => _NXXXXXX,n,Hangup()

How would I configure Asterisk to dial out on line2 if line1 is in use, or vice-versa? My hunch is that I would have to script something along the lines of “if I cannot dial line1, dial line2, els eplay the congestion tone”, but I am not quite sure how to do that yet. Also, our published telephone number is line1. If somebody is on line1 and another client calls in, how would I roll that over to line2?

Dial…/line1
Dial…/line2
Congestion

Ideally check the hangup cause to avoid calling people who don’t answer twice, etc. Congestion is only needed if you want to override the status from line2.

You can’t do the second part as it requires cooperation between the two ITSPs at a level where it would be cheaper to buy a SIP trunk with enough capacity using just one line.

So I should look at a single trunk that can handle three calls versus three trunks. Is that what you are saying?

As tot he first part, how would I check the status and handle it? I am a long-time C/C++ developer, but am new to this language and have yet to even see how to check a dial result, much less fork into an ‘else’ clause.

The definition of trunk pretty much means that it can support simultaneous calls.

One call at a time SIP services are intended for people with a simple SIP phone, not for use with PABXes.

Examples of dialplan coding can be found in the sample extension.conf supplied with the source code. More in depth information can be obtained from http://www.asteriskdocs.org/. The values of ${HANGUPCAUSE} are the nearest available ISDN clearing cause codes.