9879316a4772227e1dc8112b736a1eb2e384dcbf
[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 _0x679f=['prototype','sync','answer','sendRequest','ANSWER','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','NO\x20MESSAGE','exec','EXEC\x20%s\x20%s','join','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','HANGUP','isBoolean','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','replace','sayNumber','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','GOTO\x20%s\x20%s\x20%s','getVariable','log','getvariable','GET\x20VARIABLE\x20\x22%s\x22','recordFile','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','wait','WAIT','noop','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','util','events','EventEmitter','./error','call','setEncoding','utf8','setTimeout','emit','ready','line','hangup','substring','search','520\x20End\x20of\x20proper','function','no\x20code','indexOf','substr','startsWith','split','length','error','E_AGI_SOCKET_ERROR','code','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','command','command=','write','inherits'];(function(_0x403db1,_0x59018e){var _0x47c48f=function(_0x1b663c){while(--_0x1b663c){_0x403db1['push'](_0x403db1['shift']());}};_0x47c48f(++_0x59018e);}(_0x679f,0xd3));var _0xf679=function(_0x40a045,_0x516f0e){_0x40a045=_0x40a045-0x0;var _0x1a687c=_0x679f[_0x40a045];return _0x1a687c;};'use strict';var util=require(_0xf679('0x0'));var _=require('lodash');var EventEmitter=require(_0xf679('0x1'))[_0xf679('0x2')];var AGIReply=require('./reply');var AGIError=require(_0xf679('0x3'));function AGIChannel(_0x43e3b5){var _0x4e0a69=this,_0xaa9c94=new AGIReply(),_0x56bec1=![],_0x2296d7={};EventEmitter[_0xf679('0x4')](_0x4e0a69);_0x43e3b5[_0xf679('0x5')](_0xf679('0x6'));_0x43e3b5[_0xf679('0x7')](0x8*0x3c*0x3c*0x3e8);_0xaa9c94[_0xf679('0x5')](_0xf679('0x6'));_0xaa9c94['on']('headers',function(_0x39c87d){for(var _0x5132b9 in _0x39c87d){_0x4e0a69[_0x5132b9]=_0x39c87d[_0x5132b9];}_0x4e0a69[_0xf679('0x8')](_0xf679('0x9'));});_0xaa9c94['on'](_0xf679('0xa'),function(_0x47e991){if(_0x47e991['toLowerCase']()==_0xf679('0xb')){_0x4e0a69[_0xf679('0x8')]('hangup');return;}if(_0x47e991[_0xf679('0xc')](0x0,0xb)=='520-Invalid'){_0x56bec1=!![];}if(_0x56bec1){_0x2296d7['rx']+=_0x47e991+'\x0a';if(_0x47e991[_0xf679('0xd')](_0xf679('0xe'))!=-0x1){_0x56bec1=![];}}else{_0x2296d7['rx']=_0x47e991;}if(_0x56bec1){return;}if(typeof _0x2296d7['cb']==_0xf679('0xf')){var _0x56aafd=_0x2296d7['rx'][_0xf679('0xc')](0x0,0x3),_0x3e1eb5=null,_0xf5e510=null;_0x56aafd=parseInt(_0x56aafd);if(isNaN(_0x56aafd)){_0x2296d7['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xf679('0x10')});return;}if(_0x56aafd!=0xc8){_0x2296d7['cb'](null,{'code':_0x56aafd,'result':-0x1,'extra':'KO'});return;}_0x3e1eb5=_0x2296d7['rx'][_0xf679('0xc')](0x4)['replace']('result=','');if(_0x3e1eb5[_0xf679('0x11')]('\x20')!=-0x1){_0x3e1eb5=_0x3e1eb5[_0xf679('0x12')](0x0,_0x3e1eb5['indexOf']('\x20'));}if(_[_0xf679('0x13')](_0x3e1eb5,'-1')){_0x3e1eb5=parseInt(_0x3e1eb5);}_0xf5e510=_0x2296d7['rx'][_0xf679('0x14')]('\x20');if(_0xf5e510[_0xf679('0x15')]==0x3){_0xf5e510=_0xf5e510[0x2][_0xf679('0xc')](0x1,_0xf5e510[0x2]['length']-0x1);}else if(_0xf5e510[_0xf679('0x15')]>0x3){var _0x54b5e6=/\((.+)\)/;var _0x52e658=_0x2296d7['rx']['match'](_0x54b5e6);if(_0x52e658){_0xf5e510=_0x52e658[0x1];}else{_0xf5e510=null;}}else{_0xf5e510=null;}_0x2296d7['cb'](null,{'code':_0x56aafd,'result':_0x3e1eb5,'extra':_0xf5e510});}});_0x43e3b5['on'](_0xf679('0x16'),function(_0x4253e5){_0x4e0a69[_0xf679('0x8')](_0xf679('0x16'),new AGIError(_0xf679('0x17'),_0x4253e5[_0xf679('0x18')]));});_0x43e3b5['on'](_0xf679('0x19'),function(){_0x4e0a69[_0xf679('0x8')](_0xf679('0x19'),new AGIError(_0xf679('0x1a')));});_0x43e3b5['on'](_0xf679('0x1b'),function(){_0x4e0a69[_0xf679('0x8')](_0xf679('0x1b'),new AGIError(_0xf679('0x1c')));_0x43e3b5[_0xf679('0x1d')]();});_0x43e3b5[_0xf679('0x1e')](_0xaa9c94);this[_0xf679('0x1f')]=function(_0x328870,_0x2b6ed5){console['log'](_0xf679('0x20'),_0x328870);var _0x328870=_0x328870||'',_0x2b6ed5=typeof _0x2b6ed5==_0xf679('0xf')?_0x2b6ed5:new Function();_0x2296d7={'tx':_0x328870,'rx':'','cb':_0x2b6ed5};_0x43e3b5[_0xf679('0x21')](_0x328870+'\x0a');},this[_0xf679('0x19')]=function(){_0x43e3b5[_0xf679('0x1d')]();};}util[_0xf679('0x22')](AGIChannel,EventEmitter);AGIChannel[_0xf679('0x23')]['sendRequest']=function(_0x139bb7){return this[_0xf679('0x1f')][_0xf679('0x24')](this,_0x139bb7);};AGIChannel[_0xf679('0x23')][_0xf679('0x25')]=function(){return this[_0xf679('0x26')](_0xf679('0x27'));};AGIChannel['prototype']['getData']=function(_0x3ba0c3,_0x214423,_0x53dd1f){_0x3ba0c3=_0x3ba0c3===undefined?_0xf679('0x28'):_0x3ba0c3;_0x214423=_0x214423===undefined?'5':_0x214423;_0x53dd1f=_0x53dd1f===undefined?'1':_0x53dd1f;return this['sendRequest'](util[_0xf679('0x29')](_0xf679('0x2a'),_0x3ba0c3,_0x214423*0x3e8,_0x53dd1f));};AGIChannel['prototype']['noop']=function(_0x507047){_0x507047=_0x507047||_0xf679('0x2b');return this[_0xf679('0x26')](util[_0xf679('0x29')]('VERBOSE\x20\x22%s\x22',_0x507047));};AGIChannel['prototype'][_0xf679('0x2c')]=function(_0x380367,_0x5aeecb){if(_['isArray'](_0x5aeecb)){return this[_0xf679('0x26')](util[_0xf679('0x29')](_0xf679('0x2d'),_0x380367,_0x5aeecb[_0xf679('0x2e')](',')));}return this[_0xf679('0x26')](util[_0xf679('0x29')](_0xf679('0x2d'),_0x380367,_0x5aeecb));};AGIChannel[_0xf679('0x23')][_0xf679('0x2f')]=function(_0x52af66){return this[_0xf679('0x26')](util[_0xf679('0x29')](_0xf679('0x30'),_0x52af66));};AGIChannel['prototype'][_0xf679('0x31')]=function(_0x587560){return this[_0xf679('0x26')](util[_0xf679('0x29')](_0xf679('0x32'),_0x587560));};AGIChannel[_0xf679('0x23')][_0xf679('0x33')]=function(_0x4605c0){return this[_0xf679('0x26')](util[_0xf679('0x29')](_0xf679('0x34'),_0x4605c0));};AGIChannel[_0xf679('0x23')][_0xf679('0xb')]=function(){return this[_0xf679('0x26')](_0xf679('0x35'));};AGIChannel[_0xf679('0x23')]['setVariable']=function(_0x1c640f,_0x2fffc4){var _0xbd697d=_[_0xf679('0x36')](_0x2fffc4)||_[_0xf679('0x37')](_0x2fffc4)?_0x2fffc4[_0xf679('0x38')]():_0x2fffc4;return this[_0xf679('0x26')](util[_0xf679('0x29')](_0xf679('0x39'),_0x1c640f,_0xbd697d?_0xbd697d[_0xf679('0x38')]()[_0xf679('0x3a')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xf679('0x23')][_0xf679('0x3b')]=function(_0x1c54b3,_0x288169){return this['sendRequest'](util[_0xf679('0x29')]('SAY\x20NUMBER\x20%s\x20%s',_0x1c54b3,_0x288169));};AGIChannel[_0xf679('0x23')][_0xf679('0x3c')]=function(_0x2f5273,_0x418934){return this[_0xf679('0x26')](util[_0xf679('0x29')](_0xf679('0x3d'),_0x2f5273,_0x418934));};AGIChannel[_0xf679('0x23')][_0xf679('0x3e')]=function(_0x48e282,_0x374d7b){return this['sendRequest'](util[_0xf679('0x29')](_0xf679('0x3f'),_0x48e282,_0x374d7b));};AGIChannel[_0xf679('0x23')][_0xf679('0x40')]=function(_0x45154d,_0x9078b9,_0xd2eef8){_0x9078b9=_0x9078b9||this[_0xf679('0x41')];_0xd2eef8=_0xd2eef8||0x1;this[_0xf679('0x2f')](_0x45154d);this[_0xf679('0x31')](_0x9078b9);this[_0xf679('0x33')](_0xd2eef8);return this['noop'](util[_0xf679('0x29')](_0xf679('0x42'),_0x45154d,_0x9078b9,_0xd2eef8));};AGIChannel[_0xf679('0x23')][_0xf679('0x43')]=function(_0x56ca18){console[_0xf679('0x44')](_0xf679('0x45'),_0x56ca18);return this['sendRequest'](util[_0xf679('0x29')](_0xf679('0x46'),_0x56ca18));};AGIChannel[_0xf679('0x23')][_0xf679('0x47')]=function(_0x5343a6,_0x238ac0,_0x57d189,_0x2fd6f2,_0x390fb9,_0xb92ce9){_0x238ac0=_0x238ac0||_0xf679('0x48');_0x57d189=_0x57d189||'';_0x2fd6f2=_0x2fd6f2===undefined?-0x1:_0x2fd6f2==='-1'?-0x1:_0x2fd6f2*0x3e8;_0x390fb9=_0x390fb9===undefined?'':'s='+_0x390fb9;_0xb92ce9=_0xb92ce9?_0xf679('0x49'):'';return this[_0xf679('0x26')](util['format'](_0xf679('0x4a'),_0x5343a6,_0x238ac0,_0x57d189,_0x2fd6f2,_0xb92ce9,_0x390fb9));};AGIChannel['prototype']['streamFile']=function(_0x5c275a,_0x67f8){_0x67f8=_0x67f8||'';return this['sendRequest'](util[_0xf679('0x29')](_0xf679('0x4b'),_0x5c275a,_0x67f8));};AGIChannel[_0xf679('0x23')][_0xf679('0x4c')]=function(_0x5c2468){return this[_0xf679('0x2c')]('AGI',_0x5c2468);};AGIChannel[_0xf679('0x23')][_0xf679('0x4d')]=function(_0x4d7c56){return this[_0xf679('0x2c')](_0xf679('0x4e'),_0x4d7c56);};AGIChannel['prototype'][_0xf679('0x16')]=function(_0x1cddc9,_0xae9d62){this[_0xf679('0x4f')](util[_0xf679('0x29')](_0xf679('0x50'),_0x1cddc9['id'],_0x1cddc9[_0xf679('0x51')],_0xae9d62));return{'code':0x1f4,'result':'-1','extra':''};};module['exports']=AGIChannel;