Dreary day here today. I got some yard work done before the drizzle started, but now I need a rainy Saturday project. I am calling this boomerang, but need a better name I think.
From time to time we get queries in the forum here asking for some way to automatically route an inbound call to the last person they were speaking with. Until yesterday, my thinking was that a sufficiently complex SQL query to figure out the extension from CDR/CEL database, would be the only way to make that happen. But what if instead of using the CDR/CEL database, we keep track of the extension/CID vales independently in a simple format. Here is a pretty rough proof of concept: https://gist.github.com/lgaetz/e7dbbcd6004559c5b467a146a8b14cfc
What it does at the moment:
- Inbound and outbound calls get a hangup handler added to the channel
- when the channel terminates, the hangup handler attempts to figure out the trunk PSTN number and the most recent extension they were talking to, and writes it to the ASTDB as
boomerang/<PSTN CID> = <Extension Number>
With the above in place, you could route an inbound call to a Dynamic Route and query the astdb using the Asterisk Variable option with
${DB(boomerang/${CALLERID(number):-10})}
The returned result will either be null or an extension number. You can then branch the call based on the result.
I’ve built in some assumptions for 10 digit NANP number format and it’s a bit rough at the moment. I think this would be most useful if the inbound call first rings the looked up extension for a short while before going to a reception destination. There is no elegant way to do that at the moment, which gives me an idea for another project, a dynamic ring group. Works the same as a conventional ring group except you pass the extensions to ring as a variable instead of pre-defining them in the GUI.