{"id":896,"date":"2020-03-08T09:36:07","date_gmt":"2020-03-08T14:36:07","guid":{"rendered":"http:\/\/zewwy.ca\/?p=896"},"modified":"2020-08-07T10:42:14","modified_gmt":"2020-08-07T15:42:14","slug":"freeswitch-ivrs-and-fun-stuff","status":"publish","type":"post","link":"https:\/\/zewwy.ca\/index.php\/2020\/03\/08\/freeswitch-ivrs-and-fun-stuff\/","title":{"rendered":"FreeSWITCH &#8211; IVRs and Fun Stuff"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/nCXu7I3.png\" \/><\/p>\n<p>In my previous post I covered how to setup FreeSWITCH behind a PAN firewall, connect with a gateway (the ITSP) and configure a very basic default and public dialplans to get simple inbound and bound calls working.<\/p>\n<p>For the best reading I <a href=\"https:\/\/books.google.ca\/books?id=uISv9J6wt88C\">suggest this book<\/a>. \ud83d\ude42<\/p>\n<h1 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"FreeSwitch\"><\/span>FreeSwitch<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"IVRs\"><\/span>IVRs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The path when working with IVRs is:<\/p>\n<pre><span style=\"font-weight: 400;\">\/etc\/freeswitch\/ivr_menus\/<\/span><\/pre>\n<p>inside we can see the following:<\/p>\n<pre>root@FreeSwitch:~# ls \/etc\/freeswitch\/ivr_menus\/\r\ndemo_ivr.xml  my_ivr.xml  new_demo_ivr.xml<\/pre>\n<p>not a whole lot. First thing I wanted to figure out was how calling ext 5000 would lead to this IVR.<\/p>\n<p>So looking at the default internal dial-plan, we can see it<\/p>\n<pre>nano \/etc\/freeswitch\/dialplan\/default.xml<\/pre>\n<pre>    &lt;!-- a sample IVR  --&gt;\r\n    &lt;extension name=\"ivr_demo\"&gt;\r\n      &lt;condition field=\"destination_number\" expression=\"^5000$\"&gt;\r\n        &lt;action application=\"answer\"\/&gt;\r\n        &lt;action application=\"sleep\" data=\"2000\"\/&gt;\r\n        &lt;action application=\"ivr\" data=\"demo_ivr\"\/&gt;\r\n      &lt;\/condition&gt;\r\n    &lt;\/extension&gt;\r\n\r\n<\/pre>\n<p>Looks like it&#8217;s the application IVR data=demo_ivr. Quick way to find out let&#8217;s rename the file and see if the dialplan still works..ok, it&#8217;s not the filename, but the name value in the xml files located within the folder specified above.<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/JojPgmf.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/JojPgmf.png\" alt=\"\" width=\"1131\" height=\"742\" \/><\/a><\/p>\n<p>Now as you can see I managed to get the screaming monkeys to work by simply recording a stream of screaming monkeys and exporting it with audacity in compressed ULaw wav format, uploaded it to freeSWITCH via WinSCP. then changed the action type and param value.<\/p>\n<p>Now if you get into the nitty gritty, you&#8217;ll notice the default IVR uses phrases which are pieced together pieces of smaller recordings. These you may notice by default are also relatively referenced, instead of fully &#8220;ivr\/ivr-that-was-invalid-entry.wav&#8221; which you may notice from searching exists only in the language folders of the sounds&#8230;<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/Y6QsfZS.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/Y6QsfZS.png\" alt=\"\" width=\"762\" height=\"486\" \/><\/a><\/p>\n<p>for the time being I won&#8217;t get into making that custom of an IVR, instead start off simple. I&#8217;m gonna create an audio recording of my options (1 for sales, 2 for work, 3 for support, 4 for other). Then used WinSCP to copy to the Freeswitch server, then copied to location.<\/p>\n<pre>root@FreeSwitch:\/etc\/freeswitch\/ivr_menus# cp \/home\/zewwy\/ZewwyCA.wav \/usr\/share\/freeswitch\/sounds\/\r\nroot@FreeSwitch:\/etc\/freeswitch\/ivr_menus# ls \/usr\/share\/freeswitch\/sounds\/\r\nen  es  fr  music  pt  ru  ScreamingMonkey.wav  ZewwyCA.wav\r\n\r\n<\/pre>\n<p>ok now, let&#8217;s make the IVR do stuff with these options&#8230;.<\/p>\n<p>first we&#8217;ll set the caller ID name and number in vars.xml so we can use the default variables in our directories, and hopefully for outbound calls.<\/p>\n<p>So with my recording in place, i created my IVR as follows:<\/p>\n<pre>nano \/etc\/freeswitch\/ivr_menus\/zewwy_ivr.xml<\/pre>\n<p><a href=\"https:\/\/i.imgur.com\/PQ3sOVj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/PQ3sOVj.png\" alt=\"\" width=\"1163\" height=\"433\" \/><\/a><\/p>\n<p>then created a new extension to reach in my default dialplan<\/p>\n<pre>nano \/etc\/freeswitch\/dialplan\/default.xml<\/pre>\n<p><a href=\"https:\/\/i.imgur.com\/ETG0tl8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/ETG0tl8.png\" alt=\"\" width=\"560\" height=\"129\" \/><\/a><\/p>\n<p>Now I just need to change my public dialplan to call this extension instead of my SPAPhone directly.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/j3Tlavt.png\" \/><\/p>\n<p>Change 1002 to 5006. That&#8217;s it. \ud83d\ude00 now got a IVR.<\/p>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"Time_of_Day_Call_Routing\"><\/span>Time of Day Call Routing<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>I used <a href=\"https:\/\/freeswitch.org\/confluence\/display\/FREESWITCH\/Time+of+Day+and+Holiday+Routing\">FreeSwitch&#8217;s own post on this as a reference<\/a>.<\/p>\n<p>For me, I created option one in the options for &#8220;Sales&#8221;. I don&#8217;t want to be bothered about items for sales when I&#8217;m sleeping, or off work. Currently as above you can see calls are going straight to my voice mail. Well let&#8217;s change that&#8230;<\/p>\n<pre>&lt;!-- My Cell --&gt;\r\n&lt;extension name=\"mycell\"&gt;\r\n  &lt;condition field=\"destination_number\" expression=\"^mycell$\"&gt;\r\n    &lt;action application=\"bridge\" data=\"sofia\/gateway\/${default_gateway}\/1#######\"\/&gt;\r\n  &lt;\/condition&gt;\r\n&lt;\/extension&gt;<\/pre>\n<p>First, let&#8217;s create a new extension for Sales; 2222: in default dialplan<\/p>\n<pre>&lt;extension name=\"Sales-x2222\"&gt;\r\n  &lt;condition field=\"destination_number\" expression=\"^2222$\"&gt;\r\n    &lt;action application=\"transfer\" data=\"Sales\"\/&gt;\r\n  &lt;\/condition&gt;\r\n&lt;\/extension&gt;<\/pre>\n<p>just below that:<\/p>\n<pre>&lt;extension name=\"Sales\" continue=\"true\"&gt;\r\n&lt;condition field=\"destination_number\" expression=\"^Sales$\"\/&gt;\r\n  &lt;condition wday=\"2-6\" hour=\"9-18\"&gt;\r\n    &lt;action application=\"set\" data=\"Sales_open=true\"\/&gt;\r\n    &lt;action application=\"transfer\" data=\"xfer-to-sales\"\/&gt;    \r\n    &lt;anti-action application=\"set\" data=\"Sales_open=false\"\/&gt;\r\n    &lt;anti-action application=\"transfer\" data=\"xfer-to-sales\"\/&gt;\r\n  &lt;\/condition&gt;\r\n&lt;\/extension&gt;<\/pre>\n<pre>&lt;extension name=\"xfer-to-sales\"&gt;\r\n  &lt;condition field=\"destination_number\" expression=\"^xfer-to-sales$\"\/&gt;\r\n  &lt;condition field=\"${Sales_open}\" expression=\"^true$\"&gt;\r\n    &lt;action application=\"transfer\" data=\"mycell\"\/&gt;\r\n    &lt;action application=\"answer\"\/&gt;\r\n    &lt;action application=\"sleep\" data=\"2000\"\/&gt;\r\n    &lt;action application=\"voicemail\" data=\"default ${domain_name} 1002\"\/&gt;\r\n<span style=\"font-size: 1rem;\">    &lt;anti-action application=\"voicemail\" data=\"default ${domain_name} 1002\"\/&gt;\r\n<\/span><span style=\"font-size: 1rem;\">  &lt;\/condition&gt;\r\n<\/span>&lt;\/extension&gt;<\/pre>\n<p>If you can&#8217;t tell what is happening here, we are creating a dial number named Sales-x2222 when you dial 2222. Then we define the sales work hours Weekdays from 9 till 6, which defines the normal action lines, in this case it sets a variable &#8220;Sales_open&#8221; to true, otherwise if not within this time, set the variable to false. In the third area we use this flag to either call mycell or leave a voicemail on ext 1002.<\/p>\n<p>Now I simply changed the first line in my IVR instead of bridging a call to my cell, I send it to ext 2222 which will only call my cell during working hours. \ud83d\ude42<\/p>\n<p>*NOTE* I could have also simply done this directly under the Public based dialplan such as this:<\/p>\n<pre>&lt;include&gt;\r\n\t&lt;expression name=\"public_did\"&gt;\r\n\t\t&lt;condition field=\"destination_number\" expression=\"1#######$\"&gt;\r\n\t\t\t&lt;action application=\"answer\"\/&gt;\r\n\t\t\t&lt;condition wday=\"2-6\" hour=\"9-18\"&gt;\r\n\t\t\t\t&lt;action application=\"transfer\" data=\"callfwd\"&gt;\r\n\t\t\t\t&lt;anti-action application=\"ivr\" data=\"zewwy_ivr\"&gt;\r\n\t\t\t&lt;\/condition&gt;\r\n\t\t&lt;\/condition&gt;\r\n\t&lt;\/expression&gt;\r\n\t&lt;expression name=\"callfwd\"&gt;\r\n\t\t&lt;condition field=\"destination_number\" expression=\"^callfwd$\"&gt;\r\n\t\t\t&lt;action application=\"answer\"\/&gt;\r\n\t\t\t&lt;action application=\"speak\" data=\"flite|rms|Calling someone in reguards to a item for sale. Hold please.\"\/&gt;\r\n\t\t\t&lt;action application=\"set\" data=\"effective_caller_id_name=SALE(${caller_id_name})\"\/&gt;\r\n\t\t\t&lt;action application=\"set\" data=\"effective_caller_id_number=${caller_id_number}\"\/&gt;\r\n\t\t\t&lt;action application=\"bridge\" data=\"sofia\/gateway\/${default_gateway}\/1#######\"\/&gt;\r\n\t\t&lt;\/condition&gt;\r\n\t&lt;\/expression&gt;\r\n&lt;\/include&gt;<\/pre>\n<p>However I wanted my IVR to stay the same no matter when it was called. So I placed my time of day routing at the internal dial-plan on the specific use case\/department. It was simply a more scalable example to use.<\/p>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"Blast_Group\"><\/span>Blast Group<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>here&#8217;s an example of a 2 phone blast group via ext 511 using the default dial plan, blasting ext&#8217;s 1002 and 1003<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/4Vc7B6B.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/4Vc7B6B.png\" alt=\"\" width=\"753\" height=\"135\" \/><\/a><\/p>\n<p>this took me a bit&#8230;<\/p>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"Hunt_Group\"><\/span>Hunt Group<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>ext 512 dials Ext 1001, if not available call 1002 (ring only for 20 second), if not available ring ext 1003 (for 30 seconds), if no answer drop to 1002&#8217;s voice mailbox.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/gNwiTFc.png\" \/><\/p>\n<p>some Music on Hold would be nice while the call is being transferred&#8230;<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/XyTR8yu.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/XyTR8yu.png\" alt=\"\" width=\"795\" height=\"403\" \/><\/a><\/p>\n<pre>    &lt;extension name=\"a_blast_group\"&gt;\r\n      &lt;condition field=\"destination_number\" expression=\"^511$\"&gt;\r\n        &lt;action application=\"set\" data=\"ringback=${us-ring}\"\/&gt;\r\n        &lt;action application=\"set\" data=\"transfer_ringback=$${hold_music}\"\/&gt;\r\n        &lt;action application=\"answer\"\/&gt;\r\n        &lt;action application=\"sleep\" data=\"2000\"\/&gt;\r\n        &lt;action application=\"bridge\" data=\"sofia\/$${domain}\/1002,sofia\/$${domain}\/1003\"\/&gt;\r\n      &lt;\/condition&gt;\r\n    &lt;\/extension&gt;\r\n\r\n    &lt;extension name=\"a_hunt_group\"&gt;\r\n      &lt;condition field=\"destination_number\" expression=\"^512$\"&gt;\r\n        &lt;action application=\"set\" data=\"ringback=${us-ring}\"\/&gt;\r\n        &lt;action application=\"set\" data=\"transfer_ringback=$${hold_music}\"\/&gt;\r\n        &lt;action application=\"answer\"\/&gt;\r\n        &lt;action application=\"sleep\" data=\"2000\"\/&gt;\r\n        &lt;action application=\"set\" data=\"continue_on_fail=true\"\/&gt;\r\n        &lt;action application=\"set\" data=\"call_timeout=20\"\/&gt;\r\n        &lt;action application=\"bridge\" data=\"sofia\/$${domain}\/1001|sofia\/$${domain}\/1002\"\/&gt;\r\n        &lt;action application=\"set\" data=\"call_timeout=30\"\/&gt;\r\n        &lt;action application=\"bridge\" data=\"sofia\/$${domain}\/1003\"\/&gt;\r\n        &lt;action application=\"voicemail\" data=\"default ${domain_name} 1002\"\/&gt;\r\n      &lt;\/condition&gt;\r\n    &lt;\/extension&gt;<\/pre>\n<p>Hope someone found this guide useful. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my previous post I covered how to setup FreeSWITCH behind a PAN firewall, connect with a gateway (the ITSP) and configure a very basic default and public dialplans to get simple inbound and bound calls working. For the best reading I suggest this book. \ud83d\ude42 FreeSwitch IVRs The path when working with IVRs is: &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/zewwy.ca\/index.php\/2020\/03\/08\/freeswitch-ivrs-and-fun-stuff\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;FreeSWITCH &#8211; IVRs and Fun Stuff&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"sfsi_plus_gutenberg_text_before_share":"","sfsi_plus_gutenberg_show_text_before_share":"","sfsi_plus_gutenberg_icon_type":"","sfsi_plus_gutenberg_icon_alignemt":"","sfsi_plus_gutenburg_max_per_row":"","footnotes":""},"categories":[8,285],"tags":[283,286],"class_list":["post-896","post","type-post","status-publish","format-standard","hentry","category-server-administration","category-voip","tag-freeswitch","tag-ivr"],"_links":{"self":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/comments?post=896"}],"version-history":[{"count":8,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/896\/revisions"}],"predecessor-version":[{"id":952,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/896\/revisions\/952"}],"wp:attachment":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/media?parent=896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/categories?post=896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/tags?post=896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}