https://wiki.asterisk.org/wiki/display/AST/Hangup+...
[sip]
exten => _X.,1,NoOp(Checking CallerID against blacklist)
same => n,Set(CHANNEL(hangup_handler_push)=hdlr-blacklist,s,1())
same => n,GotoIf($[${DB_EXISTS(blacklist/${CALLERID(num)})}]?go-endcall)
same => n,Set(records=/etc/asterisk/rec/${STRFTIME(${EPOCH},,%H_%M_%d-%m-%Y)}-${CALLERID(number)}-${EXTEN}.wav)
same => n,MixMonitor(${records})
same => n,Dial(SIP/1002,15)
same => n(go-endcall),HangUp()
[hdlr-blacklist]
exten => s,1,Verbose(0, -----hdlr-blacklist-----)
same => n,Verbose(0, CDR BILLSEC is ${CDR(billsec)})
same => n,Verbose(0, CDR disposition is ${CDR(disposition)})
same => n,Set(CALLSTATUS="${CDR(disposition)}")
;same => n,ExecIf($[${CDR(billsec)}>5]?Set(CALLSTATUS="ANSWERED"):Set(CALLSTATUS="NO ANSWERED") ;; можно к времени звонка привязаться
same => n,GotoIf($[${CALLSTATUS}="ANSWERED"]?:go-endcall)
same => n,Verbose(0, CALLSTATUS is ${CALLSTATUS})
same => n,Set(DB(blacklist/${CALLERID(num)})=1)
same => n(go-endcall),Return()