Examples dbivrmenu dbcreate js

From FreeSWITCH Wiki
Jump to: navigation, search
 dbivrmenu_dbcreate.js - Database creation script for dbivrmenu.js
 JavaScript Application for FreeSwitch::mod_spidermonkey.
 by Paul Davis (pist @ #freeswitch)
 This application is only meant to be an example of the power and ease of using FreeSwitch.
 This file includes work ripped off from other JavaScript apps created by anthm @ #freeswitch.
 I hope this helps you in starting to use FreeSwitch & JS.
 Note: This application uses CoreDB module to create & populate a sqlite database.
 		This will work with the default dialplan! 
 		**change your dialplan == modify the database**
 		This app works on FS rev 3488.
 Install:  copy this file to your <freeswitch dir>/scripts/
 			execute on console: jsrun dbivrmenu_dbcreate.js
 Disclaimer: Use at your own risk.  No implied warranties or help if/when stuff blows up.
 function mycb(hash)
     console_log("notice", "Adding Menu Option=[" + hash["option"] + "] Route=[" + hash["route"] + "] to the DB\n");
 var db = new CoreDB("dbivrmenudemo");
 var sql;
 var menu_options = new Array();
 var line = "==============================\n";
 /** 3 menu options and an extension for each option **/
 menu_options["1"] = 1000;
 menu_options["2"] = 1234;
 menu_options["3"] = 888;  // you have to uncomment the section for extension 888 for this to work
 /** You could add more fields here to extend this app **/
 db.exec("create table menu_options (option varchar(10), route varchar(120));");
 for (var i in menu_options) {
     sql = "insert into menu_options values('" + i + "', " + menu_options[i] + ");";
 /** Let's see what's in the database, shall we? **/
 sql = "select * from menu_options;";
 console_log("notice", line);
 console_log("notice", "Adding Menu Options to Datab:\n");
 db.exec(sql, "mycb");
 console_log("notice", line);

See Also