{"id":1536,"date":"2015-10-31T22:58:22","date_gmt":"2015-10-31T22:58:22","guid":{"rendered":"http:\/\/178.62.237.127\/?p=1536"},"modified":"2015-11-04T12:09:11","modified_gmt":"2015-11-04T12:09:11","slug":"post-call-emailing-of-call-recordings-in-freepbx","status":"publish","type":"post","link":"https:\/\/www.cyber-cottage.co.uk\/?p=1536","title":{"rendered":"Post call emailing of Call Recordings in Freepbx"},"content":{"rendered":"<p>In freepbx there is a feature that is quite well hidden but actually does a very useful job.<\/p>\n<p>In The &#8220;Advanced Settings&#8221; page if you enable both &#8220;<label class=\"control-label\" for=\"AS_DISPLAY_READONLY_SETTINGS\">Display Readonly Settings&#8221; and &#8220;Override<label class=\"control-label\" for=\"AS_DISPLAY_READONLY_SETTINGS\">\u00a0Readonly Settings&#8221; Submit and apply you will get some more options, \u00a0one of these is \u00a0&#8220;<\/label><\/label>Post Call Recording Script&#8221; As the name suggests this is a script that run after a recorded call has ended. We created a script called postrecord.sh and in the text field on the menu we have put as below. This emails both inbound and outbound calls.<\/p>\n<p>For calls to and from an extension we can pull the email address from the voicemail.conf and send the email to that address.<\/p>\n<p>Its also set to delete the wav file away after a defined number of days.<\/p>\n<pre>\/usr\/local\/sbin\/postrecord.sh ^{TIMESTR} ^{FROMEXTEN} ^{CALLFILENAME} ^{UNIQUEID} ^{ARG3}<\/pre>\n<p>The Script below will first convert the recording then email it to you or your customer.<\/p>\n<p>A couple of prerequisites are required, these are sox and lame. sox is probably already installed, lame maybe not.<\/p>\n<p>Installing Lame is simple for centos as below.<\/p>\n<pre class=\"p1\"><span class=\"s1\">wget http:\/\/sourceforge.net\/projects\/lame\/files\/lame\/3.99\/lame-3.99.5.tar.gz\u00a0<\/span><span class=\"s1\">tar -zxvf lame-3.99.5.tar.gz\r\n<\/span><span class=\"s1\">cd lame-3.99.5\r\n<\/span><span class=\"s1\">.\/configure\r\n<\/span><span class=\"s1\">make\r\n<\/span><span class=\"s1\">make install<\/span><\/pre>\n<p>The script is fairly simple as below. the main variables are passed to it but we build the directory structure on the fly and file extension is fixed as wav. you can set the file_age variable to delete the wav file messages over that many days old.<\/p>\n<ul>\n<li>Be careful if cutting and pasting this scripty as wordpress may have wrapped some lines<\/li>\n<\/ul>\n<pre class=\"p1\"><span class=\"s1\">#!\/bin\/bash<\/span><\/pre>\n<pre class=\"p1\"><span class=\"s1\">#This script emails the recorded call right after the call is hung up. Below are<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>the variables passed through asterisk\r\n<\/span><span class=\"s1\"># $1 - Time String\r\n<\/span><span class=\"s1\"># $2 - Source\r\n<\/span><span class=\"s1\"># $3 - File\r\n<\/span><span class=\"s1\"># $4 - unique id\r\n<\/span><span class=\"s1\"># $5 - Destination\r\n<\/span><span class=\"s1\"># $dt - Date and Time\r\n<\/span><span class=\"s1\">\/bin\/nice \/bin\/sleep 3\r\n<\/span><span class=\"s1\">dy=$(date '+%Y')\r\n<\/span><span class=\"s1\">dm=$(date '+%m')\r\n<\/span><span class=\"s1\">dd=$(date '+%d')\r\n<\/span><span class=\"s1\">file_age=35\r\n\r\n<\/span><span class=\"s1\">dtpath=\/var\/spool\/asterisk\/monitor\/$dy\/$dm\/$dd\/\r\n<\/span><span class=\"s1\">\/bin\/nice \/usr\/local\/bin\/lame -b 16 -m m -q 9-resample $dtpath$3.wav<span class=\"Apple-converted-space\">\u00a0 <\/span>$dtpath$3.mp3\r\n<\/span><span class=\"s1\">\/bin\/nice \/bin\/chown<span class=\"Apple-converted-space\">\u00a0 <\/span>asterisk:asterisk $dtpath$3.mp3\r\n<\/span><span class=\"s1\">dt=$(date '+%m\/%d\/%Y %r');\r\n<\/span><span class=\"s1\">id=$(mysql -uUser -pPassword -s -N -e \"SELECT descr from asterisk.queues_config where extension = $5\");\r\n<\/span><span class=\"s1\">\r\nemail=recordings@yourdomain.com\r\n<\/span><span class=\"s1\">\r\nfile=$dtpath$3\r\n<\/span><span class=\"s1\">\r\nif [ \"$id\" = \"\" ]; then\r\n<\/span><span class=\"s1\"> <span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>direction=callers \r\n<\/span><span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>id=$(mysql -uUser -pPassword -s -N -e \"SELECT name from asterisk.users where extension = $2\");\r\n<\/span><span class=\"s1\">\r\n  IN=$(\/bin\/grep \"$2 =&gt;\" \/etc\/asterisk\/voicemail.conf)\r\n<\/span><span class=\"s1\">              echo $IN\r\n<\/span><span class=\"s1\"><span class=\"Apple-converted-space\"> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>set -- \"$IN\"\r\n<\/span><span class=\"s1\"><span class=\"Apple-converted-space\">             \u00a0 <\/span>IFS=\",\"; declare -a Array=($*)\r\n<\/span><span class=\"s1\">               email=${Array[2]}\r\n<\/span><span class=\"s1\"><span class=\"Apple-converted-space\">\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>else\r\n<\/span><span class=\"s1\"><span class=\"Apple-converted-space\">\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>direction=customers <span class=\"Apple-converted-space\">\u00a0 \u00a0\r\n<\/span><\/span><span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>fi\r\n<\/span><span class=\"s1\">\r\necho -e \"You have a new call recording to listen to\\n\\n\r\n<\/span><span class=\"s1\"> The call date and time was: $dat \\n\\n \r\n<\/span><span class=\"s1\"> The call was from: $2 \\n\\n<\/span><span class=\"s1\"> The call was to: $5 \\n\\n\r\n<\/span><span class=\"s1\"> The $direction name was: $id \\n\\n\r\n<\/span><span class=\"s1\"> And the unique call id was: $4 \\n\\n\r\n<\/span><span class=\"s1\"> Please see the attached file \\n\\n\" | mail -a $file.mp3 -s \"New Recording at $dt\" $email \r\n<\/span><span class=\"s1\">\r\n\/bin\/nice \/usr\/bin\/find \/var\/spool\/asterisk\/monitor\/<span class=\"Apple-converted-space\">\u00a0 <\/span>-type f -mtime +\"$file_age\" |grep wav | \\\r\n<\/span><span class=\"s1\">while read I; do\r\n<\/span><span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>\/bin\/rm<span class=\"Apple-converted-space\">\u00a0 <\/span>\"$I\"\r\n<\/span><span class=\"s1\">done<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In freepbx there is a feature that is quite well hidden but actually does a very useful job. In The &#8220;Advanced Settings&#8221; page if you enable both &#8220;Display Readonly Settings&#8221; and &#8220;Override\u00a0Readonly Settings&#8221; Submit and apply you will get some more options, \u00a0one of these is \u00a0&#8220;Post Call Recording Script&#8221; As the name suggests this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1425,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[104,11],"tags":[105,23,30,33,40,69,100,76],"class_list":["post-1536","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-freepbx","category-knowledge","tag-as","tag-asterisk","tag-crm","tag-digium","tag-freepbx","tag-sip","tag-technical","tag-voip"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.cyber-cottage.co.uk\/wp-content\/uploads\/2014\/11\/dial-5465e6b4_site_icon.png?fit=512%2C512&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p5daZy-oM","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1536"}],"version-history":[{"count":4,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1536\/revisions"}],"predecessor-version":[{"id":1540,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1536\/revisions\/1540"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/media\/1425"}],"wp:attachment":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}