Built motion from commit 3c2ce842.|2.6.31
[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 _0xf6ea=['setPriority','SET\x20PRIORITY\x20%s','setVariable','isBoolean','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','replace','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','extension','getVariable','GET\x20VARIABLE\x20\x22%s\x22','recordFile','wav','BEEP','streamFile','STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22','agi','AGI','wait','exec','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','util','lodash','events','./reply','./error','setEncoding','utf8','setTimeout','line','toLowerCase','hangup','emit','substring','search','520\x20End\x20of\x20proper','function','indexOf','startsWith','split','length','match','error','E_AGI_SOCKET_ERROR','code','close','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','command','inherits','prototype','sendRequest','sync','answer','ANSWER','getData','beep','noop','NO\x20MESSAGE','format','VERBOSE\x20\x22%s\x22','isArray','EXEC\x20%s\x20%s','join','setContext','setExtension','SET\x20EXTENSION\x20%s'];(function(_0x3e44fa,_0x75ed2a){var _0x2a0aba=function(_0x1db6a7){while(--_0x1db6a7){_0x3e44fa['push'](_0x3e44fa['shift']());}};_0x2a0aba(++_0x75ed2a);}(_0xf6ea,0x14c));var _0xaf6e=function(_0x2c91e9,_0x2fb965){_0x2c91e9=_0x2c91e9-0x0;var _0x13f0ff=_0xf6ea[_0x2c91e9];return _0x13f0ff;};'use strict';var util=require(_0xaf6e('0x0'));var _=require(_0xaf6e('0x1'));var EventEmitter=require(_0xaf6e('0x2'))['EventEmitter'];var AGIReply=require(_0xaf6e('0x3'));var AGIError=require(_0xaf6e('0x4'));function AGIChannel(_0x371bf2){var _0x2e0558=this,_0x4678e2=new AGIReply(),_0x450ffa=![],_0x4f7f27={};EventEmitter['call'](_0x2e0558);_0x371bf2[_0xaf6e('0x5')](_0xaf6e('0x6'));_0x371bf2[_0xaf6e('0x7')](0x8*0x3c*0x3c*0x3e8);_0x4678e2[_0xaf6e('0x5')](_0xaf6e('0x6'));_0x4678e2['on']('headers',function(_0x14b46f){for(var _0x5d5435 in _0x14b46f){_0x2e0558[_0x5d5435]=_0x14b46f[_0x5d5435];}_0x2e0558['emit']('ready');});_0x4678e2['on'](_0xaf6e('0x8'),function(_0xb2d965){if(_0xb2d965[_0xaf6e('0x9')]()==_0xaf6e('0xa')){_0x2e0558[_0xaf6e('0xb')]('hangup');return;}if(_0xb2d965[_0xaf6e('0xc')](0x0,0xb)=='520-Invalid'){_0x450ffa=!![];}if(_0x450ffa){_0x4f7f27['rx']+=_0xb2d965+'\x0a';if(_0xb2d965[_0xaf6e('0xd')](_0xaf6e('0xe'))!=-0x1){_0x450ffa=![];}}else{_0x4f7f27['rx']=_0xb2d965;}if(_0x450ffa){return;}if(typeof _0x4f7f27['cb']==_0xaf6e('0xf')){var _0x4af99c=_0x4f7f27['rx'][_0xaf6e('0xc')](0x0,0x3),_0x8abae0=null,_0x4d1bcf=null;_0x4af99c=parseInt(_0x4af99c);if(isNaN(_0x4af99c)){_0x4f7f27['cb'](null,{'code':0x1f4,'result':-0x1,'extra':'no\x20code'});return;}if(_0x4af99c!=0xc8){_0x4f7f27['cb'](null,{'code':_0x4af99c,'result':-0x1,'extra':'KO'});return;}_0x8abae0=_0x4f7f27['rx'][_0xaf6e('0xc')](0x4)['replace']('result=','');if(_0x8abae0[_0xaf6e('0x10')]('\x20')!=-0x1){_0x8abae0=_0x8abae0['substr'](0x0,_0x8abae0['indexOf']('\x20'));}if(_[_0xaf6e('0x11')](_0x8abae0,'-1')){_0x8abae0=parseInt(_0x8abae0);}_0x4d1bcf=_0x4f7f27['rx'][_0xaf6e('0x12')]('\x20');if(_0x4d1bcf['length']==0x3){_0x4d1bcf=_0x4d1bcf[0x2][_0xaf6e('0xc')](0x1,_0x4d1bcf[0x2][_0xaf6e('0x13')]-0x1);}else if(_0x4d1bcf[_0xaf6e('0x13')]>0x3){var _0x344b4a=/\((.+)\)/;var _0x1207cb=_0x4f7f27['rx'][_0xaf6e('0x14')](_0x344b4a);if(_0x1207cb){_0x4d1bcf=_0x1207cb[0x1];}else{_0x4d1bcf=null;}}else{_0x4d1bcf=null;}_0x4f7f27['cb'](null,{'code':_0x4af99c,'result':_0x8abae0,'extra':_0x4d1bcf});}});_0x371bf2['on'](_0xaf6e('0x15'),function(_0x5bc4c4){_0x2e0558[_0xaf6e('0xb')]('error',new AGIError(_0xaf6e('0x16'),_0x5bc4c4[_0xaf6e('0x17')]));});_0x371bf2['on']('close',function(){_0x2e0558[_0xaf6e('0xb')](_0xaf6e('0x18'),new AGIError('E_AGI_SOCKET_CLOSE'));});_0x371bf2['on'](_0xaf6e('0x19'),function(){_0x2e0558[_0xaf6e('0xb')]('timeout',new AGIError(_0xaf6e('0x1a')));_0x371bf2[_0xaf6e('0x1b')]();});_0x371bf2[_0xaf6e('0x1c')](_0x4678e2);this[_0xaf6e('0x1d')]=function(_0x4f03f7,_0x3fba44){var _0x4f03f7=_0x4f03f7||'',_0x3fba44=typeof _0x3fba44==_0xaf6e('0xf')?_0x3fba44:new Function();_0x4f7f27={'tx':_0x4f03f7,'rx':'','cb':_0x3fba44};_0x371bf2['write'](_0x4f03f7+'\x0a');},this[_0xaf6e('0x18')]=function(){_0x371bf2[_0xaf6e('0x1b')]();};}util[_0xaf6e('0x1e')](AGIChannel,EventEmitter);AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x20')]=function(_0x4fea68){return this[_0xaf6e('0x1d')][_0xaf6e('0x21')](this,_0x4fea68);};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x22')]=function(){return this['sendRequest'](_0xaf6e('0x23'));};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x24')]=function(_0x39553b,_0x1c6792,_0x4b1ed){_0x39553b=_0x39553b===undefined?_0xaf6e('0x25'):_0x39553b;_0x1c6792=_0x1c6792===undefined?'5':_0x1c6792;_0x4b1ed=_0x4b1ed===undefined?'1':_0x4b1ed;return this['sendRequest'](util['format']('GET\x20DATA\x20\x22%s\x22\x20%s\x20%s',_0x39553b,_0x1c6792*0x3e8,_0x4b1ed));};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x26')]=function(_0x53039b){_0x53039b=_0x53039b||_0xaf6e('0x27');return this[_0xaf6e('0x20')](util[_0xaf6e('0x28')](_0xaf6e('0x29'),_0x53039b));};AGIChannel['prototype']['exec']=function(_0xfa3084,_0x21248b){if(_[_0xaf6e('0x2a')](_0x21248b)){return this['sendRequest'](util['format'](_0xaf6e('0x2b'),_0xfa3084,_0x21248b[_0xaf6e('0x2c')](',')));}return this[_0xaf6e('0x20')](util['format'](_0xaf6e('0x2b'),_0xfa3084,_0x21248b));};AGIChannel['prototype'][_0xaf6e('0x2d')]=function(_0xa794ad){return this['sendRequest'](util[_0xaf6e('0x28')]('SET\x20CONTEXT\x20%s',_0xa794ad));};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x2e')]=function(_0x50fe3c){return this['sendRequest'](util['format'](_0xaf6e('0x2f'),_0x50fe3c));};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x30')]=function(_0x5af3e5){return this[_0xaf6e('0x20')](util[_0xaf6e('0x28')](_0xaf6e('0x31'),_0x5af3e5));};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0xa')]=function(){return this[_0xaf6e('0x20')]('HANGUP');};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x32')]=function(_0x30e31b,_0x352dc9){var _0xb8e1e2=_[_0xaf6e('0x33')](_0x352dc9)||_[_0xaf6e('0x34')](_0x352dc9)?_0x352dc9[_0xaf6e('0x35')]():_0x352dc9;return this[_0xaf6e('0x20')](util['format'](_0xaf6e('0x36'),_0x30e31b,_0xb8e1e2?_0xb8e1e2[_0xaf6e('0x35')]()[_0xaf6e('0x37')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xaf6e('0x1f')]['sayNumber']=function(_0x26fab6,_0x46c69e){return this[_0xaf6e('0x20')](util[_0xaf6e('0x28')](_0xaf6e('0x38'),_0x26fab6,_0x46c69e));};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x39')]=function(_0x1ddbc4,_0x3abc1e){return this['sendRequest'](util[_0xaf6e('0x28')](_0xaf6e('0x3a'),_0x1ddbc4,_0x3abc1e));};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x3b')]=function(_0x104171,_0x202e8b){return this['sendRequest'](util[_0xaf6e('0x28')](_0xaf6e('0x3c'),_0x104171,_0x202e8b));};AGIChannel[_0xaf6e('0x1f')]['continueAt']=function(_0x2f0f87,_0x3c9a6c,_0x571fce){_0x3c9a6c=_0x3c9a6c||this[_0xaf6e('0x3d')];_0x571fce=_0x571fce||0x1;this[_0xaf6e('0x2d')](_0x2f0f87);this[_0xaf6e('0x2e')](_0x3c9a6c);this[_0xaf6e('0x30')](_0x571fce);return this[_0xaf6e('0x26')](util[_0xaf6e('0x28')]('GOTO\x20%s\x20%s\x20%s',_0x2f0f87,_0x3c9a6c,_0x571fce));};AGIChannel['prototype'][_0xaf6e('0x3e')]=function(_0x5bed48){return this[_0xaf6e('0x20')](util[_0xaf6e('0x28')](_0xaf6e('0x3f'),_0x5bed48));};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x40')]=function(_0x348f10,_0x53b098,_0x218fee,_0xe79fcc,_0x10373f,_0x186632){_0x53b098=_0x53b098||_0xaf6e('0x41');_0x218fee=_0x218fee||'';_0xe79fcc=_0xe79fcc===undefined?-0x1:_0xe79fcc==='-1'?-0x1:_0xe79fcc*0x3e8;_0x10373f=_0x10373f===undefined?'':'s='+_0x10373f;_0x186632=_0x186632?_0xaf6e('0x42'):'';return this[_0xaf6e('0x20')](util[_0xaf6e('0x28')]('RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s',_0x348f10,_0x53b098,_0x218fee,_0xe79fcc,_0x186632,_0x10373f));};AGIChannel['prototype'][_0xaf6e('0x43')]=function(_0x3faf22,_0x4cbe6e){_0x4cbe6e=_0x4cbe6e||'';return this[_0xaf6e('0x20')](util[_0xaf6e('0x28')](_0xaf6e('0x44'),_0x3faf22,_0x4cbe6e));};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x45')]=function(_0x4a320c){return this['exec'](_0xaf6e('0x46'),_0x4a320c);};AGIChannel['prototype'][_0xaf6e('0x47')]=function(_0xd038a0){return this[_0xaf6e('0x48')](_0xaf6e('0x49'),_0xd038a0);};AGIChannel[_0xaf6e('0x1f')][_0xaf6e('0x15')]=function(_0x2c8689,_0x3c2a46){this[_0xaf6e('0x26')](util[_0xaf6e('0x28')](_0xaf6e('0x4a'),_0x2c8689['id'],_0x2c8689[_0xaf6e('0x4b')],_0x3c2a46));return{'code':0x1f4,'result':'-1','extra':''};};module['exports']=AGIChannel;