I am trying to configure freepbx to route certain extensions via a specific trunk. I have seen a few ways to do this and currently trying to do this with custom contexts.
Basically I am using two companies on the same PBX and calls from extensions with a context of company1 need to go via company1 trunk and calls from extensions with a context of company2 need to go via the company2 trunk.
Here is what I have so far:
[from-internal]
exten => h,1,Hangup()
[company1]
exten => 1234512345,1,Set(__FROM_DID=${EXTEN})
exten => 1234512345,n,Gosub(app-blacklist-check,s,1)
exten => 1234512345,n,ExecIf($[ "${CALLERID(name)}" = "" ] ?Set(CALLERID(name)=${CALLERID(num)}))
exten => 1234512345,n,Set(__CALLINGPRES_SV=${CALLERPRES()})
exten => 9498851902,n,Set(CALLERPRES()=allowed_not_screened)
exten => s,1,Dial(SIP/1500)
[company2]
exten => 1234567890,1,Set(__FROM_DID=${EXTEN})
exten => 1234567890,n,Gosub(app-blacklist-check,s,1)
exten => 1234567890,n,ExecIf($[ "${CALLERID(name)}" = "" ] ?Set(CALLERID(name)=${CALLERID(num)}))
exten => 1234567890,n,Set(__CALLINGPRES_SV=${CALLERPRES()})
exten => 1234567890,n,Set(CALLERPRES()=allowed_not_screened)
exten => s,1,Dial(SIP/1701)
This was taken from a site discussing multitenants. I need to modify this so that any extension goes to the trunk I specify. I am sure I can work out the pattern matching for any extension, but how can I say goto this trunk for example. I do not seem to be able to find anything on this.
Finally go round to a solution for this after reading every bit of documentation I could get my hands on.
I used the following code in extensions_custom.conf:
[company1]
include => from-internal
exten => _X.,1,Set(_COMPANY=company1)
include => macro-dialout-trunk-predial-hook
[company2]
include => from-internal
exten => _X.,1,Set(_COMPANY=company2)
include => macro-dialout-trunk-predial-hook
I used the following code in extensions.conf
[macro-dialout-trunk-predial-hook]
exten => s,1,Set(PREDIAL_HOOK_RET=)
exten => s,n,Set(DIAL_TRUNK=${IF($[ ${COMPANY} = company2]?2:${IF($[ ${COMPANY} = company1]?1:99)})})
exten => s,n,Set(OUTBOUND_GROUP=${IF($[ ${COMPANY} = company2]?2:${IF($[ ${COMPANY} = company1]?1:99)})})
exten => s,n,ExecIf($[${ISNULL(${COMPANY})}]?Hangup())
exten => s,n,MacroExit()
I am sure this could be tidied and improved, but for now, I have the solution I need. Hopefully this will help someone else.