f01660961d883c73dde22526e5645843a36d61d0
[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 _0x0e6e=['error','code','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','command','write','prototype','sendRequest','sync','ANSWER','getData','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','NO\x20MESSAGE','EXEC\x20%s\x20%s','join','setContext','SET\x20CONTEXT\x20%s','setExtension','setPriority','setVariable','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','continueAt','extension','GOTO\x20%s\x20%s\x20%s','getVariable','recordFile','wav','BEEP','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','agi','exec','AGI','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','exports','lodash','EventEmitter','./reply','./error','setEncoding','utf8','setTimeout','headers','emit','ready','line','toLowerCase','hangup','520-Invalid','search','520\x20End\x20of\x20proper','function','substring','no\x20code','replace','result=','indexOf','substr','startsWith','length','match'];(function(_0x142fd0,_0x34ea3c){var _0x39ac58=function(_0x332b16){while(--_0x332b16){_0x142fd0['push'](_0x142fd0['shift']());}};_0x39ac58(++_0x34ea3c);}(_0x0e6e,0x153));var _0xe0e6=function(_0x3cf13a,_0x549ff3){_0x3cf13a=_0x3cf13a-0x0;var _0x56b7e1=_0x0e6e[_0x3cf13a];return _0x56b7e1;};'use strict';var util=require('util');var _=require(_0xe0e6('0x0'));var EventEmitter=require('events')[_0xe0e6('0x1')];var AGIReply=require(_0xe0e6('0x2'));var AGIError=require(_0xe0e6('0x3'));function AGIChannel(_0x3f7edf){var _0xa207ee=this,_0x4d50f8=new AGIReply(),_0x14f875=![],_0x39d7d7={};EventEmitter['call'](_0xa207ee);_0x3f7edf[_0xe0e6('0x4')](_0xe0e6('0x5'));_0x3f7edf[_0xe0e6('0x6')](0x8*0x3c*0x3c*0x3e8);_0x4d50f8[_0xe0e6('0x4')](_0xe0e6('0x5'));_0x4d50f8['on'](_0xe0e6('0x7'),function(_0x5dab68){for(var _0x56c416 in _0x5dab68){_0xa207ee[_0x56c416]=_0x5dab68[_0x56c416];}_0xa207ee[_0xe0e6('0x8')](_0xe0e6('0x9'));});_0x4d50f8['on'](_0xe0e6('0xa'),function(_0x3faad2){if(_0x3faad2[_0xe0e6('0xb')]()==_0xe0e6('0xc')){_0xa207ee[_0xe0e6('0x8')](_0xe0e6('0xc'));return;}if(_0x3faad2['substring'](0x0,0xb)==_0xe0e6('0xd')){_0x14f875=!![];}if(_0x14f875){_0x39d7d7['rx']+=_0x3faad2+'\x0a';if(_0x3faad2[_0xe0e6('0xe')](_0xe0e6('0xf'))!=-0x1){_0x14f875=![];}}else{_0x39d7d7['rx']=_0x3faad2;}if(_0x14f875){return;}if(typeof _0x39d7d7['cb']==_0xe0e6('0x10')){var _0x3c728e=_0x39d7d7['rx'][_0xe0e6('0x11')](0x0,0x3),_0x2c13c3=null,_0x1d488c=null;_0x3c728e=parseInt(_0x3c728e);if(isNaN(_0x3c728e)){_0x39d7d7['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xe0e6('0x12')});return;}if(_0x3c728e!=0xc8){_0x39d7d7['cb'](null,{'code':_0x3c728e,'result':-0x1,'extra':'KO'});return;}_0x2c13c3=_0x39d7d7['rx']['substring'](0x4)[_0xe0e6('0x13')](_0xe0e6('0x14'),'');if(_0x2c13c3[_0xe0e6('0x15')]('\x20')!=-0x1){_0x2c13c3=_0x2c13c3[_0xe0e6('0x16')](0x0,_0x2c13c3['indexOf']('\x20'));}if(_[_0xe0e6('0x17')](_0x2c13c3,'-1')){_0x2c13c3=parseInt(_0x2c13c3);}_0x1d488c=_0x39d7d7['rx']['split']('\x20');if(_0x1d488c['length']==0x3){_0x1d488c=_0x1d488c[0x2][_0xe0e6('0x11')](0x1,_0x1d488c[0x2][_0xe0e6('0x18')]-0x1);}else if(_0x1d488c[_0xe0e6('0x18')]>0x3){var _0x23a91b=/\((.+)\)/;var _0x2091f7=_0x39d7d7['rx'][_0xe0e6('0x19')](_0x23a91b);if(_0x2091f7){_0x1d488c=_0x2091f7[0x1];}else{_0x1d488c=null;}}else{_0x1d488c=null;}_0x39d7d7['cb'](null,{'code':_0x3c728e,'result':_0x2c13c3,'extra':_0x1d488c});}});_0x3f7edf['on'](_0xe0e6('0x1a'),function(_0x4f7583){_0xa207ee[_0xe0e6('0x8')](_0xe0e6('0x1a'),new AGIError('E_AGI_SOCKET_ERROR',_0x4f7583[_0xe0e6('0x1b')]));});_0x3f7edf['on'](_0xe0e6('0x1c'),function(){_0xa207ee[_0xe0e6('0x8')]('close',new AGIError(_0xe0e6('0x1d')));});_0x3f7edf['on'](_0xe0e6('0x1e'),function(){_0xa207ee[_0xe0e6('0x8')](_0xe0e6('0x1e'),new AGIError(_0xe0e6('0x1f')));_0x3f7edf[_0xe0e6('0x20')]();});_0x3f7edf[_0xe0e6('0x21')](_0x4d50f8);this[_0xe0e6('0x22')]=function(_0x1d5020,_0x58b019){var _0x1d5020=_0x1d5020||'',_0x58b019=typeof _0x58b019=='function'?_0x58b019:new Function();_0x39d7d7={'tx':_0x1d5020,'rx':'','cb':_0x58b019};_0x3f7edf[_0xe0e6('0x23')](_0x1d5020+'\x0a');},this['close']=function(){_0x3f7edf['destroy']();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel[_0xe0e6('0x24')][_0xe0e6('0x25')]=function(_0x2e31f9){return this[_0xe0e6('0x22')][_0xe0e6('0x26')](this,_0x2e31f9);};AGIChannel['prototype']['answer']=function(){return this[_0xe0e6('0x25')](_0xe0e6('0x27'));};AGIChannel['prototype'][_0xe0e6('0x28')]=function(_0x272574,_0x1834cc,_0x45746c){_0x272574=_0x272574===undefined?_0xe0e6('0x29'):_0x272574;_0x1834cc=_0x1834cc===undefined?'5':_0x1834cc;_0x45746c=_0x45746c===undefined?'1':_0x45746c;return this[_0xe0e6('0x25')](util[_0xe0e6('0x2a')](_0xe0e6('0x2b'),_0x272574,_0x1834cc*0x3e8,_0x45746c));};AGIChannel[_0xe0e6('0x24')][_0xe0e6('0x2c')]=function(_0x447587){_0x447587=_0x447587||_0xe0e6('0x2d');return this['sendRequest'](util[_0xe0e6('0x2a')]('VERBOSE\x20\x22%s\x22',_0x447587));};AGIChannel[_0xe0e6('0x24')]['exec']=function(_0x6ecbd2,_0x3e55c7){if(_['isArray'](_0x3e55c7)){return this[_0xe0e6('0x25')](util['format'](_0xe0e6('0x2e'),_0x6ecbd2,_0x3e55c7[_0xe0e6('0x2f')](',')));}return this['sendRequest'](util[_0xe0e6('0x2a')](_0xe0e6('0x2e'),_0x6ecbd2,_0x3e55c7));};AGIChannel[_0xe0e6('0x24')][_0xe0e6('0x30')]=function(_0x38d536){return this[_0xe0e6('0x25')](util[_0xe0e6('0x2a')](_0xe0e6('0x31'),_0x38d536));};AGIChannel[_0xe0e6('0x24')][_0xe0e6('0x32')]=function(_0x23f0d6){return this[_0xe0e6('0x25')](util[_0xe0e6('0x2a')]('SET\x20EXTENSION\x20%s',_0x23f0d6));};AGIChannel[_0xe0e6('0x24')][_0xe0e6('0x33')]=function(_0x39caeb){return this[_0xe0e6('0x25')](util['format']('SET\x20PRIORITY\x20%s',_0x39caeb));};AGIChannel['prototype'][_0xe0e6('0xc')]=function(){return this['sendRequest']('HANGUP');};AGIChannel[_0xe0e6('0x24')][_0xe0e6('0x34')]=function(_0x1aebbc,_0x2480da){var _0x5466bf=_['isBoolean'](_0x2480da)||_[_0xe0e6('0x35')](_0x2480da)?_0x2480da[_0xe0e6('0x36')]():_0x2480da;return this[_0xe0e6('0x25')](util['format'](_0xe0e6('0x37'),_0x1aebbc,_0x5466bf?_0x5466bf[_0xe0e6('0x36')]()['replace'](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xe0e6('0x24')][_0xe0e6('0x38')]=function(_0x186e85,_0x4abfaf){return this[_0xe0e6('0x25')](util['format'](_0xe0e6('0x39'),_0x186e85,_0x4abfaf));};AGIChannel['prototype'][_0xe0e6('0x3a')]=function(_0xaa1156,_0x1c5ac4){return this[_0xe0e6('0x25')](util[_0xe0e6('0x2a')](_0xe0e6('0x3b'),_0xaa1156,_0x1c5ac4));};AGIChannel[_0xe0e6('0x24')]['sayPhonetic']=function(_0x4e2258,_0x15f69c){return this[_0xe0e6('0x25')](util['format']('SAY\x20PHONETIC\x20\x22%s\x22\x20%s',_0x4e2258,_0x15f69c));};AGIChannel[_0xe0e6('0x24')][_0xe0e6('0x3c')]=function(_0xa2caff,_0x7923db,_0x4089e5){_0x7923db=_0x7923db||this[_0xe0e6('0x3d')];_0x4089e5=_0x4089e5||0x1;this[_0xe0e6('0x30')](_0xa2caff);this['setExtension'](_0x7923db);this[_0xe0e6('0x33')](_0x4089e5);return this[_0xe0e6('0x2c')](util[_0xe0e6('0x2a')](_0xe0e6('0x3e'),_0xa2caff,_0x7923db,_0x4089e5));};AGIChannel[_0xe0e6('0x24')][_0xe0e6('0x3f')]=function(_0x42d906){return this[_0xe0e6('0x25')](util[_0xe0e6('0x2a')]('GET\x20VARIABLE\x20\x22%s\x22',_0x42d906));};AGIChannel['prototype'][_0xe0e6('0x40')]=function(_0x16b3d0,_0x1ecb11,_0x220253,_0xf71c94,_0x46777c,_0x547b6d){_0x1ecb11=_0x1ecb11||_0xe0e6('0x41');_0x220253=_0x220253||'';_0xf71c94=_0xf71c94===undefined?-0x1:_0xf71c94==='-1'?-0x1:_0xf71c94*0x3e8;_0x46777c=_0x46777c===undefined?'':'s='+_0x46777c;_0x547b6d=_0x547b6d?_0xe0e6('0x42'):'';return this[_0xe0e6('0x25')](util[_0xe0e6('0x2a')](_0xe0e6('0x43'),_0x16b3d0,_0x1ecb11,_0x220253,_0xf71c94,_0x547b6d,_0x46777c));};AGIChannel['prototype']['streamFile']=function(_0xa692c4,_0x261bae){_0x261bae=_0x261bae||'';return this[_0xe0e6('0x25')](util[_0xe0e6('0x2a')]('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0xa692c4,_0x261bae));};AGIChannel[_0xe0e6('0x24')][_0xe0e6('0x44')]=function(_0x2c9f86){return this[_0xe0e6('0x45')](_0xe0e6('0x46'),_0x2c9f86);};AGIChannel['prototype']['wait']=function(_0x21972c){return this['exec']('WAIT',_0x21972c);};AGIChannel['prototype'][_0xe0e6('0x1a')]=function(_0x111e04,_0x238562){this[_0xe0e6('0x2c')](util['format'](_0xe0e6('0x47'),_0x111e04['id'],_0x111e04['label'],_0x238562));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xe0e6('0x48')]=AGIChannel;