Redirect calls from external to VM part2

func_odbc is life-changing.

One thing I have with it is to add SMS logging to the CDR DB, which is straightforward because FreePBX already uses ODBC to interface with the CDR DB.

2 Likes

Thanks, I will need to look into ODBC, but I like the looks of AMPUSER database instead. This would give me the flexibility to allow others that are not familiar with MySQL to edit settings. Are there any other fields besides accountcode that I can use? I am currently using accountcode for storing physical location of the phone.

Yes I am in the USA, and I have an inbound route emergency call back to a ring group. That will be able to direct\transfer them back into the room.

Be careful not to confuse the mysql ampuser table with the astdb.sqlite3 AMPUSER family , (where you could read and set the DND of an extension to accomplish similar behavior dynamically via a cron job or a systemd .timer service )

No. I have periodically considered putting multiple comma separated values in that field and then using REGEX or SHIFT to look thru them, but never did any actual tests to prove to myself that it would work.

Is there anything else that distinguishes classroom phones from admin phones, such as extension range? If so, you may be able to accomplish your goal without doing any kind of lookups at all, but just matching on an existing characteristic.

No sadly not, extensions are sprinkled in on who needs daytime calls, and every other year it changes due to room changes. Extension safe in the Room for example XX01 is room 1, XX02 is room 2 etc.

Regex might work! Thanks this is VERY helpful. I will post a new dialplan once I get something working. I am sure there are other school districts in the same situation.

You could also consider using part of the CallerID name string from the AstDB, i.e. if the first 9 characters $["${DB(AMPUSER/xxx/cidname):9}"= "Classroom"]

. . . or perhaps add an AMPUSER/xxx/Classroom field ?

Oh I think dicko is right, I am confusing the astdb.sqlite3 database with the mysql amuser. This accountcode is not the same as ${DB(AMPUSER/${AMPUSER}/accountcode)} is it?

The GUI/mysql data is for the most part static and only instigated on a ‘reload’, on the other hand manipulating the astdb is dynamic. If you decide to so manipulate the astdb, only use the asterisk database API ‘wrapper functions’, or you will regret it at some point in the future :wink: .

The GUI account code field is in the AstDB, and you can confirm that from the Asterisk console with

database show AMPUSER xxxx/accountcode

sub the ext number for the x’s

so “${DB(AMPUSER/${AMPUSER}/accountcode)}” and “database show AMPUSER xxxx/accountcode” is pointing to the same place?

Yes. DB = database.

Pro Tip: at the bash prompt, you can grep the AstDB with:

asterisk -x "database show" | grep <string>

OK awesome! that is what I thought at first, guess I got into my own head. Back to the drawing board.

OK here it is, I added @classroom under Account Code for any classroom extension

Used a regex to search for the word @classroom in the above field

;AMPUSER daytime redirect
[daytimevm-custom-ampuser]
exten => _XXXX,1,Answer()
same => n,Set(CALLER_ACCOUNTCODE=${DB(AMPUSER/${EXTEN}/accountcode)})
same => n,NoOp(========== The DAYTIMEVM for ${EXTEN} value is ${CALLER_ACCOUNTCODE} ==========)
same => n,NoOp(========== ${EXTEN} @classroom = ${REGEX("@classroom" ${CALLER_ACCOUNTCODE})} ==========)
same => n,GotoIf($["${REGEX("@classroom" ${CALLER_ACCOUNTCODE})}" != “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)
same => n,Hangup()

Only thing I wish I could get working is, instead of hard coding the gotoiftime, but instead referencing the “Time Groups” so I could update the times from the gui. As well, if I have a Directory with “Spell By Name” enabled it does not apply to this dialplan. I cant figure out what context it is using, seems to be using “from-internal”

Thanks @dicko and @lgaetz!!!

A time condition (not a group) has a toggle feature code with an associated hint:

*CLI> core show hint *271
*[email protected]: Custom:TC1            State:InUse           Presence:not_set         Watchers  0

See this post where you can see the value of a hint with

${EXTENSION_STATE(*[email protected])}

In this case it will probably return either NOT_INUSE or INUSE.

Awesome! thanks @lgaetz I got it working with Time conditions now! Here itis if anyone is interested.

exten => _XXXX,1,Answer()
same => n,Set(CALLER_ACCOUNTCODE=${DB(AMPUSER/${EXTEN}/accountcode)})
same => n,Set(classroom_hours=${EXTENSION_STATE(*[email protected])})
same => n,Set(holiday=${EXTENSION_STATE(*[email protected])})
same => n,GotoIf($["${REGEX("@classroom" ${CALLER_ACCOUNTCODE})}" != “1”]]?SkipForwardVM)
same => n,GotoIf($["${classroom_hours}" = “INUSE”]?SkipForwardVM)
same => n,GotoIf($["${holiday}" = “NOT_INUSE”]?SkipForwardVM)
same => n(ForwardVM),Voicemail(${EXTEN},u)
same => n,Macro(hangupcall,)
same => n(SkipForwardVM),Goto(from-did-direct-continue,${EXTEN},1)
same => n,Hangup()

3 Likes

When you get it refined to the point you like it, create a new thread in ‘Tips and Tricks’ with the result.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.