3 var _ = require('lodash');
5 var db = require('../../mysqldb').db;
6 var logger = require('../logger')('app');
7 var DBPromise = require('bluebird');
12 appdata: 'CDR(type)=internal'
15 appdata: 'No alias set'
20 appdata: 'demo-echotest',
27 appdata: 'demo-echodone',
34 appdata: 'CDR(type)=internal'
37 appdata: 'No alias set'
42 appdata: 'Support,xX,,,300,,,,,',
50 appdata: 'CDR(type)=internal'
53 appdata: 'No alias set'
58 appdata: 'Sales,xX,,,300,,,,,',
66 appdata: 'CDR(type)=internal'
69 appdata: 'No alias set'
72 appdata: 'agi://127.0.0.1/square,AutoAttendant',
80 appdata: 'CDR(type)=internal'
83 appdata: 'No alias set'
86 appdata: 'agi://127.0.0.1/square,Orders',
94 appdata: 'CDR(type)=internal'
97 appdata: 'No alias set'
100 appdata: 'agi://127.0.0.1/square,CSI',
108 appdata: 'CDR(type)=internal'
111 appdata: 'No alias set'
114 appdata: 'agi://127.0.0.1/square,Survey',
122 appdata: 'CDR(type)=internal'
125 appdata: 'No alias set'
128 appdata: 'agi://127.0.0.1/square,AgentManagement',
134 'xcally-motion-dialer': [{
136 appdata: 'CDR(type)=dialer'
139 appdata: 'CALLERID(all)=${XMD-CALLERID}'
142 appdata: '$["${XMD-AMD}" != "NONE" ]?5:11'
151 appdata: '${XMD-AMDINITIALSILENCE},${XMD-AMDGREETING},${XMD-AMDAFTERGREETINGSILENCE},${XMD-AMDTOTALANALYSISTIME},${XMD-AMDMINWORDLENGTH},${XMD-AMDBETWEENWORDSSILENCE},${XMD-AMDMAXIMUMNUMBEROFWORDS},${XMD-AMDSILENCETHRESHOLD},${XMD-AMDMAXIMUMWORDLENGTH}'
154 appdata: '$["${AMDSTATUS}" == "HUMAN" ]?11:9'
157 appdata: '$["${AMDSTATUS}" == "NOTSURE" ]?11:10'
160 appdata: '$["${AMDSTATUS}" == "MACHINE" ]?14:11'
163 appdata: '$["${XMD-AGI}" != "NONE" ]?AGI(${XMD-AGI})'
166 appdata: '$["${XMD-QUEUE}" != "NONE" ]?QUEUE(${XMD-QUEUE})'
169 appdata: '$["${XMD-AGIAFTER}" != "NONE" ]?AGI(${XMD-AGIAFTER})'
173 'xcally-motion-fax': [{
175 appdata: 'CDR(type)=outbound-fax'
181 appdata: 'FAXOPT(ecm)=${XMF-ECM}'
184 appdata: 'FAXOPT(headerinfo)=${XMF-HEADERINFO}'
187 appdata: 'FAXOPT(localstationid)=${XMF-LOCALSTATIONID}'
190 appdata: 'FAXOPT(maxrate)=${XMF-MAXRATE}'
193 appdata: 'FAXOPT(minrate)=${XMF-MINRATE}'
196 appdata: 'FAXOPT(modem)=${XMF-MODEM}'
199 appdata: 'FAXOPT(t38timeout)=${XMF-T38TIMEOUT}'
202 appdata: '${XMF-PATH},d'
204 'xcally-motion-preview': [{
206 appdata: 'CDR(type)=dialer'
209 appdata: 'CALLERID(all)=${XMD-CALLERID}'
212 appdata: '$["${XMD-AGI}" != "NONE" ]?AGI(${XMD-AGI})'
215 appdata: '${XMD-DIALCHANNEL},${XMD-DIALTIMEOUT},${XMD-DIALOPTIONS},${XMD-DIALURL}'
218 appdata: '$["${XMD-AGIAFTER}" != "NONE" ]?AGI(${XMD-AGIAFTER})'
224 appdata: 'CDR(type)=outbound'
227 appdata: 'No alias set'
230 appdata: 'XCALLY-MOTION-ANSWER=0'
233 appdata: 'XCALLY-MOTION-PROGRESS=0'
236 appdata: 'MONITOR_OPTIONS=ab'
239 outboundrouteid: true
242 appdata: '_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}'
245 appdata: '_XCALLY_MIXMONITOR_FORMAT=wav'
248 appdata: 'demo-congrats',
256 appdata: 'CDR(type)=inbound'
259 appdata: 'No alias set'
264 appdata: 'demo-congrats',
277 var voiceExtensions = [{
281 description: 'echo test demo auto generated'
286 description: 'forward to Support queue auto generated'
291 description: 'forward to Sales queue auto generated'
296 description: 'forward to Auto Attendant IVR auto generated'
301 description: 'forward to Orders IVR auto generated'
306 description: 'forward to CSI IVR auto generated'
311 description: 'forward to Survey IVR auto generated'
316 description: 'forward to Agent Management IVR auto generated'
320 exten: 'xcally-motion-dialer',
321 description: 'dialer extensions auto generated'
325 exten: 'xcally-motion-fax',
326 description: 'fax extensions auto generated'
330 exten: 'xcally-motion-preview',
331 description: 'dialer extensions auto generated'
336 description: 'demo outbound calls auto generated'
339 context: 'from-voip-provider',
341 description: 'catch all inbound calls auto generated'
346 description: 'catch hangup event auto generated'
351 description: 'catch failed event auto generated'
354 var applicationsAlways = {
357 appdata: '${XCALLY_MIXMONITOR_UNIQUEID}.${XCALLY_MIXMONITOR_FORMAT},ab'
361 '_[x][c][a][l][l][y][Q][u][e][u][e][E][x][t][e][n][s][i][o][n].': [{
366 appdata: '${EXTEN:20},xX'
371 var voiceExtensionsAlways = [{
373 context: 'xcally-mixmonitor-context',
378 exten: '_[x][c][a][l][l][y][Q][u][e][u][e][E][x][t][e][n][s][i][o][n].'
381 function createExtensions(voiceExtensions, applications) {
382 return db.VoiceExtension
383 .bulkCreate(voiceExtensions, {
384 ignoreDuplicates: true,
385 individualHooks: true
387 .then(function(entities) {
388 for (var i = 0; i < entities.length; i += 1) {
389 if (applications[entities[i].exten]) {
390 for (var j = 0; j < applications[entities[i].exten].length; j += 1) {
392 // NOTE: only for outbound route with outboundrouteid
393 if (applications[entities[i].exten][j].outboundrouteid) {
394 applications[entities[i].exten][j].appdata = 'outboundrouteid=' + entities[i].id;
395 delete applications[entities[i].exten][j].outboundrouteid;
398 applications[entities[i].exten][j] = _.defaults(applications[entities[i].exten][j], {
401 type: entities[i].type,
402 context: entities[i].context,
403 exten: entities[i].exten,
404 priority: parseInt(entities[i].priority, 10) + 1 + j,
405 description: entities[i].description,
406 VoiceExtensionId: entities[i].id
409 db.VoiceExtension.create(applications[entities[i].exten][j]);
416 logger.info('Voice Extensions have been created');
418 .catch(function(err) {
419 logger.error('Can\'t create Voice Extensions', err);
423 exports.create = function() {
424 createExtensions(voiceExtensions, applications);
427 exports.createAlways = function() {
428 return db.VoiceExtension
431 $or: voiceExtensionsAlways
435 createExtensions(voiceExtensionsAlways, applicationsAlways);
437 .catch(function(err) {
438 logger.error('Can\'t create Voice Extensions', err);