Built motion from commit (unavailable).|2.0.83
[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 _0x20b4=['inherits','prototype','sendRequest','command','sync','answer','ANSWER','getData','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','NO\x20MESSAGE','exec','isArray','join','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','SET\x20VARIABLE\x20%s\x20\x22%s\x22','toString','replace','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','setContext','GOTO\x20%s\x20%s\x20%s','getVariable','GET\x20VARIABLE\x20\x22%s\x22','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','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','events','EventEmitter','./error','call','setEncoding','utf8','setTimeout','headers','emit','ready','line','hangup','520-Invalid','search','520\x20End\x20of\x20proper','substring','no\x20code','result=','indexOf','substr','startsWith','split','length','match','error','code','close','E_AGI_SOCKET_CLOSE','timeout','pipe','destroy'];(function(_0x3b0912,_0x39d739){var _0xa8f339=function(_0x6a31ab){while(--_0x6a31ab){_0x3b0912['push'](_0x3b0912['shift']());}};_0xa8f339(++_0x39d739);}(_0x20b4,0x15d));var _0x420b=function(_0x5a2436,_0x11375a){_0x5a2436=_0x5a2436-0x0;var _0x2d8468=_0x20b4[_0x5a2436];return _0x2d8468;};'use strict';var util=require('util');var _=require('lodash');var EventEmitter=require(_0x420b('0x0'))[_0x420b('0x1')];var AGIReply=require('./reply');var AGIError=require(_0x420b('0x2'));function AGIChannel(_0x304f7d){var _0x80b5f0=this,_0x18d22b=new AGIReply(),_0x1f3df4=![],_0x499148={};EventEmitter[_0x420b('0x3')](_0x80b5f0);_0x304f7d[_0x420b('0x4')](_0x420b('0x5'));_0x304f7d[_0x420b('0x6')](0x8*0x3c*0x3c*0x3e8);_0x18d22b[_0x420b('0x4')]('utf8');_0x18d22b['on'](_0x420b('0x7'),function(_0x2f8ce3){for(var _0x5a328a in _0x2f8ce3){_0x80b5f0[_0x5a328a]=_0x2f8ce3[_0x5a328a];}_0x80b5f0[_0x420b('0x8')](_0x420b('0x9'));});_0x18d22b['on'](_0x420b('0xa'),function(_0x434860){if(_0x434860['toLowerCase']()==_0x420b('0xb')){_0x80b5f0[_0x420b('0x8')]('hangup');return;}if(_0x434860['substring'](0x0,0xb)==_0x420b('0xc')){_0x1f3df4=!![];}if(_0x1f3df4){_0x499148['rx']+=_0x434860+'\x0a';if(_0x434860[_0x420b('0xd')](_0x420b('0xe'))!=-0x1){_0x1f3df4=![];}}else{_0x499148['rx']=_0x434860;}if(_0x1f3df4){return;}if(typeof _0x499148['cb']=='function'){var _0x4826fa=_0x499148['rx'][_0x420b('0xf')](0x0,0x3),_0x17ff56=null,_0x44348a=null;_0x4826fa=parseInt(_0x4826fa);if(isNaN(_0x4826fa)){_0x499148['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x420b('0x10')});return;}if(_0x4826fa!=0xc8){_0x499148['cb'](null,{'code':_0x4826fa,'result':-0x1,'extra':'KO'});return;}_0x17ff56=_0x499148['rx']['substring'](0x4)['replace'](_0x420b('0x11'),'');if(_0x17ff56[_0x420b('0x12')]('\x20')!=-0x1){_0x17ff56=_0x17ff56[_0x420b('0x13')](0x0,_0x17ff56['indexOf']('\x20'));}if(_[_0x420b('0x14')](_0x17ff56,'-1')){_0x17ff56=parseInt(_0x17ff56);}_0x44348a=_0x499148['rx'][_0x420b('0x15')]('\x20');if(_0x44348a['length']==0x3){_0x44348a=_0x44348a[0x2][_0x420b('0xf')](0x1,_0x44348a[0x2][_0x420b('0x16')]-0x1);}else if(_0x44348a['length']>0x3){var _0x3e6fb8=/\((.+)\)/;var _0x49b59e=_0x499148['rx'][_0x420b('0x17')](_0x3e6fb8);if(_0x49b59e){_0x44348a=_0x49b59e[0x1];}else{_0x44348a=null;}}else{_0x44348a=null;}_0x499148['cb'](null,{'code':_0x4826fa,'result':_0x17ff56,'extra':_0x44348a});}});_0x304f7d['on']('error',function(_0x16410a){_0x80b5f0[_0x420b('0x8')](_0x420b('0x18'),new AGIError('E_AGI_SOCKET_ERROR',_0x16410a[_0x420b('0x19')]));});_0x304f7d['on'](_0x420b('0x1a'),function(){_0x80b5f0[_0x420b('0x8')](_0x420b('0x1a'),new AGIError(_0x420b('0x1b')));});_0x304f7d['on'](_0x420b('0x1c'),function(){_0x80b5f0['emit'](_0x420b('0x1c'),new AGIError('E_AGI_SOCKET_TIMEOUT'));_0x304f7d['destroy']();});_0x304f7d[_0x420b('0x1d')](_0x18d22b);this['command']=function(_0x2e5278,_0x1e5540){var _0x2e5278=_0x2e5278||'',_0x1e5540=typeof _0x1e5540=='function'?_0x1e5540:new Function();_0x499148={'tx':_0x2e5278,'rx':'','cb':_0x1e5540};_0x304f7d['write'](_0x2e5278+'\x0a');},this[_0x420b('0x1a')]=function(){_0x304f7d[_0x420b('0x1e')]();};}util[_0x420b('0x1f')](AGIChannel,EventEmitter);AGIChannel[_0x420b('0x20')][_0x420b('0x21')]=function(_0x4223b2){return this[_0x420b('0x22')][_0x420b('0x23')](this,_0x4223b2);};AGIChannel[_0x420b('0x20')][_0x420b('0x24')]=function(){return this[_0x420b('0x21')](_0x420b('0x25'));};AGIChannel[_0x420b('0x20')][_0x420b('0x26')]=function(_0x1fa89e,_0x5e3668,_0x293daf){_0x1fa89e=_0x1fa89e===undefined?_0x420b('0x27'):_0x1fa89e;_0x5e3668=_0x5e3668===undefined?'5':_0x5e3668;_0x293daf=_0x293daf===undefined?'1':_0x293daf;return this[_0x420b('0x21')](util[_0x420b('0x28')](_0x420b('0x29'),_0x1fa89e,_0x5e3668*0x3e8,_0x293daf));};AGIChannel[_0x420b('0x20')][_0x420b('0x2a')]=function(_0x2992dd){_0x2992dd=_0x2992dd||_0x420b('0x2b');return this[_0x420b('0x21')](util['format']('VERBOSE\x20\x22%s\x22',_0x2992dd));};AGIChannel[_0x420b('0x20')][_0x420b('0x2c')]=function(_0x1e3f87,_0x514cd4){if(_[_0x420b('0x2d')](_0x514cd4)){return this[_0x420b('0x21')](util[_0x420b('0x28')]('EXEC\x20%s\x20%s',_0x1e3f87,_0x514cd4[_0x420b('0x2e')](',')));}return this[_0x420b('0x21')](util[_0x420b('0x28')]('EXEC\x20%s\x20%s',_0x1e3f87,_0x514cd4));};AGIChannel['prototype']['setContext']=function(_0x525415){return this[_0x420b('0x21')](util[_0x420b('0x28')](_0x420b('0x2f'),_0x525415));};AGIChannel[_0x420b('0x20')][_0x420b('0x30')]=function(_0x5ea6f9){return this[_0x420b('0x21')](util[_0x420b('0x28')](_0x420b('0x31'),_0x5ea6f9));};AGIChannel[_0x420b('0x20')][_0x420b('0x32')]=function(_0x58e871){return this[_0x420b('0x21')](util[_0x420b('0x28')](_0x420b('0x33'),_0x58e871));};AGIChannel[_0x420b('0x20')][_0x420b('0xb')]=function(){return this[_0x420b('0x21')]('HANGUP');};AGIChannel[_0x420b('0x20')]['setVariable']=function(_0x43c1ec,_0x3f554b){return this[_0x420b('0x21')](util['format'](_0x420b('0x34'),_0x43c1ec,_0x3f554b?_0x3f554b[_0x420b('0x35')]()[_0x420b('0x36')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel['prototype'][_0x420b('0x37')]=function(_0x34e712,_0x5d23f1){return this[_0x420b('0x21')](util[_0x420b('0x28')](_0x420b('0x38'),_0x34e712,_0x5d23f1));};AGIChannel[_0x420b('0x20')][_0x420b('0x39')]=function(_0x1918a9,_0x196efe){return this[_0x420b('0x21')](util['format']('SAY\x20DIGITS\x20%s\x20%s',_0x1918a9,_0x196efe));};AGIChannel[_0x420b('0x20')][_0x420b('0x3a')]=function(_0x3e5a2f,_0x46fd16){return this[_0x420b('0x21')](util[_0x420b('0x28')](_0x420b('0x3b'),_0x3e5a2f,_0x46fd16));};AGIChannel[_0x420b('0x20')][_0x420b('0x3c')]=function(_0x26b242,_0x24bf28,_0x23c8c8){_0x24bf28=_0x24bf28||this[_0x420b('0x3d')];_0x23c8c8=_0x23c8c8||0x1;this[_0x420b('0x3e')](_0x26b242);this['setExtension'](_0x24bf28);this[_0x420b('0x32')](_0x23c8c8);return this[_0x420b('0x2a')](util[_0x420b('0x28')](_0x420b('0x3f'),_0x26b242,_0x24bf28,_0x23c8c8));};AGIChannel[_0x420b('0x20')][_0x420b('0x40')]=function(_0x229a29){return this[_0x420b('0x21')](util[_0x420b('0x28')](_0x420b('0x41'),_0x229a29));};AGIChannel[_0x420b('0x20')]['recordFile']=function(_0x3f6720,_0x31afc2,_0x402d2b,_0x2bee52,_0xd61c15,_0x3c5548){_0x31afc2=_0x31afc2||'wav';_0x402d2b=_0x402d2b||'';_0x2bee52=_0x2bee52===undefined?-0x1:_0x2bee52==='-1'?-0x1:_0x2bee52*0x3e8;_0xd61c15=_0xd61c15===undefined?'':'s='+_0xd61c15;_0x3c5548=_0x3c5548?'BEEP':'';return this[_0x420b('0x21')](util['format'](_0x420b('0x42'),_0x3f6720,_0x31afc2,_0x402d2b,_0x2bee52,_0x3c5548,_0xd61c15));};AGIChannel[_0x420b('0x20')][_0x420b('0x43')]=function(_0x45c7bd,_0x49c677){_0x49c677=_0x49c677||'';return this[_0x420b('0x21')](util['format'](_0x420b('0x44'),_0x45c7bd,_0x49c677));};AGIChannel['prototype'][_0x420b('0x45')]=function(_0x3ef702){return this[_0x420b('0x2c')](_0x420b('0x46'),_0x3ef702);};AGIChannel[_0x420b('0x20')][_0x420b('0x47')]=function(_0x36c466){return this[_0x420b('0x2c')](_0x420b('0x48'),_0x36c466);};AGIChannel['prototype'][_0x420b('0x18')]=function(_0x29fc55,_0x51ac76){this[_0x420b('0x2a')](util['format'](_0x420b('0x49'),_0x29fc55['id'],_0x29fc55[_0x420b('0x4a')],_0x51ac76));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x420b('0x4b')]=AGIChannel;