Looking for guidance on my first custom dialplan
So let me explain, working for a school district using FreePBX. We do not want outside calls to be able to ring into a classroom extension during “class hours” but inside goes directly to voicemail. We want internal calls to be able to call into a classroom and calls to be able to transfer in. After class hours, the direct dial would ring directly into the classroom as normal.
For example, we have an IVR with direct dial enabled, and from 7am-3pm Monday-Friday any classroom extension will go to voicemail. To be able call into the classroom the caller will need to call the office from the IVR and the office can decide to transfer directly or to VM.
Since there was no built-in solution for this I just disable direct dial and told the school, parents will need to call the office to get transferred in. Not ideal but worked.
Finally, I rolled up my sleeves and try to build my first custom dialplan.
First I created a SQL database called customdb and a table called classroom_phones, with a list of extensions and daytimevm set to 1 to go voicemail.
±----------±----------+
| extension | daytimevm |
±----------±----------+
| 1002 | 1 |
| 1003 | 1 |
±----------±----------+
Then I added the following under /etc/asterisk/extensions.conf
[from-did-direct]
include => daytimevm-custom
include => ext-findmefollow
include => ext-local[daytimevm-custom]
exten => _XXXX,1,Answer()
same => n,MYSQL(Connect connid localhost READONLY_USERNAME READONLY_PW customdb)
same => n,MYSQL(Query resultid ${connid} SELECT daytimevm from classroom_phones WHERE extension=‘${EXTEN}’ AND daytimevm LIKE ‘1’ LIMIT 1)
same => n,MYSQL(Fetch fetchid ${resultid} classroom)
same => n,MYSQL(Disconnect ${connid})
same => n,NoOp(========== The DAYTIMEVM value is ${classroom} ==========)
same => n,GotoIf($[“${classroom}” != “1”]?SkipForwardVM)
same => n,GotoIfTime(15:30-7:00,mon-sun,,?SkipForwardVM)
same => n(ForwardVM),Voicemail(${EXTEN},u)
same => n,Macro(hangupcall,)
same => n(SkipForwardVM),Goto(from-did-direct-continue,${EXTEN},1)[from-did-direct-continue]
include => ext-findmefollow
include => ext-local
On my test system it seems to be working fine, but before I deploy this into production want to get your guys to opinion on this. Since this is my first I am sure, I am sure it is not efficiently written. The only thing I can not get working is Direct Dial when I have Directory with a spell by name directory enabled. From what I could tell FreePBX consider this an internal transfer that bypasses from-did-direct
Thanks in advance.