8ddd848d612f203e66ef0dd1bef4ff148875d3e2
[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 _0x457a=['utf8','setTimeout','headers','ready','line','toLowerCase','substring','520-Invalid','520\x20End\x20of\x20proper','function','replace','result=','indexOf','substr','split','length','match','error','E_AGI_SOCKET_ERROR','close','emit','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','write','prototype','sendRequest','command','sync','answer','beep','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','NO\x20MESSAGE','format','VERBOSE\x20\x22%s\x22','exec','EXEC\x20%s\x20%s','join','setContext','setExtension','SET\x20EXTENSION\x20%s','setVariable','isBoolean','isNumber','toString','sayNumber','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','setPriority','GOTO\x20%s\x20%s\x20%s','GET\x20VARIABLE\x20\x22%s\x22','recordFile','wav','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','streamFile','agi','AGI','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','util','lodash','events','./reply','call','setEncoding'];(function(_0x272fc2,_0x442274){var _0x549597=function(_0x144736){while(--_0x144736){_0x272fc2['push'](_0x272fc2['shift']());}};_0x549597(++_0x442274);}(_0x457a,0x167));var _0xa457=function(_0x4e2fbd,_0x2b3a2e){_0x4e2fbd=_0x4e2fbd-0x0;var _0x2fd586=_0x457a[_0x4e2fbd];return _0x2fd586;};'use strict';var util=require(_0xa457('0x0'));var _=require(_0xa457('0x1'));var EventEmitter=require(_0xa457('0x2'))['EventEmitter'];var AGIReply=require(_0xa457('0x3'));var AGIError=require('./error');function AGIChannel(_0x84908f){var _0x3fe457=this,_0x8a0ea9=new AGIReply(),_0x685838=![],_0x553716={};EventEmitter[_0xa457('0x4')](_0x3fe457);_0x84908f[_0xa457('0x5')](_0xa457('0x6'));_0x84908f[_0xa457('0x7')](0x8*0x3c*0x3c*0x3e8);_0x8a0ea9['setEncoding'](_0xa457('0x6'));_0x8a0ea9['on'](_0xa457('0x8'),function(_0xf8f6bb){for(var _0x6bb203 in _0xf8f6bb){_0x3fe457[_0x6bb203]=_0xf8f6bb[_0x6bb203];}_0x3fe457['emit'](_0xa457('0x9'));});_0x8a0ea9['on'](_0xa457('0xa'),function(_0x689279){if(_0x689279[_0xa457('0xb')]()=='hangup'){_0x3fe457['emit']('hangup');return;}if(_0x689279[_0xa457('0xc')](0x0,0xb)==_0xa457('0xd')){_0x685838=!![];}if(_0x685838){_0x553716['rx']+=_0x689279+'\x0a';if(_0x689279['search'](_0xa457('0xe'))!=-0x1){_0x685838=![];}}else{_0x553716['rx']=_0x689279;}if(_0x685838){return;}if(typeof _0x553716['cb']==_0xa457('0xf')){var _0x2811af=_0x553716['rx'][_0xa457('0xc')](0x0,0x3),_0x4c1251=null,_0xa18dea=null;_0x2811af=parseInt(_0x2811af);if(isNaN(_0x2811af)){_0x553716['cb'](null,{'code':0x1f4,'result':-0x1,'extra':'no\x20code'});return;}if(_0x2811af!=0xc8){_0x553716['cb'](null,{'code':_0x2811af,'result':-0x1,'extra':'KO'});return;}_0x4c1251=_0x553716['rx']['substring'](0x4)[_0xa457('0x10')](_0xa457('0x11'),'');if(_0x4c1251[_0xa457('0x12')]('\x20')!=-0x1){_0x4c1251=_0x4c1251[_0xa457('0x13')](0x0,_0x4c1251[_0xa457('0x12')]('\x20'));}if(_['startsWith'](_0x4c1251,'-1')){_0x4c1251=parseInt(_0x4c1251);}_0xa18dea=_0x553716['rx'][_0xa457('0x14')]('\x20');if(_0xa18dea['length']==0x3){_0xa18dea=_0xa18dea[0x2][_0xa457('0xc')](0x1,_0xa18dea[0x2][_0xa457('0x15')]-0x1);}else if(_0xa18dea['length']>0x3){var _0x45059b=/\((.+)\)/;var _0x5ad0aa=_0x553716['rx'][_0xa457('0x16')](_0x45059b);if(_0x5ad0aa){_0xa18dea=_0x5ad0aa[0x1];}else{_0xa18dea=null;}}else{_0xa18dea=null;}_0x553716['cb'](null,{'code':_0x2811af,'result':_0x4c1251,'extra':_0xa18dea});}});_0x84908f['on'](_0xa457('0x17'),function(_0x39e62e){_0x3fe457['emit'](_0xa457('0x17'),new AGIError(_0xa457('0x18'),_0x39e62e['code']));});_0x84908f['on'](_0xa457('0x19'),function(){_0x3fe457[_0xa457('0x1a')](_0xa457('0x19'),new AGIError(_0xa457('0x1b')));});_0x84908f['on'](_0xa457('0x1c'),function(){_0x3fe457[_0xa457('0x1a')]('timeout',new AGIError(_0xa457('0x1d')));_0x84908f[_0xa457('0x1e')]();});_0x84908f[_0xa457('0x1f')](_0x8a0ea9);this['command']=function(_0x78f58f,_0x4a8084){var _0x78f58f=_0x78f58f||'',_0x4a8084=typeof _0x4a8084==_0xa457('0xf')?_0x4a8084:new Function();_0x553716={'tx':_0x78f58f,'rx':'','cb':_0x4a8084};_0x84908f[_0xa457('0x20')](_0x78f58f+'\x0a');},this[_0xa457('0x19')]=function(){_0x84908f[_0xa457('0x1e')]();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel[_0xa457('0x21')][_0xa457('0x22')]=function(_0x256781){return this[_0xa457('0x23')][_0xa457('0x24')](this,_0x256781);};AGIChannel[_0xa457('0x21')][_0xa457('0x25')]=function(){return this[_0xa457('0x22')]('ANSWER');};AGIChannel['prototype']['getData']=function(_0x291efb,_0x591b33,_0x2507c4){_0x291efb=_0x291efb===undefined?_0xa457('0x26'):_0x291efb;_0x591b33=_0x591b33===undefined?'5':_0x591b33;_0x2507c4=_0x2507c4===undefined?'1':_0x2507c4;return this[_0xa457('0x22')](util['format'](_0xa457('0x27'),_0x291efb,_0x591b33*0x3e8,_0x2507c4));};AGIChannel[_0xa457('0x21')][_0xa457('0x28')]=function(_0x2c1c01){_0x2c1c01=_0x2c1c01||_0xa457('0x29');return this['sendRequest'](util[_0xa457('0x2a')](_0xa457('0x2b'),_0x2c1c01));};AGIChannel[_0xa457('0x21')][_0xa457('0x2c')]=function(_0x234280,_0x287734){if(_['isArray'](_0x287734)){return this[_0xa457('0x22')](util[_0xa457('0x2a')](_0xa457('0x2d'),_0x234280,_0x287734[_0xa457('0x2e')](',')));}return this[_0xa457('0x22')](util[_0xa457('0x2a')](_0xa457('0x2d'),_0x234280,_0x287734));};AGIChannel['prototype'][_0xa457('0x2f')]=function(_0x25112a){return this[_0xa457('0x22')](util[_0xa457('0x2a')]('SET\x20CONTEXT\x20%s',_0x25112a));};AGIChannel['prototype'][_0xa457('0x30')]=function(_0x50aded){return this[_0xa457('0x22')](util['format'](_0xa457('0x31'),_0x50aded));};AGIChannel[_0xa457('0x21')]['setPriority']=function(_0x750c70){return this['sendRequest'](util[_0xa457('0x2a')]('SET\x20PRIORITY\x20%s',_0x750c70));};AGIChannel['prototype']['hangup']=function(){return this[_0xa457('0x22')]('HANGUP');};AGIChannel[_0xa457('0x21')][_0xa457('0x32')]=function(_0x163c9d,_0x45cfff){var _0x235a49=_[_0xa457('0x33')](_0x45cfff)||_[_0xa457('0x34')](_0x45cfff)?_0x45cfff[_0xa457('0x35')]():_0x45cfff;return this[_0xa457('0x22')](util[_0xa457('0x2a')]('SET\x20VARIABLE\x20%s\x20\x22%s\x22',_0x163c9d,_0x235a49?_0x235a49['toString']()['replace'](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xa457('0x21')][_0xa457('0x36')]=function(_0x3b7923,_0x259eaf){return this[_0xa457('0x22')](util[_0xa457('0x2a')]('SAY\x20NUMBER\x20%s\x20%s',_0x3b7923,_0x259eaf));};AGIChannel[_0xa457('0x21')]['sayDigits']=function(_0xc9504a,_0x3dad10){return this['sendRequest'](util[_0xa457('0x2a')](_0xa457('0x37'),_0xc9504a,_0x3dad10));};AGIChannel['prototype'][_0xa457('0x38')]=function(_0x2096de,_0x495d86){return this['sendRequest'](util[_0xa457('0x2a')](_0xa457('0x39'),_0x2096de,_0x495d86));};AGIChannel[_0xa457('0x21')][_0xa457('0x3a')]=function(_0x272fd8,_0x1feb4d,_0xc2bef8){_0x1feb4d=_0x1feb4d||this[_0xa457('0x3b')];_0xc2bef8=_0xc2bef8||0x1;this[_0xa457('0x2f')](_0x272fd8);this['setExtension'](_0x1feb4d);this[_0xa457('0x3c')](_0xc2bef8);return this[_0xa457('0x28')](util['format'](_0xa457('0x3d'),_0x272fd8,_0x1feb4d,_0xc2bef8));};AGIChannel['prototype']['getVariable']=function(_0x1f635a){return this[_0xa457('0x22')](util[_0xa457('0x2a')](_0xa457('0x3e'),_0x1f635a));};AGIChannel[_0xa457('0x21')][_0xa457('0x3f')]=function(_0x362f06,_0x496031,_0x2d598e,_0x57a067,_0x1658c0,_0x5f163d){_0x496031=_0x496031||_0xa457('0x40');_0x2d598e=_0x2d598e||'';_0x57a067=_0x57a067===undefined?-0x1:_0x57a067==='-1'?-0x1:_0x57a067*0x3e8;_0x1658c0=_0x1658c0===undefined?'':'s='+_0x1658c0;_0x5f163d=_0x5f163d?'BEEP':'';return this[_0xa457('0x22')](util['format'](_0xa457('0x41'),_0x362f06,_0x496031,_0x2d598e,_0x57a067,_0x5f163d,_0x1658c0));};AGIChannel[_0xa457('0x21')][_0xa457('0x42')]=function(_0x1c8ae3,_0x50186d){_0x50186d=_0x50186d||'';return this[_0xa457('0x22')](util[_0xa457('0x2a')]('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0x1c8ae3,_0x50186d));};AGIChannel['prototype'][_0xa457('0x43')]=function(_0x34ae98){return this[_0xa457('0x2c')](_0xa457('0x44'),_0x34ae98);};AGIChannel[_0xa457('0x21')]['wait']=function(_0x3c792a){return this['exec'](_0xa457('0x45'),_0x3c792a);};AGIChannel[_0xa457('0x21')][_0xa457('0x17')]=function(_0x58365c,_0x47948c){this[_0xa457('0x28')](util[_0xa457('0x2a')](_0xa457('0x46'),_0x58365c['id'],_0x58365c[_0xa457('0x47')],_0x47948c));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xa457('0x48')]=AGIChannel;