66b4fe59ef22bdefd248a85f362239e2cbf2eb2e
[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 _0x2c6f=['setEncoding','utf8','setTimeout','headers','emit','ready','toLowerCase','hangup','520-Invalid','search','520\x20End\x20of\x20proper','function','substring','replace','result=','indexOf','substr','startsWith','split','length','error','E_AGI_SOCKET_ERROR','code','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','pipe','command','write','prototype','sendRequest','sync','answer','ANSWER','getData','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','isArray','EXEC\x20%s\x20%s','join','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','HANGUP','setVariable','isNumber','SET\x20VARIABLE\x20%s\x20\x22%s\x22','toString','sayNumber','SAY\x20NUMBER\x20%s\x20%s','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','continueAt','extension','GOTO\x20%s\x20%s\x20%s','getVariable','wav','BEEP','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','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','util','lodash','events','./error'];(function(_0x3cb392,_0x56515b){var _0x4e0163=function(_0x28a8ab){while(--_0x28a8ab){_0x3cb392['push'](_0x3cb392['shift']());}};_0x4e0163(++_0x56515b);}(_0x2c6f,0x138));var _0xf2c6=function(_0x3cb61c,_0x559bd2){_0x3cb61c=_0x3cb61c-0x0;var _0x1015e1=_0x2c6f[_0x3cb61c];return _0x1015e1;};'use strict';var util=require(_0xf2c6('0x0'));var _=require(_0xf2c6('0x1'));var EventEmitter=require(_0xf2c6('0x2'))['EventEmitter'];var AGIReply=require('./reply');var AGIError=require(_0xf2c6('0x3'));function AGIChannel(_0x55ec37){var _0x59ed4d=this,_0x46e156=new AGIReply(),_0x30e041=![],_0x1208b3={};EventEmitter['call'](_0x59ed4d);_0x55ec37[_0xf2c6('0x4')](_0xf2c6('0x5'));_0x55ec37[_0xf2c6('0x6')](0x8*0x3c*0x3c*0x3e8);_0x46e156[_0xf2c6('0x4')]('utf8');_0x46e156['on'](_0xf2c6('0x7'),function(_0x573a7d){for(var _0x296a14 in _0x573a7d){_0x59ed4d[_0x296a14]=_0x573a7d[_0x296a14];}_0x59ed4d[_0xf2c6('0x8')](_0xf2c6('0x9'));});_0x46e156['on']('line',function(_0x1ea5c6){if(_0x1ea5c6[_0xf2c6('0xa')]()==_0xf2c6('0xb')){_0x59ed4d[_0xf2c6('0x8')](_0xf2c6('0xb'));return;}if(_0x1ea5c6['substring'](0x0,0xb)==_0xf2c6('0xc')){_0x30e041=!![];}if(_0x30e041){_0x1208b3['rx']+=_0x1ea5c6+'\x0a';if(_0x1ea5c6[_0xf2c6('0xd')](_0xf2c6('0xe'))!=-0x1){_0x30e041=![];}}else{_0x1208b3['rx']=_0x1ea5c6;}if(_0x30e041){return;}if(typeof _0x1208b3['cb']==_0xf2c6('0xf')){var _0x2b5236=_0x1208b3['rx'][_0xf2c6('0x10')](0x0,0x3),_0x3dff21=null,_0x2aee72=null;_0x2b5236=parseInt(_0x2b5236);if(isNaN(_0x2b5236)){_0x1208b3['cb'](null,{'code':0x1f4,'result':-0x1,'extra':'no\x20code'});return;}if(_0x2b5236!=0xc8){_0x1208b3['cb'](null,{'code':_0x2b5236,'result':-0x1,'extra':'KO'});return;}_0x3dff21=_0x1208b3['rx'][_0xf2c6('0x10')](0x4)[_0xf2c6('0x11')](_0xf2c6('0x12'),'');if(_0x3dff21[_0xf2c6('0x13')]('\x20')!=-0x1){_0x3dff21=_0x3dff21[_0xf2c6('0x14')](0x0,_0x3dff21[_0xf2c6('0x13')]('\x20'));}if(_[_0xf2c6('0x15')](_0x3dff21,'-1')){_0x3dff21=parseInt(_0x3dff21);}_0x2aee72=_0x1208b3['rx'][_0xf2c6('0x16')]('\x20');if(_0x2aee72[_0xf2c6('0x17')]==0x3){_0x2aee72=_0x2aee72[0x2][_0xf2c6('0x10')](0x1,_0x2aee72[0x2]['length']-0x1);}else if(_0x2aee72[_0xf2c6('0x17')]>0x3){var _0x24dfca=/\((.+)\)/;var _0x2dc695=_0x1208b3['rx']['match'](_0x24dfca);if(_0x2dc695){_0x2aee72=_0x2dc695[0x1];}else{_0x2aee72=null;}}else{_0x2aee72=null;}_0x1208b3['cb'](null,{'code':_0x2b5236,'result':_0x3dff21,'extra':_0x2aee72});}});_0x55ec37['on'](_0xf2c6('0x18'),function(_0x27253c){_0x59ed4d['emit'](_0xf2c6('0x18'),new AGIError(_0xf2c6('0x19'),_0x27253c[_0xf2c6('0x1a')]));});_0x55ec37['on']('close',function(){_0x59ed4d[_0xf2c6('0x8')](_0xf2c6('0x1b'),new AGIError(_0xf2c6('0x1c')));});_0x55ec37['on'](_0xf2c6('0x1d'),function(){_0x59ed4d[_0xf2c6('0x8')](_0xf2c6('0x1d'),new AGIError(_0xf2c6('0x1e')));_0x55ec37['destroy']();});_0x55ec37[_0xf2c6('0x1f')](_0x46e156);this[_0xf2c6('0x20')]=function(_0x49b055,_0x54c0eb){var _0x49b055=_0x49b055||'',_0x54c0eb=typeof _0x54c0eb==_0xf2c6('0xf')?_0x54c0eb:new Function();_0x1208b3={'tx':_0x49b055,'rx':'','cb':_0x54c0eb};_0x55ec37[_0xf2c6('0x21')](_0x49b055+'\x0a');},this[_0xf2c6('0x1b')]=function(){_0x55ec37['destroy']();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x23')]=function(_0x1d1db2){return this[_0xf2c6('0x20')][_0xf2c6('0x24')](this,_0x1d1db2);};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x25')]=function(){return this[_0xf2c6('0x23')](_0xf2c6('0x26'));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x27')]=function(_0x4971b1,_0x2c13cb,_0x5382aa){_0x4971b1=_0x4971b1===undefined?_0xf2c6('0x28'):_0x4971b1;_0x2c13cb=_0x2c13cb===undefined?'5':_0x2c13cb;_0x5382aa=_0x5382aa===undefined?'1':_0x5382aa;return this[_0xf2c6('0x23')](util[_0xf2c6('0x29')](_0xf2c6('0x2a'),_0x4971b1,_0x2c13cb*0x3e8,_0x5382aa));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x2b')]=function(_0x185475){_0x185475=_0x185475||_0xf2c6('0x2c');return this[_0xf2c6('0x23')](util[_0xf2c6('0x29')](_0xf2c6('0x2d'),_0x185475));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x2e')]=function(_0x29a032,_0x5c6939){if(_[_0xf2c6('0x2f')](_0x5c6939)){return this[_0xf2c6('0x23')](util[_0xf2c6('0x29')](_0xf2c6('0x30'),_0x29a032,_0x5c6939[_0xf2c6('0x31')](',')));}return this['sendRequest'](util['format']('EXEC\x20%s\x20%s',_0x29a032,_0x5c6939));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x32')]=function(_0x43b0d2){return this['sendRequest'](util[_0xf2c6('0x29')](_0xf2c6('0x33'),_0x43b0d2));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x34')]=function(_0x1ae259){return this[_0xf2c6('0x23')](util['format'](_0xf2c6('0x35'),_0x1ae259));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x36')]=function(_0x5aa627){return this[_0xf2c6('0x23')](util['format'](_0xf2c6('0x37'),_0x5aa627));};AGIChannel[_0xf2c6('0x22')]['hangup']=function(){return this['sendRequest'](_0xf2c6('0x38'));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x39')]=function(_0x420a0b,_0x251d8f){var _0x392a74=_['isBoolean'](_0x251d8f)||_[_0xf2c6('0x3a')](_0x251d8f)?_0x251d8f['toString']():_0x251d8f;return this[_0xf2c6('0x23')](util[_0xf2c6('0x29')](_0xf2c6('0x3b'),_0x420a0b,_0x392a74?_0x392a74[_0xf2c6('0x3c')]()[_0xf2c6('0x11')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x3d')]=function(_0x2a32a9,_0x198281){return this[_0xf2c6('0x23')](util[_0xf2c6('0x29')](_0xf2c6('0x3e'),_0x2a32a9,_0x198281));};AGIChannel['prototype']['sayDigits']=function(_0x46a530,_0x1543bf){return this[_0xf2c6('0x23')](util[_0xf2c6('0x29')](_0xf2c6('0x3f'),_0x46a530,_0x1543bf));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x40')]=function(_0x1c27cf,_0x4387e3){return this['sendRequest'](util['format']('SAY\x20PHONETIC\x20\x22%s\x22\x20%s',_0x1c27cf,_0x4387e3));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x41')]=function(_0x342ac9,_0x1ff2f4,_0x4fa88c){_0x1ff2f4=_0x1ff2f4||this[_0xf2c6('0x42')];_0x4fa88c=_0x4fa88c||0x1;this[_0xf2c6('0x32')](_0x342ac9);this[_0xf2c6('0x34')](_0x1ff2f4);this[_0xf2c6('0x36')](_0x4fa88c);return this['noop'](util[_0xf2c6('0x29')](_0xf2c6('0x43'),_0x342ac9,_0x1ff2f4,_0x4fa88c));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x44')]=function(_0x176a11){return this[_0xf2c6('0x23')](util[_0xf2c6('0x29')]('GET\x20VARIABLE\x20\x22%s\x22',_0x176a11));};AGIChannel[_0xf2c6('0x22')]['recordFile']=function(_0x363b48,_0xaa89bb,_0x2b7cea,_0x1feffc,_0x246737,_0x35edb4){_0xaa89bb=_0xaa89bb||_0xf2c6('0x45');_0x2b7cea=_0x2b7cea||'';_0x1feffc=_0x1feffc===undefined?-0x1:_0x1feffc==='-1'?-0x1:_0x1feffc*0x3e8;_0x246737=_0x246737===undefined?'':'s='+_0x246737;_0x35edb4=_0x35edb4?_0xf2c6('0x46'):'';return this[_0xf2c6('0x23')](util[_0xf2c6('0x29')](_0xf2c6('0x47'),_0x363b48,_0xaa89bb,_0x2b7cea,_0x1feffc,_0x35edb4,_0x246737));};AGIChannel[_0xf2c6('0x22')]['streamFile']=function(_0x38e43f,_0x2a8de9){_0x2a8de9=_0x2a8de9||'';return this[_0xf2c6('0x23')](util['format'](_0xf2c6('0x48'),_0x38e43f,_0x2a8de9));};AGIChannel[_0xf2c6('0x22')][_0xf2c6('0x49')]=function(_0x33bfd5){return this['exec'](_0xf2c6('0x4a'),_0x33bfd5);};AGIChannel['prototype'][_0xf2c6('0x4b')]=function(_0x5816cf){return this[_0xf2c6('0x2e')](_0xf2c6('0x4c'),_0x5816cf);};AGIChannel[_0xf2c6('0x22')]['error']=function(_0x42c58d,_0x1f8856){this[_0xf2c6('0x2b')](util['format'](_0xf2c6('0x4d'),_0x42c58d['id'],_0x42c58d[_0xf2c6('0x4e')],_0x1f8856));return{'code':0x1f4,'result':'-1','extra':''};};module['exports']=AGIChannel;