|
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 colegue Bleek. Asterisk basics -> Delayed Ring Group ; [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)
%3B%0A%5Bwait-op%5D%0A%3B%20Ask%20if%20the%20channel%20is%20available%2C%20if%20it%20is%0A%3B%20go%20to%20the%20next%20step.%20If%20it%20isn%27t%20go%20to%20no-op%0A%3B%20and%20skip%20the%20delay.%0Aexten%20%3D%20_XX%2C1%2CChanIsAvail%28SIP%2F%24%7BEXTEN%7D%29%0Aexten%20%3D%20_XX%2Cn%2CGotoIf%28%24%5B%20%22%24%7BAVAILCHAN%7D%22%3D%22%22%20%5D%3Fno-op%7Cs-na%7C1%3A3%29%0A%3B%20Increment%20the%20delay%20by%20a%20value%20of%20five.%0Aexten%20%3D%20_XX%2Cn%2CSet%28DB%28cross%2Fdelay-%24%7Bkey%7D%29%3D%24%5B%24%7BDB%28cross%2Fdelay-%24%7Bkey%7D%29%7D%2B5%5D%29%0Aexten%20%3D%20_XX%2Cn%2CWait%28%24%7BDB%28cross%2Fdelay-%24%7Bkey%7D%29%7D%29%0Aexten%20%3D%20_XX%2Cn%2CDial%28SIP%2F%24%7BEXTEN%7D%29%0A%0A%5Bno-op%5D%0A%3B%20Do%20nothing%0Aexten%20%3D%20s%2C1%2CNoOp%28Dummy%29%0Aexten%20%3D%20s-na%2C1%2CNoOp%28Channel%20is%20not%20available%29%0A%0A%5Bhotline-0%5D%0A%3B%20Define%20a%20custom%20name%20for%20the%20caller%20ID.%20%0A%3B%20This%20was%20an%20extra%20that%20I%20did%0Aexten%20%3D%20s%2C1%2CSet%28CALLERID%28name%29%3Dhotline%20%24%7BCALLERID%28name%29%7D%20%24%7BCALLERID%28num%29%7D%29%0A%3B%20Set%20a%20key%20unique%20for%20each%20channel.%20So%20id%20doesn%27t%20matter%20how%0A%3B%20many%20calls%20we%20get%2C%20there%20will%20always%20exist%20just%20one%20key%20per%20channel%0A%3B%20This%20way%20we%20increase%20the%20delay%20only%20when%20we%20want%20to.%0Aexten%20%3D%20s%2Cn%2CSet%28__key%3D%24%7BCHANNEL%7D%29%0A%3B%20Define%20the%20initial%20delay%20value%20on%20the%20database.%20That%27s%20even%20better%20than%0A%3B%20a%20global%20variable.%20One%20advantage%2C%20pointed%20out%20by%20a%20collegue%20of%20mine%2C%20is%0A%3B%20that%20when%20the%20process%20is%20over%2C%20you%20can%20delete%20the%20key%20from%20the%20DB.%0Aexten%20%3D%20s%2Cn%2CSet%28DB%28cross%2Fdelay-%24%7Bkey%7D%29%3D-5%29%0A%3B%20Set%20all%20the%20devices%20as%20a%20single%20variable.%0A%3B%20Note%20that%20all%20of%20them%20use%20the%20%22Local%22%20context%0Aexten%20%3D%20s%2Cn%2CSet%28dg0%3DLocal%2F91%40wait-op%29%0Aexten%20%3D%20s%2Cn%2CSet%28dg0%3D%24%7Bdg0%7D%26amp%3BLocal%2F93%40wait-op%29%0Aexten%20%3D%20s%2Cn%2CSet%28dg0%3D%24%7Bdg0%7D%26amp%3BLocal%2F95%40wait-op%29%0Aexten%20%3D%20s%2Cn%2CSet%28dg0%3D%24%7Bdg0%7D%26amp%3BLocal%2F20%40wait-op%29%0Aexten%20%3D%20s%2Cn%2CSet%28dg0%3D%24%7Bdg0%7D%26amp%3BLocal%2F21%40wait-op%29%0Aexten%20%3D%20s%2Cn%2CSet%28dg0%3D%24%7Bdg0%7D%26amp%3BLocal%2F50%40wait-op%29%0Aexten%20%3D%20s%2Cn%2CSet%28dg0%3D%24%7Bdg0%7D%26amp%3BLocal%2F22%40wait-op%29%0Aexten%20%3D%20s%2Cn%2CDial%28%24%7Bdg0%7D%7C80%29%0A%3B%20Manage%20the%20voicemail%20with%20a%20macro%0Aexten%20%3D%20s%2Cn%2CMacro%28hotline-voicemail%7C%24%7BDIALSTATUS%7D%7C0%29%0A%3B%20Delete%20the%20keys%20at%20hangup%0Aexten%20%3D%20h%2C1%2CNoOp%28DB_DELETE%28cross%2Finc-%24%7Bkey%7D%29%0Aexten%20%3D%20h%2Cn%2CHangup%0A%0A%5Bmacro-hotline-voicemail%5D%0A%3B%20%24%7BARG1%7D%20Dialstatus%0A%3B%20%24%7BARG2%7D%20Whose%20voicemail%3F%0Aexten%20%3D%20s%2C1%2CSet%28CHANNEL%28language%29%3Dde%29%0Aexten%20%3D%20s%2Cn%2CGoto%28s-%24%7BARG1%7D%2C1%29%0Aexten%20%3D%20s-BUSY%2C1%2CVoicemail%28%24%7BARG2%7D%2Cb%29%0Aexten%20%3D%20s-NOANSWER%2C1%2CVoicemail%28%24%7BARG2%7D%2Cu%29%0Aexten%20%3D%20s-CONGESTION%2C1%2CVoicemail%28%24%7BARG2%7D%2Cb%29%0Aexten%20%3D%20s-CHANUNAVAIL%2C1%2CVoicemail%28%24%7BARG2%7D%2Cu%29 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. | | No comments for this item |
|
Last Updated ( Friday, 01 August 2008 )
|
|
|
Written by Gurito
|
|
So, I did a fresh install from Asterisk on a server, then configured some SIP users and connected Snom phones for each one of them. Then, as I was testing, I noticed that the "Mail" button on the Snom phones dialed an extension "asterisk". So I couldn't get around dialing the general voicemail extension in order to check my mail. Anyway, there are a few solutions to this problem. One of them is including the option "vmexten" for each user, either in sip.conf or in users.conf. The problem with this approach is that any other user can dial any existing "vmexten" value and, given that he/she knows the password for this voicemail, access the mailbox. So, in order to solve this problem a collegue told me that it was perhaps a good idea to use the "asterisk" extension. Here is how I did it. In the file "extensions.conf" I performed the next changes: Asterisk basics -> Voicemail ; ; *First thing is defining an ew context for the voicemail* [voicemail] exten = asterisk,1,NoOp(This extension takes us to check the voicemail) exten = asterisk,n,NoOp(Caller ID : ${CALLERID(num)}) exten = asterisk,n,NoOp(Channel Type : ${CHANNEL(channeltype)}) exten = asterisk,n,GotoIf($[ "${CHANNEL(channeltype)}" = "SIP" ]?asterisk-sip,1) exten = asterisk,n,GotoIf($[ "${CHANNEL(channeltype)}" = "IAX2" ]?asterisk-iax,1) exten = asterisk-sip,1,NoOp(SIP Name : ${SIPCHANINFO(peername)}) exten = asterisk-sip,n,NoOp(Mailbox : ${SIPPEER(${SIPCHANINFO(peername)}|mailbox)}) exten = asterisk-sip,n,Macro(voicemail-general|${SIPPEER(${SIPCHANINFO(peername)}|mailbox)}) ; *Now, there's no IAXCHANINFO on asterisk 1.2 - 1.4. But it will work if you have an IAX2 client* ; *that supports entering voicemail login info. (like voix phone)* exten = asterisk-iax,1,NoOp(IAX automatic voicemail is not yet supported) exten = asterisk-iax,n,Macro(voicemail-general) ; *Second thing is definig a Voicemail Macro.* ; *Think of this macro as of a function which performs a login for the voicemail.* [macro-voicemail-general] ; ${ARG1} = User's mailbox ; *If the SIP 12 has the mailbox 30, then ${ARG1} = 30.* ; *But don't worry, this parameter is already given by the "asterisk" context previously defined.* ; Set the language for the voicemail message. exten = s,1,Set(CHANNEL(language)=de) exten = s,n,Answer() exten = s,n,GotoIf($[ ${ISNULL(${ARG1})} ]?s-null,1) ; *In my case I had to put this wait in order for the greeting message to play completely.* exten = s,n,Wait(1) exten = s,n,VoiceMailMain(${ARG1}) exten = s,n,Hangup() ; *The extension s-null is called when ${ARG1} is empty* ; *In this case, we call VoiceMailMain withouth parameters and, if the client, say voix phone,* ; *has the voicemail login data configured, it will pass it automatically to asterisk.* ; *It may well be that you don't need the "Wait()" here* exten = s-null,1,Wait(1) exten = s-null,n,VoiceMailMain() exten = s-null,n,Hangup() ; *Finally, I included the "voicemail" context on the default context for my users.* [default] include = voicemail ... -
%3B%0A%3B%20%2AFirst%20thing%20is%20defining%20an%20ew%20context%20for%20the%20voicemail%2A%0A%5Bvoicemail%5D%0Aexten%20%3D%20asterisk%2C1%2CNoOp%28This%20extension%20takes%20us%20to%20check%20the%20voicemail%29%0Aexten%20%3D%20asterisk%2Cn%2CNoOp%28Caller%20ID%20%3A%20%24%7BCALLERID%28num%29%7D%29%0Aexten%20%3D%20asterisk%2Cn%2CNoOp%28Channel%20Type%20%3A%20%24%7BCHANNEL%28channeltype%29%7D%29%0Aexten%20%3D%20asterisk%2Cn%2CGotoIf%28%24%5B%20%22%24%7BCHANNEL%28channeltype%29%7D%22%20%3D%20%22SIP%22%20%5D%3Fasterisk-sip%2C1%29%0Aexten%20%3D%20asterisk%2Cn%2CGotoIf%28%24%5B%20%22%24%7BCHANNEL%28channeltype%29%7D%22%20%3D%20%22IAX2%22%20%5D%3Fasterisk-iax%2C1%29%0Aexten%20%3D%20asterisk-sip%2C1%2CNoOp%28SIP%20Name%20%3A%20%24%7BSIPCHANINFO%28peername%29%7D%29%0Aexten%20%3D%20asterisk-sip%2Cn%2CNoOp%28Mailbox%20%3A%20%24%7BSIPPEER%28%24%7BSIPCHANINFO%28peername%29%7D%7Cmailbox%29%7D%29%0Aexten%20%3D%20asterisk-sip%2Cn%2CMacro%28voicemail-general%7C%24%7BSIPPEER%28%24%7BSIPCHANINFO%28peername%29%7D%7Cmailbox%29%7D%29%0A%3B%20%2ANow%2C%20there%27s%20no%20IAXCHANINFO%20on%20asterisk%201.2%20-%201.4.%20But%20it%20will%20work%20if%20you%20have%20an%20IAX2%20client%2A%0A%3B%20%2Athat%20supports%20entering%20voicemail%20login%20info.%20%28like%20voix%20phone%29%2A%0Aexten%20%3D%20asterisk-iax%2C1%2CNoOp%28IAX%20automatic%20voicemail%20is%20not%20yet%20supported%29%0Aexten%20%3D%20asterisk-iax%2Cn%2CMacro%28voicemail-general%29%0A%0A%0A%3B%20%2ASecond%20thing%20is%20definig%20a%20Voicemail%20Macro.%2A%0A%3B%20%2AThink%20of%20this%20macro%20as%20of%20a%20function%20which%20performs%20a%20login%20for%20the%20voicemail.%2A%0A%5Bmacro-voicemail-general%5D%0A%3B%20%24%7BARG1%7D%20%3D%20User%27s%20mailbox%0A%3B%20%2AIf%20the%20SIP%2012%20has%20the%20mailbox%2030%2C%20then%20%24%7BARG1%7D%20%3D%2030.%2A%0A%3B%20%2ABut%20don%27t%20worry%2C%20this%20parameter%20is%20already%20given%20by%20the%20%22asterisk%22%20context%20previously%20defined.%2A%0A%3B%20Set%20the%20language%20for%20the%20voicemail%20message.%0Aexten%20%3D%20s%2C1%2CSet%28CHANNEL%28language%29%3Dde%29%0Aexten%20%3D%20s%2Cn%2CAnswer%28%29%0Aexten%20%3D%20s%2Cn%2CGotoIf%28%24%5B%20%24%7BISNULL%28%24%7BARG1%7D%29%7D%20%5D%3Fs-null%2C1%29%0A%3B%20%2AIn%20my%20case%20I%20had%20to%20put%20this%20wait%20in%20order%20for%20the%20greeting%20message%20to%20play%20completely.%2A%0Aexten%20%3D%20s%2Cn%2CWait%281%29%0Aexten%20%3D%20s%2Cn%2CVoiceMailMain%28%24%7BARG1%7D%29%0Aexten%20%3D%20s%2Cn%2CHangup%28%29%0A%3B%20%2AThe%20extension%20s-null%20is%20called%20when%20%24%7BARG1%7D%20is%20empty%2A%0A%3B%20%2AIn%20this%20case%2C%20we%20call%20VoiceMailMain%20withouth%20parameters%20and%2C%20if%20the%20client%2C%20say%20voix%20phone%2C%2A%0A%3B%20%2Ahas%20the%20voicemail%20login%20data%20configured%2C%20it%20will%20pass%20it%20automatically%20to%20asterisk.%2A%0A%3B%20%2AIt%20may%20well%20be%20that%20you%20don%27t%20need%20the%20%22Wait%28%29%22%20here%2A%0Aexten%20%3D%20s-null%2C1%2CWait%281%29%0Aexten%20%3D%20s-null%2Cn%2CVoiceMailMain%28%29%20%0Aexten%20%3D%20s-null%2Cn%2CHangup%28%29%0A%0A%0A%3B%20%2AFinally%2C%20I%20included%20the%20%22voicemail%22%20context%20on%20the%20default%20context%20for%20my%20users.%2A%0A%5Bdefault%5D%0Ainclude%20%3D%20voicemail%0A...%0A
So that's it... I hope you find it useful.
Happy coding. :) | | No comments for this item |
|
Last Updated ( Monday, 28 July 2008 )
|
|