Built motion from commit (unavailable).|2.4.1
[motion2.git] / server / services / agi / channel.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x2edb=['setTimeout','headers','emit','ready','line','toLowerCase','hangup','substring','520-Invalid','search','520\x20End\x20of\x20proper','no\x20code','result=','startsWith','length','match','error','E_AGI_SOCKET_ERROR','code','close','E_AGI_SOCKET_CLOSE','timeout','destroy','pipe','command','function','write','inherits','prototype','sendRequest','answer','getData','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','NO\x20MESSAGE','exec','EXEC\x20%s\x20%s','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','setVariable','SET\x20VARIABLE\x20%s\x20\x22%s\x22','toString','replace','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','getVariable','recordFile','wav','BEEP','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','streamFile','STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22','agi','AGI','wait','noop','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','exports','util','events','EventEmitter','./reply','./error','setEncoding','utf8'];(function(_0x74892f,_0x1e981b){var _0x10ee61=function(_0x3c480a){while(--_0x3c480a){_0x74892f['push'](_0x74892f['shift']());}};_0x10ee61(++_0x1e981b);}(_0x2edb,0x16b));var _0xb2ed=function(_0x4cce8,_0x22d1fe){_0x4cce8=_0x4cce8-0x0;var _0x458440=_0x2edb[_0x4cce8];return _0x458440;};'use strict';var util=require(_0xb2ed('0x0'));var _=require('lodash');var EventEmitter=require(_0xb2ed('0x1'))[_0xb2ed('0x2')];var AGIReply=require(_0xb2ed('0x3'));var AGIError=require(_0xb2ed('0x4'));function AGIChannel(_0x51c905){var _0x1f1367=this,_0x4a32f1=new AGIReply(),_0x3710f4=![],_0x52eeb5={};EventEmitter['call'](_0x1f1367);_0x51c905[_0xb2ed('0x5')](_0xb2ed('0x6'));_0x51c905[_0xb2ed('0x7')](0x8*0x3c*0x3c*0x3e8);_0x4a32f1[_0xb2ed('0x5')]('utf8');_0x4a32f1['on'](_0xb2ed('0x8'),function(_0x231613){for(var _0x4ea0d1 in _0x231613){_0x1f1367[_0x4ea0d1]=_0x231613[_0x4ea0d1];}_0x1f1367[_0xb2ed('0x9')](_0xb2ed('0xa'));});_0x4a32f1['on'](_0xb2ed('0xb'),function(_0x357a0b){if(_0x357a0b[_0xb2ed('0xc')]()=='hangup'){_0x1f1367[_0xb2ed('0x9')](_0xb2ed('0xd'));return;}if(_0x357a0b[_0xb2ed('0xe')](0x0,0xb)==_0xb2ed('0xf')){_0x3710f4=!![];}if(_0x3710f4){_0x52eeb5['rx']+=_0x357a0b+'\x0a';if(_0x357a0b[_0xb2ed('0x10')](_0xb2ed('0x11'))!=-0x1){_0x3710f4=![];}}else{_0x52eeb5['rx']=_0x357a0b;}if(_0x3710f4){return;}if(typeof _0x52eeb5['cb']=='function'){var _0x32102e=_0x52eeb5['rx'][_0xb2ed('0xe')](0x0,0x3),_0x4ff145=null,_0x231ff=null;_0x32102e=parseInt(_0x32102e);if(isNaN(_0x32102e)){_0x52eeb5['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xb2ed('0x12')});return;}if(_0x32102e!=0xc8){_0x52eeb5['cb'](null,{'code':_0x32102e,'result':-0x1,'extra':'KO'});return;}_0x4ff145=_0x52eeb5['rx'][_0xb2ed('0xe')](0x4)['replace'](_0xb2ed('0x13'),'');if(_0x4ff145['indexOf']('\x20')!=-0x1){_0x4ff145=_0x4ff145['substr'](0x0,_0x4ff145['indexOf']('\x20'));}if(_[_0xb2ed('0x14')](_0x4ff145,'-1')){_0x4ff145=parseInt(_0x4ff145);}_0x231ff=_0x52eeb5['rx']['split']('\x20');if(_0x231ff[_0xb2ed('0x15')]==0x3){_0x231ff=_0x231ff[0x2][_0xb2ed('0xe')](0x1,_0x231ff[0x2][_0xb2ed('0x15')]-0x1);}else if(_0x231ff[_0xb2ed('0x15')]>0x3){var _0x695f1e=/\((.+)\)/;var _0x2cd53c=_0x52eeb5['rx'][_0xb2ed('0x16')](_0x695f1e);if(_0x2cd53c){_0x231ff=_0x2cd53c[0x1];}else{_0x231ff=null;}}else{_0x231ff=null;}_0x52eeb5['cb'](null,{'code':_0x32102e,'result':_0x4ff145,'extra':_0x231ff});}});_0x51c905['on'](_0xb2ed('0x17'),function(_0x108698){_0x1f1367['emit']('error',new AGIError(_0xb2ed('0x18'),_0x108698[_0xb2ed('0x19')]));});_0x51c905['on'](_0xb2ed('0x1a'),function(){_0x1f1367['emit'](_0xb2ed('0x1a'),new AGIError(_0xb2ed('0x1b')));});_0x51c905['on'](_0xb2ed('0x1c'),function(){_0x1f1367[_0xb2ed('0x9')](_0xb2ed('0x1c'),new AGIError('E_AGI_SOCKET_TIMEOUT'));_0x51c905[_0xb2ed('0x1d')]();});_0x51c905[_0xb2ed('0x1e')](_0x4a32f1);this[_0xb2ed('0x1f')]=function(_0x23de9a,_0x5ae144){var _0x23de9a=_0x23de9a||'',_0x5ae144=typeof _0x5ae144==_0xb2ed('0x20')?_0x5ae144:new Function();_0x52eeb5={'tx':_0x23de9a,'rx':'','cb':_0x5ae144};_0x51c905[_0xb2ed('0x21')](_0x23de9a+'\x0a');},this[_0xb2ed('0x1a')]=function(){_0x51c905[_0xb2ed('0x1d')]();};}util[_0xb2ed('0x22')](AGIChannel,EventEmitter);AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x24')]=function(_0x213b08){return this[_0xb2ed('0x1f')]['sync'](this,_0x213b08);};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x25')]=function(){return this[_0xb2ed('0x24')]('ANSWER');};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x26')]=function(_0x18062e,_0x863dc6,_0x9eec1a){_0x18062e=_0x18062e===undefined?_0xb2ed('0x27'):_0x18062e;_0x863dc6=_0x863dc6===undefined?'5':_0x863dc6;_0x9eec1a=_0x9eec1a===undefined?'1':_0x9eec1a;return this[_0xb2ed('0x24')](util[_0xb2ed('0x28')](_0xb2ed('0x29'),_0x18062e,_0x863dc6*0x3e8,_0x9eec1a));};AGIChannel[_0xb2ed('0x23')]['noop']=function(_0x570b66){_0x570b66=_0x570b66||_0xb2ed('0x2a');return this[_0xb2ed('0x24')](util[_0xb2ed('0x28')]('VERBOSE\x20\x22%s\x22',_0x570b66));};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x2b')]=function(_0xc94b69,_0x1f1877){if(_['isArray'](_0x1f1877)){return this['sendRequest'](util[_0xb2ed('0x28')](_0xb2ed('0x2c'),_0xc94b69,_0x1f1877['join'](',')));}return this[_0xb2ed('0x24')](util[_0xb2ed('0x28')](_0xb2ed('0x2c'),_0xc94b69,_0x1f1877));};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x2d')]=function(_0x460446){return this[_0xb2ed('0x24')](util[_0xb2ed('0x28')](_0xb2ed('0x2e'),_0x460446));};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x2f')]=function(_0x22ee4c){return this[_0xb2ed('0x24')](util[_0xb2ed('0x28')](_0xb2ed('0x30'),_0x22ee4c));};AGIChannel['prototype'][_0xb2ed('0x31')]=function(_0x35542a){return this[_0xb2ed('0x24')](util[_0xb2ed('0x28')](_0xb2ed('0x32'),_0x35542a));};AGIChannel[_0xb2ed('0x23')]['hangup']=function(){return this[_0xb2ed('0x24')]('HANGUP');};AGIChannel['prototype'][_0xb2ed('0x33')]=function(_0x2aafed,_0x1463e2){return this['sendRequest'](util['format'](_0xb2ed('0x34'),_0x2aafed,_0x1463e2?_0x1463e2[_0xb2ed('0x35')]()[_0xb2ed('0x36')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x37')]=function(_0x247167,_0x5d3edb){return this[_0xb2ed('0x24')](util[_0xb2ed('0x28')](_0xb2ed('0x38'),_0x247167,_0x5d3edb));};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x39')]=function(_0x4ccc61,_0x2b17ed){return this[_0xb2ed('0x24')](util[_0xb2ed('0x28')](_0xb2ed('0x3a'),_0x4ccc61,_0x2b17ed));};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x3b')]=function(_0x53a830,_0x304a18){return this['sendRequest'](util['format'](_0xb2ed('0x3c'),_0x53a830,_0x304a18));};AGIChannel[_0xb2ed('0x23')]['continueAt']=function(_0x341dc2,_0x27a15c,_0x338a9d){_0x27a15c=_0x27a15c||this['extension'];_0x338a9d=_0x338a9d||0x1;this[_0xb2ed('0x2d')](_0x341dc2);this['setExtension'](_0x27a15c);this[_0xb2ed('0x31')](_0x338a9d);return this['noop'](util[_0xb2ed('0x28')]('GOTO\x20%s\x20%s\x20%s',_0x341dc2,_0x27a15c,_0x338a9d));};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x3d')]=function(_0x494759){return this[_0xb2ed('0x24')](util[_0xb2ed('0x28')]('GET\x20VARIABLE\x20\x22%s\x22',_0x494759));};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x3e')]=function(_0x422757,_0x50ee16,_0x521421,_0x349565,_0x4ed175,_0x5baa11){_0x50ee16=_0x50ee16||_0xb2ed('0x3f');_0x521421=_0x521421||'';_0x349565=_0x349565===undefined?-0x1:_0x349565==='-1'?-0x1:_0x349565*0x3e8;_0x4ed175=_0x4ed175===undefined?'':'s='+_0x4ed175;_0x5baa11=_0x5baa11?_0xb2ed('0x40'):'';return this[_0xb2ed('0x24')](util[_0xb2ed('0x28')](_0xb2ed('0x41'),_0x422757,_0x50ee16,_0x521421,_0x349565,_0x5baa11,_0x4ed175));};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x42')]=function(_0x530b3a,_0xdc4293){_0xdc4293=_0xdc4293||'';return this[_0xb2ed('0x24')](util['format'](_0xb2ed('0x43'),_0x530b3a,_0xdc4293));};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x44')]=function(_0x5e5835){return this[_0xb2ed('0x2b')](_0xb2ed('0x45'),_0x5e5835);};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x46')]=function(_0x36d77a){return this[_0xb2ed('0x2b')]('WAIT',_0x36d77a);};AGIChannel[_0xb2ed('0x23')][_0xb2ed('0x17')]=function(_0x5853a6,_0x523961){this[_0xb2ed('0x47')](util[_0xb2ed('0x28')](_0xb2ed('0x48'),_0x5853a6['id'],_0x5853a6['label'],_0x523961));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xb2ed('0x49')]=AGIChannel;