Statistics

Content View Hits : 19205
Asterisk Ring Groups PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Gurito   

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.

  1. [wait-op]
  2. ; Ask if the channel is available, if it is
  3. ; go to the next step. If it isn't go to no-op
  4. ; and skip the delay.
  5. exten = _XX,1,ChanIsAvail(SIP/${EXTEN})
  6. exten = _XX,n,GotoIf($[ "${AVAILCHAN}"="" ]?no-op|s-na|1:3)
  7. ; Increment the delay by a value of five.
  8. exten = _XX,n,Set(DB(cross/delay-${key})=$[${DB(cross/delay-${key})}+5])
  9. exten = _XX,n,Wait(${DB(cross/delay-${key})})
  10. exten = _XX,n,Dial(SIP/${EXTEN})
  11.  
  12. [no-op]
  13. ; Do nothing
  14. exten = s,1,NoOp(Dummy)
  15. exten = s-na,1,NoOp(Channel is not available)
  16.  
  17. [hotline-0]
  18. ; Define a custom name for the caller ID.
  19. ; This was an extra that I did
  20. exten = s,1,Set(CALLERID(name)=hotline ${CALLERID(name)} ${CALLERID(num)})
  21. ; Set a key unique for each channel. So id doesn't matter how
  22. ; many calls we get, there will always exist just one key per channel
  23. ; This way we increase the delay only when we want to.
  24. exten = s,n,Set(__key=${CHANNEL})
  25. ; Define the initial delay value on the database. That's even better than
  26. ; a global variable. One advantage, pointed out by a collegue of mine, is
  27. ; that when the process is over, you can delete the key from the DB.
  28. exten = s,n,Set(DB(cross/delay-${key})=-5)
  29. ; Set all the devices as a single variable.
  30. ; Note that all of them use the "Local" context
  31. exten = s,n,Set(dg0=Local/91@wait-op)
  32. exten = s,n,Set(dg0=${dg0}&Local/93@wait-op)
  33. exten = s,n,Set(dg0=${dg0}&Local/95@wait-op)
  34. exten = s,n,Set(dg0=${dg0}&Local/20@wait-op)
  35. exten = s,n,Set(dg0=${dg0}&Local/21@wait-op)
  36. exten = s,n,Set(dg0=${dg0}&Local/50@wait-op)
  37. exten = s,n,Set(dg0=${dg0}&Local/22@wait-op)
  38. exten = s,n,Dial(${dg0}|80)
  39. ; Manage the voicemail with a macro
  40. exten = s,n,Macro(hotline-voicemail|${DIALSTATUS}|0)
  41. ; Delete the keys at hangup
  42. exten = h,1,NoOp(DB_DELETE(cross/inc-${key})
  43. exten = h,n,Hangup
  44.  
  45. [macro-hotline-voicemail]
  46. ; ${ARG1} Dialstatus
  47. ; ${ARG2} Whose voicemail?
  48. exten = s,1,Set(CHANNEL(language)=de)
  49. exten = s,n,Goto(s-${ARG1},1)
  50. exten = s-BUSY,1,Voicemail(${ARG2},b)
  51. exten = s-NOANSWER,1,Voicemail(${ARG2},u)
  52. exten = s-CONGESTION,1,Voicemail(${ARG2},b)
  53. 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. 

Last Updated on Tuesday, 31 March 2009 14:55