Cutting long distance costs

The situation:

We’re a SIP-PSTN gateway for our users. As such, all our users have real PSTN phone numbers, so incoming calls have extensions like:

[local]
exten => 6045551234,1,Dial(SIP/foo1|25)

exten => 6045551235,1,Dial(SIP/foo2|25)

exten => 2505551234,1,Dial(SIP/foo3|25)

And outgoing calls look like:

[outgoing]
; Toll free example
exten => _1888NXXXXXX,1,Dial(Zap/g1/${EXTEN},100)
exten => _1888NXXXXXX,2,Hangup
; Local call example, usually 604 area code
exten => _NXXNXXXXXX,1,Dial(Zap/g1/${EXTEN})
exten => _NXXNXXXXXX,2,Noop(LOCAL CALL THRU TRUNK)
exten => _NXXNXXXXXX,3,Hangup
; Long distance example
exten => _1NXXNXXXXXX,1,Dial(SIP/${EXTEN}@ldprovider1)
exten => _1NXXNXXXXXX,2,Dial(SIP/${EXTEN}@ldprovider2)
exten => _1NXXNXXXXXX,3,Hangup

How would I make the technically-long-distance-but-local-to-us calls between 250 and 604 area codes first check with the extensions in [local], before dialing out on the local or long distance channels? Aside from repeating every extension in [local] under the [outgoing] context (there’s really a lot of them).

change the dial pattern matching on the local calls from:

exten => _NXXNXXXXXX,1,Dial(Zap/g1/${EXTEN})

to:

exten => _604NXXXXXX,1,Dial(Zap/g1/${EXTEN})

Attempting to make calls to long distance numbers without the 1 will just result in an operator message anyway. This doesn’t help much.

What I’m really worried about is that when the customer at 6045551234 calls 12505551234, a long distance call is made, which subsequently gets routed right back to us. We still pay the long distance charges, even though it should be an internally routed call. Technically, the solution is to put all of our phone numbers that are in [local] into [outgoing] as well. At least I know that works. It’s rather cumbersome however.