Just to document what I’ve proposed in one message so someone may verify it’s correctness:
First:
Create an outbound route that uses any trunk (doesn’t matter much which because it will never be used) - label it something clear like "dummy-inserting-acctcodes"
In the outbound route, creat the dialplan to reflect what you allow to dial (minimum is 77XXXXXX.). Here you may choose to either define an actual pattern or as an example “77[0-689]XXXXX.” Make sure you have enough minimum Xs to insert a code and then a further 2 Xs and a period. Again, the pattern might be 77[0-689]XXX1XXXXXXXXXX (for four digit account code) but this would restrict you to US numbers. Essentially you need to make sure that whatever you define after the account code can be handled by your dial plan and that the initial part does NOT satisfy any dial patterns you actually use (hence my not allowing 777X).
After you submit Changes and Apply Config you can
First read extensions-additional.conf to find the entry that shows the new route… search for [outrt- and in all probability the last entered outbound route will show first - that’s what you’re looking for… say it is [outrt-17]
edit /etc/asterisk/extensions-custom.conf
insert:
[outrt-17-custom]
exten => _77[0-689]XXXXX.!,1,Noop(insert accnt code on the fly)
exten => _77[0-689]XXXXX.!,n,Set(CDR(accountcode)=${EXTEN:2:4}-${CDR(accountcode)})
exten => _77[0-689]XXXXX.!,n,Goto(outbound-allroutes,${EXTEN:6:15},1)
exten => h,1,Hangup()
Here this would cater for any dial pattern after the 4 digit account code (please note account codes here cannot begin with a 7 - you can obviously allow for a different setup but mind the rest of your dialplan). I have also allowed retaining the phone-configured account code in this string (your judgement if you want this or not)- if you enter 77123401197317543700 (as an example to call me) your account code will show 1234-extension acct code and the number 01197317543700 will be sent back and re-parsed to use your overseas calls provider (which perhaps would process the number further before sending).
Again, please note after processing these lines, you are thrown back at the top of the outbound-allroutes which will re-parse the remaining portion of your dialstring to send you to the correct trunk.
Save the file (you might be prompted to enter your password) and in Asterisk’s CLI type
core restart when convenient
which will kick you out of Asterisk but will restart it.
type Asterisk -r -vvvvvvvvvvv (to reenter Asterisk)
or just enter it from the web browser and
core set verbose 30
Now you can test.
Please also test all dialling situations from various devices, did(s) and disa(s) while watching your CLI - this is to ensure that you can see if it is failing.
Some of your extensions might choke on dialling a number beginning with 77 so you would probably have to solve these problems.