[Freeswitch-svn] [commit] r13072 - freeswitch/trunk/scripts/contrib/nmartin/dial_by_name_directory
FreeSWITCH SVN
nmartin at freeswitch.org
Thu Apr 16 21:14:48 PDT 2009
Author: nmartin
Date: Thu Apr 16 23:14:48 2009
New Revision: 13072
Log:
New and improved Dial By Name Directory, includes an actual helpful README, example usage, and a generic phrase macro that uses stock FreeSWITCH IVR prompts. Refactored about 60 lines of code out of the original aadir.js, added comments and debugging.
Added:
freeswitch/trunk/scripts/contrib/nmartin/dial_by_name_directory/
freeswitch/trunk/scripts/contrib/nmartin/dial_by_name_directory/README
freeswitch/trunk/scripts/contrib/nmartin/dial_by_name_directory/dial_by_name_directory.js
freeswitch/trunk/scripts/contrib/nmartin/dial_by_name_directory/dial_by_name_directory.xml
Added: freeswitch/trunk/scripts/contrib/nmartin/dial_by_name_directory/README
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/nmartin/dial_by_name_directory/README Thu Apr 16 23:14:48 2009
@@ -0,0 +1,64 @@
+Dial By Name Directory
+Nik Martin
+For support, contact me at freeswitch at servercorps.com
+
+=======================
+Nostly From the Original Code:
+Original Code Author: John Wehle
+Date: November 6, 2008
+Copyright (c) 2008 Feith Systems and Software, Inc.
+All Rights Reserved
+=======================
+
+
+If the prior author's claimed copyright is infringed by the one I claim we'll
+work it out, BUT I prefer a much looser license:
+==============================================================
+Copyright (c) 2009 Nik Martin
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+The original author of this work, Nik Martin, must be credited
+as the original author of this work.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+
+==============================================================
+
+dial_by_name_directory.xml is a phrase macro for the beginning of the directory app.
+dial_by_name_directory.js is the directory app itself.
+
+Place dial_by_name_directory somewhere in conf/lang/en/ maybe in a folder named directory?
+edit en.xml in conf/lang/en to include the directory/ directory (uh-oh, bad name)
+
+drop dial_by_name_directpry.js in scripts/
+
+in the dial plan, execute the dial by name directpry like:
+
+<extension name="dial_by_name">
+ <condition field="destination_number" expression="^6000$">
+ <action application="javascript" data="dial_by_name_directory.js" />
+ </condition>
+</extension>
+
+or, from an IVR:
+
+<entry action="menu-exec-app" digits="9" param="javascript dial_by_name_directory.js"/>
\ No newline at end of file
Added: freeswitch/trunk/scripts/contrib/nmartin/dial_by_name_directory/dial_by_name_directory.js
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/nmartin/dial_by_name_directory/dial_by_name_directory.js Thu Apr 16 23:14:48 2009
@@ -0,0 +1,209 @@
+/**
+=======================
+Mostly From the Original Code aadir.js:
+Original Code Author: John Wehle
+Date: November 6, 2008
+Copyright (c) 2008 Feith Systems and Software, Inc.
+All Rights Reserved
+=======================
+
+
+If the prior author's claimed copyright is infringed by the one I claim we'll
+work it out, BUT I prefer a much looser MIT license:
+==============================================================
+Copyright (c) 2009 Nik Martin
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+The original author of this work, Nik Martin, must be credited
+as the original author of this work.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+
+==============================================================
+*/
+
+var digitTimeOut = 3000;
+var interDigitTimeOut = 1000;
+var absoluteTimeOut = 10000;
+var base_dir = session.getVariable ("base_dir");
+var domain = session.getVariable ("domain");
+var voicemail_path = base_dir + "/storage/voicemail/default/" + domain + "/";
+var file_exts = [ ".wav", ".mp3" ];
+var extRE = /^1[0-9][0-9][0-9]$/g;
+var operator = "operator";
+var directory;
+
+var translations = [ "0",
+ "QZ", "ABC", "DEF",
+ "GHI", "JKL", "MNO",
+ "PQRS", "TUV", "WXYZ" ];
+var extension = "";
+var dtmf_digits = "";
+
+
+/**
+ * Build an array of [last_namefirst_name,extension].
+ * matches will then start at last name and go until
+ * a unique match emerges:
+ * martinnik and martinmatt match until the a in matt and i in nik
+ *
+ * @return the image at the specified URL
+ */
+
+function build_directory_list() {
+ var i;
+ var name;
+ var number;
+ var dir = apiExecute ("xml_locate", "directory domain name " + domain);
+ var re = /\s+$/g;
+ var length = dir.search (re);
+ if (length == -1)
+ length = dir.length;
+ dir = dir.substring (0, length);
+ var xdir = new XML (dir);
+ directory = new Array ();
+ i = 0;
+ re = /[^A-Z0-9\s]/gi;
+ for each (var variables in xdir.groups.group.users.user.variables) {
+
+ name = "";
+ number = "";
+ for each (variable in variables.variable) {
+ if (variable. at name.toString() == "effective_caller_id_name")
+ name = variable. at value.toString();
+
+ //clean up the name string, letters and numbers only
+ name = name.replace (re, "");
+ if (variable. at name.toString() == "effective_caller_id_number")
+ number = variable. at value.toString();
+ }
+ if (name.length == 0 || number.length == 0 || number.search (extRE) == -1)
+ continue;
+ directory[i] = new Array (2);
+ //make the name look like LastnameFirstname
+ name = name.split(" ")[1] + name.split(" ")[0];
+ directory[i][0] = name;
+ directory[i][1] = number;
+ console_log ("debug", directory[i][0] + ":" + directory[i][1] + "\n");
+ i++;
+ }
+}
+
+function directory_lookup (digits) {
+ var i;
+ var match = "";
+ var pattern = "^";
+ var re;
+ if (digits.length && digits[0] == 0)
+ return 0;
+ for (i = 0; i < digits.length; i++) {
+ if (isNaN (parseInt (digits[i], 10)))
+ return -1;
+ //build a regex pattern to match against
+ pattern += "[" + translations[parseInt (digits[i], 10)] + "]";
+ console_log("debug", "pattern: " + pattern + "\n");
+ }
+ re = new RegExp (pattern, "i");
+ for (i = 0; i < directory.length; i++)
+ if (directory[i][0].search (re) != -1) {
+ if (! isNaN (parseInt (match, 10)))
+ return "";
+ match = directory[i][1];
+ }
+ if (isNaN (parseInt (match, 10)))
+ return -1;
+ return match;
+}
+function on_dtmf (session, type, obj, arg) {
+ if (type == "dtmf") {
+ dtmf_digits += obj.digit;
+ extension = directory_lookup (dtmf_digits)
+ return false;
+ }
+ return true;
+}
+function directory_prompt () {
+ var choice;
+ var index;
+ var repeat;
+ extension = "";
+ choice = "";
+ repeat = 0;
+ while (session.ready() && repeat < 3) {
+ /* play phrase - if digit keyed while playing callback will catch them*/
+ session.sayPhrase ("dial_by_name_directory", "#", "", on_dtmf, "");
+ choice = dtmf_digits;
+ while ( isNaN (parseInt (extension, 10)) ) {
+ if (! session.ready ())
+ return "";
+ dtmf_digits = session.getDigits (1, '#', digitTimeOut,
+ interDigitTimeOut, absoluteTimeOut);
+ choice += dtmf_digits;
+ console_log ("debug", "choice: " + choice + "\n");
+ extension = directory_lookup(choice);
+ }
+ if (parseInt (extension, 10) >= 0)
+ break;
+ session.sayPhrase ("voicemail_invalid_extension", "#", "", on_dtmf, "");
+ dtmf_digits = "";
+ extension = "";
+ choice = "";
+ repeat++;
+ session.flushDigits ();
+ }
+ return extension;
+}
+var choice = "";
+var fd;
+var i;
+var recorded_name;
+session.answer ();
+session.execute("sleep", "1000");
+console_log("info", "loading dial-by-name directory\n");
+build_directory_list();
+dtmf_digits = "";
+session.flushDigits ();
+choice = directory_prompt ();
+
+if (! session.ready ()) {
+ session.hangup();
+ exit();
+}
+
+//this must try to determine if the extension is a number, but it seems that
+//non-integer extension are ok in FS. Leftover from original code
+if ( isNaN (parseInt (choice, 10)) || parseInt (choice, 10) <= 0) {
+ session.execute ("transfer", operator + " XML default");
+ exit();
+}
+
+for (i = 0; i < file_exts.length; i++) {
+ recorded_name = voicemail_path + choice + "/recorded_name" + file_exts[i];
+ fd = new File (recorded_name);
+ if (fd.exists) {
+ session.streamFile (recorded_name);
+ break;
+ }
+}
+session.execute ("phrase", "spell," + choice);
+session.execute ("transfer", choice + " XML features");
+exit();
\ No newline at end of file
Added: freeswitch/trunk/scripts/contrib/nmartin/dial_by_name_directory/dial_by_name_directory.xml
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/nmartin/dial_by_name_directory/dial_by_name_directory.xml Thu Apr 16 23:14:48 2009
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<include><!--This line will be ignored it's here to validate the xml and is optional -->
+
+
+<macro name="dial_by_name_directory">
+ <input pattern="^(.*)$">
+ <match>
+ <action function="play-file" data="ivr/ivr-use_telephone_keypad.wav"/>
+ <!--<action function="say" data="$1" method="pronounced" type="name_spelled"/>-->
+ <action function="play-file" data="ivr/ivr-spell_name.wav"/>
+ <action function="play-file" data="ivr/ivr-last_name_first.wav"/>
+ </match>
+ </input>
+ </macro>
+
+
+
+</include><!--This line will be ignored it's here to validate the xml and is optional -->
More information about the Freeswitch-svn
mailing list