{"id":165,"date":"2010-12-28T00:00:57","date_gmt":"2010-12-28T08:00:57","guid":{"rendered":"http:\/\/4gi.wtf\/wp\/?p=165"},"modified":"2021-12-08T10:17:24","modified_gmt":"2021-12-08T18:17:24","slug":"managing-an-internal-dialtone-with-asterisk","status":"publish","type":"post","link":"https:\/\/looseassociations.com\/?p=165","title":{"rendered":"Managing an Internal Dialtone with asterisk"},"content":{"rendered":"<p>I run an <a href=\"https:\/\/www.asterisk.org\/\" target=\"_blank\" rel=\"noopener\">asterisk PBX<\/a>, largely to handle the complex telephony needs of <a href=\"https:\/\/sacmedoasis.com\/\" target=\"_blank\" rel=\"noopener\">Sacramento Medical Oasis, Inc.<\/a> If you don&#8217;t know what an asterisk PBX is, you can stop reading now and you won&#8217;t miss anything. I promise.<\/p>\n<p><!--more--><\/p>\n<p>I had a pretty simple task that I needed asterisk to perform: give a caller a special dial tone, wait for the caller to key a 10-digit number, stopping the dialtone at the first key press. It&#8217;s something that telephones do every day, and I didn&#8217;t expect it to be any trouble. I found that it wasn&#8217;t quite so easy.<\/p>\n<p>The most logical thing to do was to play a dial tone using Playtones(dial), then WaitExten(). Alas, Playtones() cheerfully continues to play the dialtone throughout all ten key presses &#8212; that&#8217;s non-standard and rather disconcerting.<\/p>\n<p>Of course, BackGround() will play a sound file and stop playing with a keypress, but you&#8217;d have to have a long sound file of a dial tone and make some provision for detecting when the file was finished and either play it again or go to some kind of time-out sequence. Looping the sound file will also cause audio glitches. A cursory search of the net didn&#8217;t turn up any usable dialtone files (my needs are rather specific, though easily handled through playtones). It also seemed like rather a kludge.<\/p>\n<p>My search did turn up a surprising number of asterisk users posting to bulletin boards with the same issue I had. I had assumed that I just missed something pretty basic, but apparently not. The posts all had the same refrain (&#8220;this should be easy &#8212; am I missing something?&#8221;) and none had gotten satisfactory answers.<\/p>\n<p>The most helpful answer referenced the DISA() application. It&#8217;s oh-so-close but, as is often the case with a built-in solution, it lacks the flexibility I need. I suspect that for most of the posters, however, it&#8217;s the best solution.<\/p>\n<p>The answer for me turned out to be pretty simple after all. To wit:<\/p>\n<pre>.\r\n.\r\n.\r\n; play our custom dialtone and wait for keypress\r\nexten =&gt; s,n,playtones(custom_dialtone)\r\nexten =&gt; s,n,waitExten(15)\r\n\r\n; stop the dialtone when we get a keypress\r\n; you could also define single-key escapes here [eg. exten =&gt; #,1,goto(main_loop,s,1)]\r\nexten =&gt; _X,1,stopPlaytones\r\nexten =&gt; _X,n,set(FIRSTDIGIT=${EXTEN})\r\nexten =&gt; _X,n,goto(get_the_rest,s,1)\r\n\r\nexten =&gt; t,1,hangup\r\nexten =&gt; i,1,hangup\r\n\r\n[get_the_rest]\r\nexten =&gt; s,1,waitExten(15)\r\n\r\n; for now we'll just read back the entered ten-digit number and hang up\r\nexten =&gt; _XXXXXXXXX,1,sayDigits(${FIRSTDIGIT}${EXTEN})\r\nexten =&gt; _XXXXXXXXX,n,hangup\r\n\r\nexten =&gt; t,1,hangup\r\nexten =&gt; i,1,hangup\r\n<\/pre>\n<p>Perhaps not trivial, but certainly not too complicated.<\/p>\n<p>&#8211;Ron &#8211; 2010-12-28<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I run an asterisk PBX, largely to handle the complex telephony needs of Sacramento Medical Oasis, Inc. If you don&#8217;t know what an asterisk PBX is, you can stop reading now and you won&#8217;t miss anything. I promise.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-165","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/looseassociations.com\/index.php?rest_route=\/wp\/v2\/posts\/165"}],"collection":[{"href":"https:\/\/looseassociations.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/looseassociations.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/looseassociations.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/looseassociations.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=165"}],"version-history":[{"count":4,"href":"https:\/\/looseassociations.com\/index.php?rest_route=\/wp\/v2\/posts\/165\/revisions"}],"predecessor-version":[{"id":354,"href":"https:\/\/looseassociations.com\/index.php?rest_route=\/wp\/v2\/posts\/165\/revisions\/354"}],"wp:attachment":[{"href":"https:\/\/looseassociations.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/looseassociations.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/looseassociations.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}