{"id":449,"date":"2012-09-02T01:00:00","date_gmt":"2012-09-01T23:00:00","guid":{"rendered":"https:\/\/www.fussylogic.co.uk\/blog\/?p=449"},"modified":"2012-09-27T22:18:44","modified_gmt":"2012-09-27T21:18:44","slug":"asterisk-for-a-small-business-v","status":"publish","type":"post","link":"https:\/\/www.fussylogic.co.uk\/blog\/?p=449","title":{"rendered":"Asterisk For a Small Business (V)"},"content":{"rendered":"<p>Last time we had reached a milestone. Internal calls working, outbound calls working, and incoming calls working.<\/p>\n<p>What next then? It would be nice if people calling our business or residential line got an answering machine when we weren\u00e2\u20ac\u2122t in wouldn\u00e2\u20ac\u2122t it?<\/p>\n<p>There are two dialplan functions needed for voicemail:<\/p>\n<ul>\n<li><code>Voicemail()<\/code> which connects a caller to the recording service \u00e2\u20ac\u201c lets them leave a message.<\/li>\n<li><code>VoicemailMain()<\/code> which connects a caller to the listening service \u00e2\u20ac\u201c lets them listen to their recorded messages.<\/li>\n<\/ul>\n<p>We\u00e2\u20ac\u2122ll begin with a slightly unrelated reorganisation. Recall that we did this to handle external calls:<\/p>\n<pre><code>[external]\nexten =&gt; voiptalkRESIDENTIAL,1,Verbose(1,Incoming call on callbackextension=${EXTEN})\nexten =&gt; voiptalkRESIDENTIAL,n,Dial(SIP\/andyp&amp;SIP\/wife&amp;SIP\/handytone1)\nexten =&gt; voiptalkOFFICE,1,Verbose(1,Incoming call on callbackextension=${EXTEN} from ${CALLERID(all)})\nexten =&gt; voiptalkOFFICE,n,Dial(SIP\/andyp&amp;SIP\/handytone2)<\/code><\/pre>\n<p>That is to say we used <code>Dial()<\/code>. Instead, let\u00e2\u20ac\u2122s make the system slightly more flexible by using Asterisk\u00e2\u20ac\u2122s queue system.<\/p>\n<p>Edit the <code>\/etc\/asterisk\/queues.conf<\/code> file and add a queue for each of our endpoint groups.<\/p>\n<pre><code>[residential]\nstrategy = ringall    \nmember =&gt; SIP\/andyp\nmember =&gt; SIP\/wife\nmember =&gt; SIP\/handytone1\n\n[business]\nstrategy = ringall    \nmember =&gt; SIP\/andyp\nmember =&gt; SIP\/handytone2<\/code><\/pre>\n<p>Then we\u00e2\u20ac\u2122ll alter the <code>[external]<\/code> context to use queue dial.<\/p>\n<pre><code>[external]\nexten =&gt; voiptalkRESIDENTIAL,1,Verbose(1,Incoming call on callbackextension=${EXTEN})\nexten =&gt; voiptalkRESIDENTIAL,n,Queue(residential,cnrtk,,,30)\nexten =&gt; voiptalkOFFICE,1,Verbose(1,Incoming call on callbackextension=${EXTEN} from ${CALLERID(all)})\nexten =&gt; voiptalkOFFICE,n,Queue(business,cnrtk,,,30)<\/code><\/pre>\n<p>This method gives us more flexibility in how we handle queue members coming and going (see the Asterisk documentation for the definitions of the \u00e2\u20ac\u02dccnrtk\u00e2\u20ac\u2122 flags).<\/p>\n<p>Now we add fallback to the voicemail if no one answers:<\/p>\n<pre><code>[external]\nexten =&gt; voiptalkRESIDENTIAL,1,Verbose(1,Incoming call on callbackextension=${EXTEN})\nexten =&gt; voiptalkRESIDENTIAL,n,Queue(residential,cnrtk,,,30)\nexten =&gt; voiptalkRESIDENTIAL,n,Voicemail(household)\nexten =&gt; voiptalkOFFICE,1,Verbose(1,Incoming call on callbackextension=${EXTEN} from ${CALLERID(all)})\nexten =&gt; voiptalkOFFICE,n,Queue(business,cnrtk,,,30)\nexten =&gt; voiptalkOFFICE,n,Voicemail(business)<\/code><\/pre>\n<p>This isn\u00e2\u20ac\u2122t quite sufficient. We have to tell Asterisk the names of the voicemail boxes. Edit <code>\/etc\/asterisk\/voicemail.conf<\/code>.<\/p>\n<pre><code>[default]\nandyp       =&gt; IGNOREPASSWORD,Andy Parkins,andyp@localhost\nwife        =&gt; IGNOREPASSWORD,wife,wife@localhost\nhousehold   =&gt; IGNOREPASSWORD,Residence Voicemail\nbusiness    =&gt; IGNOREPASSWORD,Business Voicemail,business-voicemail@localhost<\/code><\/pre>\n<p>Leaving the <code>andyp<\/code> and <code>wife<\/code> voicemail boxes aside for a moment, we\u00e2\u20ac\u2122ve established a way of leaving messages, but how do we pick them up? First we need to decide what we\u00e2\u20ac\u2122d like.<\/p>\n<ul>\n<li>Dialling the special extension 1571 from <code>handytone1<\/code> gets you to the residential voicemail. (1571 is the BT number for their voicemail service, people already know it so why not leverage that?)<\/li>\n<li>Dialling the special extension 1571 from <code>handytone2<\/code> gets you to the business voicemail.<\/li>\n<\/ul>\n<p>We\u00e2\u20ac\u2122re seasoned users of the dialplan now. This is very straightforward.<\/p>\n<pre><code>[internal-residential]\ninclude =&gt; internal-extensions\nexten =&gt; 1571,1,VoicemailMain(household,s)\nexten =&gt; _0X.,1,Dial(SIP\/voiptalkRESIDENTIAL\/${EXTEN})\n\n[internal-business]    \ninclude =&gt; internal-extensions\nexten =&gt; 1571,1,VoicemailMain(business,s)\nexten =&gt; _0X.,1,Dial(SIP\/voiptalkOFFICE\/${EXTEN})<\/code><\/pre>\n<p>We\u00e2\u20ac\u2122ve simply added the same extension to two contexts, but with different commands when it matches. The \u00e2\u20ac\u2122s\u00e2\u20ac\u2122 flag to <code>VoicemailMain()<\/code> means don\u00e2\u20ac\u2122t ask for a passcode; we don\u00e2\u20ac\u2122t need a passcode as we\u00e2\u20ac\u2122re using the context to establish security. Can we do better though? Yes. Scrap the previous. Recall one of our local extension endpoint definitions.<\/p>\n<pre><code>[handytone1](user,ht386)\n    secret=handytonesecret1\n    callerid=&quot;Residential&quot; &lt;2102&gt;\n    context=internal-residential\n    mailbox=household@default<\/code><\/pre>\n<p>The <code>mailbox<\/code> option also lets us write code that accesses a different mailbox depending on who dialled a common access number. Add the following:<\/p>\n<pre><code>[internal-extensions]\n; Numeric aliases\nexten =&gt; 2100,1,Goto(andyp,1)\nexten =&gt; 2101,1,Goto(wife,1)\nexten =&gt; 2102,1,Goto(handytone1,1)\nexten =&gt; 2103,1,Goto(handytone2,1)\nexten =&gt; 1571,1,Goto(voicemail,1)\n; Named extensions\nexten =&gt; andyp,1,Gosub(stdexten,s,1(SIP\/${EXTEN},${EXTEN}))\nexten =&gt; andyp,hint,SIP\/${EXTEN}\nexten =&gt; wife,1,Gosub(stdexten,s,1(SIP\/${EXTEN},${EXTEN}))\nexten =&gt; wife,hint,SIP\/${EXTEN}\nexten =&gt; handytone1,1,Gosub(stdexten,s,1(SIP\/${EXTEN},${EXTEN}))\nexten =&gt; handytone1,hint,SIP\/${EXTEN}\nexten =&gt; handytone2,1,Gosub(stdexten,s,1(SIP\/${EXTEN},${EXTEN}))\nexten =&gt; handytone2,hint,SIP\/${EXTEN}\n; Special extensions\nexten =&gt; voicemail,1,Ringing\nexten =&gt; voicemail,n,Set(mailbox=${SIPPEER(${CHANNEL(peername)},mailbox)})\nexten =&gt; voicemail,n,GotoIf($[&quot;${mailbox}&quot; = &quot;&quot;]?end)\nexten =&gt; voicemail,n(message),Verbose(1,Transferring ${CALLERID(all)} to ${mailbox} voicemail)\nexten =&gt; voicemail,n,SendText(Connected to ${mailbox} Voicemail)\nexten =&gt; voicemail,n,Wait(2)\nexten =&gt; voicemail,n,Answer\nexten =&gt; voicemail,n,VoicemailMain(${mailbox},s)\nexten =&gt; voicemail,n(end),Hangup<\/code><\/pre>\n<p>This additional named extension, <code>voicemail<\/code>, doesn\u00e2\u20ac\u2122t direct the caller to an endpoint, instead it checks to see if there was an <code>mailbox<\/code> set in <code>sip.conf<\/code> (or any other endpoint device defintion file), then runs <code>VoicemailMain()<\/code> with a mailbox of that name.<\/p>\n<p>The advantage here is that we can specify the voicemail box independently of device name or context. We could now easily point <code>andyp<\/code> at either the <code>andyp<\/code> mailbox or the <code>business<\/code> mailbox, and similarly for any other extensions we add.<\/p>\n<p>One final note, the <code>mailbox<\/code> option in the endpoint definition primarily tells the phone its default mailbox (should it support that facility) to subscribe to for its message waiting indicator (i.e.\u00c2\u00a0a little light on the phone that tells you whether you have new voicemail). The <code>vmexten<\/code> option in the <code>user<\/code> template lets us tell the phone what extension to dial in response to a push of its voicemail button (should it support that facility) \u00e2\u20ac\u201c this would save the user even having to know 1571.<\/p>\n<p><a href=\"?p=441\">asterisk1<\/a> <a href=\"?p=443\">asterisk2<\/a> <a href=\"?p=445\">asterisk3<\/a> <a href=\"?p=447\">asterisk4<\/a> <a href=\"?p=449\">asterisk5<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last time we had reached a milestone. Internal calls working, outbound calls working, and incoming calls working. What next then? It would be nice if people calling our business or residential line got an answering machine when we weren\u00e2\u20ac\u2122t in wouldn\u00e2\u20ac\u2122t it? There are two dialplan functions needed for voicemail: Voicemail() which connects a caller\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.fussylogic.co.uk\/blog\/?p=449\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[31,6],"_links":{"self":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/449"}],"collection":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=449"}],"version-history":[{"count":15,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/449\/revisions"}],"predecessor-version":[{"id":775,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/449\/revisions\/775"}],"wp:attachment":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}