Last active
May 30, 2021 16:46
-
-
Save lgaetz/e7dbbcd6004559c5b467a146a8b14cfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Name: lgaetz-boomerang | |
; | |
; Latest version: https://gist.github.com/lgaetz/e7dbbcd6004559c5b467a146a8b14cfc | |
; | |
; Description: this dialplan Stores the most recent local extension number to speak with the referenced CallerID Number | |
; To direct an inbound call based on the last extension they last spoke to, do astdb query on the key/family | |
; boomerang/${CALLERID(number):-10} | |
; if set, will give most recent local exten. Something like dynamic routes could be used to branch call flow | |
; based on the returned result | |
; license: GNU GPL3+ | |
; | |
; Version history: | |
; 2021-05-29 First commit astdb writes rough but working | |
[from-pstn-boomerang] | |
; add hangup handler to inbound channel, trunks must use this context | |
exten => _.,1,Noop(Entering user defined context from-pstn-boomerang in extensions_custom.conf) | |
exten => _.,n,Set(CHANNEL(hangup_handler_push)=boomerang-tag-call,s,inbound) | |
exten => _.,n,Goto(from-pstn,${EXTEN},1) | |
[macro-dialout-trunk-predial-hook] | |
; add hangup handler to outbound call | |
; using this context is not ideal, the hangup handler is on the dialing channel, not the dialed channel. | |
; to work better needs to be spliced to func-apply-sipheaders | |
exten => s,1,Noop(Entering user defined context macro-dialout-trunk-predial-hook in extensions_custom.conf) | |
exten => s,n,Set(CHANNEL(hangup_handler_push)=boomerang-tag-call,s,outbound) | |
exten => s,n,MacroExit | |
[boomerang-tag-call] | |
exten => s,1,Noop(Entering user defined context boomerang-tag-call in extensions_custom.conf) | |
; exten => s,n,DumpChan() | |
; exten => s,n,Noop(CID ${CALLERID(number)}) | |
; exten => s,n,Noop(DIALEDPEERNUMBER ${DIALEDPEERNUMBER}) | |
; exten => s,n,Noop(DNIS ${CONNECTEDLINE(number)}) | |
exten => s,n,GoToIf($["${DIRECTION}"="INBOUND"]?inbound) | |
exten => s,n,GoToIf($["${OUTNUM}"!=""]?outbound) | |
exten => s,n,Return ; give up | |
exten => s,n(inbound),Noop(Inbound call) | |
; using dialed peer number to determine what exten was the most recent to talk to this cid, format is "6002" chan_sip, and "6003/sip:6003@10.8.0.7:5060;ob" for chan_pjsip; | |
exten => s,n,set(extnum=${CUT(DIALEDPEERNUMBER,/,1)}) ; numeric extension number | |
; if extnum string exists as a local extension, write to astdb with final 10 digits of incoming CID number | |
exten => s,n,ExecIf($[${DB_EXISTS(AMPUSER/${extnum}/device)}]?Set(DB(boomerang/${CALLERID(number):-10})=${extnum})) | |
exten => s,n,Return | |
exten => s,n(outbound),Noop(Outbound call) | |
; if AMPUSER string exists as a local extension, write to astdb with final 10 digits of conected CID number | |
; again, not ideal only the original dialing extension is stored, not necessarily the most recent | |
exten => s,n,ExecIf($[${DB_EXISTS(AMPUSER/${AMPUSER}/device)}]?Set(DB(boomerang/${CONNECTEDLINE(number):-10})=${AMPUSER})) | |
exten => s,n,Return |
Rather than AGI, I think you could still keep it all in dialplan but add mysql with timestamps by using func_odbc. A single function in func_odbc with a read query and a write query might be enough.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2021-05-29 very much a work in progress, problems: