|
A few days ago I was asked to implement a ring group in Asterisk. I thought okay, it's pretty straight forward, I just put all the devices I want to ring in a Dial command and that's it. So I did, but then I was told that that was not entirely ok. They wanted a delay between devices, such that at first only one phone would ring, X seconds later a second device (without the first one stopping) and so on. I thought I could put more Dial commands in a specific order, but then I had the problem that if the first one didn't answer, it would indicate a missed call. So here is how I finally solved it with help of my colleague Bleek. [wait-op] ; Ask if the channel is available, if it is ; go to the next step. If it isn't go to no-op ; and skip the delay. exten = _XX,1,ChanIsAvail(SIP/${EXTEN}) exten = _XX,n,GotoIf($[ "${AVAILCHAN}"="" ]?no-op|s-na|1:3) ; Increment the delay by a value of five. exten = _XX,n,Set(DB(cross/delay-${key})=$[${DB(cross/delay-${key})}+5]) exten = _XX,n,Wait(${DB(cross/delay-${key})}) exten = _XX,n,Dial(SIP/${EXTEN}) [no-op] ; Do nothing exten = s,1,NoOp(Dummy) exten = s-na,1,NoOp(Channel is not available) [hotline-0] ; Define a custom name for the caller ID. ; This was an extra that I did exten = s,1,Set(CALLERID(name)=hotline ${CALLERID(name)} ${CALLERID(num)}) ; Set a key unique for each channel. So id doesn't matter how ; many calls we get, there will always exist just one key per channel ; This way we increase the delay only when we want to. exten = s,n,Set(__key=${CHANNEL}) ; Define the initial delay value on the database. That's even better than ; a global variable. One advantage, pointed out by a collegue of mine, is ; that when the process is over, you can delete the key from the DB. exten = s,n,Set(DB(cross/delay-${key})=-5) ; Set all the devices as a single variable. ; Note that all of them use the "Local" context exten = s,n,Set(dg0=Local/91@wait-op) exten = s,n,Set(dg0=${dg0}&Local/93@wait-op) exten = s,n,Set(dg0=${dg0}&Local/95@wait-op) exten = s,n,Set(dg0=${dg0}&Local/20@wait-op) exten = s,n,Set(dg0=${dg0}&Local/21@wait-op) exten = s,n,Set(dg0=${dg0}&Local/50@wait-op) exten = s,n,Set(dg0=${dg0}&Local/22@wait-op) exten = s,n,Dial(${dg0}|80) ; Manage the voicemail with a macro exten = s,n,Macro(hotline-voicemail|${DIALSTATUS}|0) ; Delete the keys at hangup exten = h,1,NoOp(DB_DELETE(cross/inc-${key}) exten = h,n,Hangup [macro-hotline-voicemail] ; ${ARG1} Dialstatus ; ${ARG2} Whose voicemail? exten = s,1,Set(CHANNEL(language)=de) exten = s,n,Goto(s-${ARG1},1) exten = s-BUSY,1,Voicemail(${ARG2},b) exten = s-NOANSWER,1,Voicemail(${ARG2},u) exten = s-CONGESTION,1,Voicemail(${ARG2},b) exten = s-CHANUNAVAIL,1,Voicemail(${ARG2},u)
I know it's perhaps not the best approach. We didn't want to use queues, because our peers aren't agents, and, though it can be optimised, it works now :) Hope it helps somebody, Happy coding. |