Built motion from commit 932cf0d0.|2.5.42
[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 _0x3c6a=['emit','ready','line','hangup','substring','520-Invalid','no\x20code','replace','result=','indexOf','startsWith','split','length','match','error','E_AGI_SOCKET_ERROR','code','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','command','function','write','close','destroy','inherits','sendRequest','sync','prototype','ANSWER','getData','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','isArray','format','EXEC\x20%s\x20%s','setExtension','SET\x20EXTENSION\x20%s','SET\x20PRIORITY\x20%s','HANGUP','setVariable','isBoolean','isNumber','toString','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','continueAt','extension','GET\x20VARIABLE\x20\x22%s\x22','wav','BEEP','STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22','agi','AGI','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','lodash','events','EventEmitter','./reply','./error','call','utf8','setTimeout','setEncoding','headers'];(function(_0xea8947,_0x1b573d){var _0x2455e9=function(_0x18771e){while(--_0x18771e){_0xea8947['push'](_0xea8947['shift']());}};_0x2455e9(++_0x1b573d);}(_0x3c6a,0xd1));var _0xa3c6=function(_0x450689,_0x3b857c){_0x450689=_0x450689-0x0;var _0x46ffb0=_0x3c6a[_0x450689];return _0x46ffb0;};'use strict';var util=require('util');var _=require(_0xa3c6('0x0'));var EventEmitter=require(_0xa3c6('0x1'))[_0xa3c6('0x2')];var AGIReply=require(_0xa3c6('0x3'));var AGIError=require(_0xa3c6('0x4'));function AGIChannel(_0x216afa){var _0x280c81=this,_0x8addc2=new AGIReply(),_0xc6a73b=![],_0x3392c5={};EventEmitter[_0xa3c6('0x5')](_0x280c81);_0x216afa['setEncoding'](_0xa3c6('0x6'));_0x216afa[_0xa3c6('0x7')](0x8*0x3c*0x3c*0x3e8);_0x8addc2[_0xa3c6('0x8')](_0xa3c6('0x6'));_0x8addc2['on'](_0xa3c6('0x9'),function(_0xa4d22){for(var _0x3eb474 in _0xa4d22){_0x280c81[_0x3eb474]=_0xa4d22[_0x3eb474];}_0x280c81[_0xa3c6('0xa')](_0xa3c6('0xb'));});_0x8addc2['on'](_0xa3c6('0xc'),function(_0xa5da8c){if(_0xa5da8c['toLowerCase']()==_0xa3c6('0xd')){_0x280c81['emit'](_0xa3c6('0xd'));return;}if(_0xa5da8c[_0xa3c6('0xe')](0x0,0xb)==_0xa3c6('0xf')){_0xc6a73b=!![];}if(_0xc6a73b){_0x3392c5['rx']+=_0xa5da8c+'\x0a';if(_0xa5da8c['search']('520\x20End\x20of\x20proper')!=-0x1){_0xc6a73b=![];}}else{_0x3392c5['rx']=_0xa5da8c;}if(_0xc6a73b){return;}if(typeof _0x3392c5['cb']=='function'){var _0x3f17c2=_0x3392c5['rx'][_0xa3c6('0xe')](0x0,0x3),_0x53dcba=null,_0x24b8ae=null;_0x3f17c2=parseInt(_0x3f17c2);if(isNaN(_0x3f17c2)){_0x3392c5['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xa3c6('0x10')});return;}if(_0x3f17c2!=0xc8){_0x3392c5['cb'](null,{'code':_0x3f17c2,'result':-0x1,'extra':'KO'});return;}_0x53dcba=_0x3392c5['rx'][_0xa3c6('0xe')](0x4)[_0xa3c6('0x11')](_0xa3c6('0x12'),'');if(_0x53dcba[_0xa3c6('0x13')]('\x20')!=-0x1){_0x53dcba=_0x53dcba['substr'](0x0,_0x53dcba[_0xa3c6('0x13')]('\x20'));}if(_[_0xa3c6('0x14')](_0x53dcba,'-1')){_0x53dcba=parseInt(_0x53dcba);}_0x24b8ae=_0x3392c5['rx'][_0xa3c6('0x15')]('\x20');if(_0x24b8ae['length']==0x3){_0x24b8ae=_0x24b8ae[0x2][_0xa3c6('0xe')](0x1,_0x24b8ae[0x2]['length']-0x1);}else if(_0x24b8ae[_0xa3c6('0x16')]>0x3){var _0x4ad5dc=/\((.+)\)/;var _0x364289=_0x3392c5['rx'][_0xa3c6('0x17')](_0x4ad5dc);if(_0x364289){_0x24b8ae=_0x364289[0x1];}else{_0x24b8ae=null;}}else{_0x24b8ae=null;}_0x3392c5['cb'](null,{'code':_0x3f17c2,'result':_0x53dcba,'extra':_0x24b8ae});}});_0x216afa['on'](_0xa3c6('0x18'),function(_0x217d82){_0x280c81[_0xa3c6('0xa')](_0xa3c6('0x18'),new AGIError(_0xa3c6('0x19'),_0x217d82[_0xa3c6('0x1a')]));});_0x216afa['on']('close',function(){_0x280c81[_0xa3c6('0xa')]('close',new AGIError(_0xa3c6('0x1b')));});_0x216afa['on'](_0xa3c6('0x1c'),function(){_0x280c81[_0xa3c6('0xa')](_0xa3c6('0x1c'),new AGIError(_0xa3c6('0x1d')));_0x216afa['destroy']();});_0x216afa['pipe'](_0x8addc2);this[_0xa3c6('0x1e')]=function(_0x5c9c2c,_0x5403b1){var _0x5c9c2c=_0x5c9c2c||'',_0x5403b1=typeof _0x5403b1==_0xa3c6('0x1f')?_0x5403b1:new Function();_0x3392c5={'tx':_0x5c9c2c,'rx':'','cb':_0x5403b1};_0x216afa[_0xa3c6('0x20')](_0x5c9c2c+'\x0a');},this[_0xa3c6('0x21')]=function(){_0x216afa[_0xa3c6('0x22')]();};}util[_0xa3c6('0x23')](AGIChannel,EventEmitter);AGIChannel['prototype'][_0xa3c6('0x24')]=function(_0x92b3fb){return this[_0xa3c6('0x1e')][_0xa3c6('0x25')](this,_0x92b3fb);};AGIChannel[_0xa3c6('0x26')]['answer']=function(){return this['sendRequest'](_0xa3c6('0x27'));};AGIChannel[_0xa3c6('0x26')][_0xa3c6('0x28')]=function(_0x5731d9,_0x55c9e7,_0x1394f3){_0x5731d9=_0x5731d9===undefined?'beep':_0x5731d9;_0x55c9e7=_0x55c9e7===undefined?'5':_0x55c9e7;_0x1394f3=_0x1394f3===undefined?'1':_0x1394f3;return this[_0xa3c6('0x24')](util['format'](_0xa3c6('0x29'),_0x5731d9,_0x55c9e7*0x3e8,_0x1394f3));};AGIChannel[_0xa3c6('0x26')][_0xa3c6('0x2a')]=function(_0x14aa2b){_0x14aa2b=_0x14aa2b||_0xa3c6('0x2b');return this[_0xa3c6('0x24')](util['format'](_0xa3c6('0x2c'),_0x14aa2b));};AGIChannel[_0xa3c6('0x26')][_0xa3c6('0x2d')]=function(_0x412fc1,_0x33c5d){if(_[_0xa3c6('0x2e')](_0x33c5d)){return this['sendRequest'](util[_0xa3c6('0x2f')]('EXEC\x20%s\x20%s',_0x412fc1,_0x33c5d['join'](',')));}return this['sendRequest'](util[_0xa3c6('0x2f')](_0xa3c6('0x30'),_0x412fc1,_0x33c5d));};AGIChannel[_0xa3c6('0x26')]['setContext']=function(_0x1e1876){return this['sendRequest'](util[_0xa3c6('0x2f')]('SET\x20CONTEXT\x20%s',_0x1e1876));};AGIChannel[_0xa3c6('0x26')][_0xa3c6('0x31')]=function(_0x3dc775){return this[_0xa3c6('0x24')](util[_0xa3c6('0x2f')](_0xa3c6('0x32'),_0x3dc775));};AGIChannel[_0xa3c6('0x26')]['setPriority']=function(_0x5b0a02){return this[_0xa3c6('0x24')](util[_0xa3c6('0x2f')](_0xa3c6('0x33'),_0x5b0a02));};AGIChannel[_0xa3c6('0x26')][_0xa3c6('0xd')]=function(){return this[_0xa3c6('0x24')](_0xa3c6('0x34'));};AGIChannel[_0xa3c6('0x26')][_0xa3c6('0x35')]=function(_0x2fea57,_0x451f90){var _0x4329b3=_[_0xa3c6('0x36')](_0x451f90)||_[_0xa3c6('0x37')](_0x451f90)?_0x451f90[_0xa3c6('0x38')]():_0x451f90;return this[_0xa3c6('0x24')](util[_0xa3c6('0x2f')]('SET\x20VARIABLE\x20%s\x20\x22%s\x22',_0x2fea57,_0x4329b3?_0x4329b3[_0xa3c6('0x38')]()['replace'](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel['prototype'][_0xa3c6('0x39')]=function(_0x5896cd,_0x35603e){return this['sendRequest'](util[_0xa3c6('0x2f')](_0xa3c6('0x3a'),_0x5896cd,_0x35603e));};AGIChannel['prototype'][_0xa3c6('0x3b')]=function(_0x3b082a,_0x382b38){return this[_0xa3c6('0x24')](util[_0xa3c6('0x2f')](_0xa3c6('0x3c'),_0x3b082a,_0x382b38));};AGIChannel['prototype']['sayPhonetic']=function(_0x35b2f3,_0x3ea3c1){return this[_0xa3c6('0x24')](util['format']('SAY\x20PHONETIC\x20\x22%s\x22\x20%s',_0x35b2f3,_0x3ea3c1));};AGIChannel[_0xa3c6('0x26')][_0xa3c6('0x3d')]=function(_0x49e2a9,_0x1a9c9a,_0x5c6a37){_0x1a9c9a=_0x1a9c9a||this[_0xa3c6('0x3e')];_0x5c6a37=_0x5c6a37||0x1;this['setContext'](_0x49e2a9);this[_0xa3c6('0x31')](_0x1a9c9a);this['setPriority'](_0x5c6a37);return this[_0xa3c6('0x2a')](util[_0xa3c6('0x2f')]('GOTO\x20%s\x20%s\x20%s',_0x49e2a9,_0x1a9c9a,_0x5c6a37));};AGIChannel[_0xa3c6('0x26')]['getVariable']=function(_0x9601a8){return this['sendRequest'](util[_0xa3c6('0x2f')](_0xa3c6('0x3f'),_0x9601a8));};AGIChannel[_0xa3c6('0x26')]['recordFile']=function(_0xb8ca63,_0x4da165,_0x4b9489,_0x172578,_0x5ecd1a,_0x1b3870){_0x4da165=_0x4da165||_0xa3c6('0x40');_0x4b9489=_0x4b9489||'';_0x172578=_0x172578===undefined?-0x1:_0x172578==='-1'?-0x1:_0x172578*0x3e8;_0x5ecd1a=_0x5ecd1a===undefined?'':'s='+_0x5ecd1a;_0x1b3870=_0x1b3870?_0xa3c6('0x41'):'';return this[_0xa3c6('0x24')](util[_0xa3c6('0x2f')]('RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s',_0xb8ca63,_0x4da165,_0x4b9489,_0x172578,_0x1b3870,_0x5ecd1a));};AGIChannel['prototype']['streamFile']=function(_0x25423d,_0x2ed918){_0x2ed918=_0x2ed918||'';return this['sendRequest'](util[_0xa3c6('0x2f')](_0xa3c6('0x42'),_0x25423d,_0x2ed918));};AGIChannel[_0xa3c6('0x26')][_0xa3c6('0x43')]=function(_0x2c9d01){return this[_0xa3c6('0x2d')](_0xa3c6('0x44'),_0x2c9d01);};AGIChannel['prototype']['wait']=function(_0x360d67){return this['exec'](_0xa3c6('0x45'),_0x360d67);};AGIChannel[_0xa3c6('0x26')]['error']=function(_0x329f06,_0x54a61f){this[_0xa3c6('0x2a')](util[_0xa3c6('0x2f')](_0xa3c6('0x46'),_0x329f06['id'],_0x329f06[_0xa3c6('0x47')],_0x54a61f));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xa3c6('0x48')]=AGIChannel;