a4542821a5ec5e261aaeb5bc05a046015ebff949
[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 _0x46aa=['error','emit','E_AGI_SOCKET_ERROR','close','E_AGI_SOCKET_CLOSE','timeout','destroy','pipe','command','inherits','prototype','sendRequest','sync','answer','ANSWER','getData','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','VERBOSE\x20\x22%s\x22','exec','EXEC\x20%s\x20%s','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','isBoolean','isNumber','SET\x20VARIABLE\x20%s\x20\x22%s\x22','toString','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','GOTO\x20%s\x20%s\x20%s','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','streamFile','AGI','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','exports','lodash','EventEmitter','./reply','./error','call','setEncoding','utf8','setTimeout','headers','ready','line','toLowerCase','hangup','substring','search','520\x20End\x20of\x20proper','function','no\x20code','replace','result=','indexOf','substr','startsWith','split','length'];(function(_0x4609a2,_0x3292df){var _0x347de7=function(_0x2d81fc){while(--_0x2d81fc){_0x4609a2['push'](_0x4609a2['shift']());}};_0x347de7(++_0x3292df);}(_0x46aa,0xcb));var _0xa46a=function(_0x11c573,_0x9e7c6e){_0x11c573=_0x11c573-0x0;var _0x6b72de=_0x46aa[_0x11c573];return _0x6b72de;};'use strict';var util=require('util');var _=require(_0xa46a('0x0'));var EventEmitter=require('events')[_0xa46a('0x1')];var AGIReply=require(_0xa46a('0x2'));var AGIError=require(_0xa46a('0x3'));function AGIChannel(_0x1ec29a){var _0x43f37c=this,_0x2c622e=new AGIReply(),_0x904ab4=![],_0x2e3ab3={};EventEmitter[_0xa46a('0x4')](_0x43f37c);_0x1ec29a[_0xa46a('0x5')](_0xa46a('0x6'));_0x1ec29a[_0xa46a('0x7')](0x8*0x3c*0x3c*0x3e8);_0x2c622e['setEncoding'](_0xa46a('0x6'));_0x2c622e['on'](_0xa46a('0x8'),function(_0x4f2bbf){for(var _0x814320 in _0x4f2bbf){_0x43f37c[_0x814320]=_0x4f2bbf[_0x814320];}_0x43f37c['emit'](_0xa46a('0x9'));});_0x2c622e['on'](_0xa46a('0xa'),function(_0x41f491){if(_0x41f491[_0xa46a('0xb')]()==_0xa46a('0xc')){_0x43f37c['emit'](_0xa46a('0xc'));return;}if(_0x41f491[_0xa46a('0xd')](0x0,0xb)=='520-Invalid'){_0x904ab4=!![];}if(_0x904ab4){_0x2e3ab3['rx']+=_0x41f491+'\x0a';if(_0x41f491[_0xa46a('0xe')](_0xa46a('0xf'))!=-0x1){_0x904ab4=![];}}else{_0x2e3ab3['rx']=_0x41f491;}if(_0x904ab4){return;}if(typeof _0x2e3ab3['cb']==_0xa46a('0x10')){var _0x3f9fe1=_0x2e3ab3['rx'][_0xa46a('0xd')](0x0,0x3),_0x2720c4=null,_0x2eda0b=null;_0x3f9fe1=parseInt(_0x3f9fe1);if(isNaN(_0x3f9fe1)){_0x2e3ab3['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xa46a('0x11')});return;}if(_0x3f9fe1!=0xc8){_0x2e3ab3['cb'](null,{'code':_0x3f9fe1,'result':-0x1,'extra':'KO'});return;}_0x2720c4=_0x2e3ab3['rx'][_0xa46a('0xd')](0x4)[_0xa46a('0x12')](_0xa46a('0x13'),'');if(_0x2720c4[_0xa46a('0x14')]('\x20')!=-0x1){_0x2720c4=_0x2720c4[_0xa46a('0x15')](0x0,_0x2720c4[_0xa46a('0x14')]('\x20'));}if(_[_0xa46a('0x16')](_0x2720c4,'-1')){_0x2720c4=parseInt(_0x2720c4);}_0x2eda0b=_0x2e3ab3['rx'][_0xa46a('0x17')]('\x20');if(_0x2eda0b[_0xa46a('0x18')]==0x3){_0x2eda0b=_0x2eda0b[0x2][_0xa46a('0xd')](0x1,_0x2eda0b[0x2][_0xa46a('0x18')]-0x1);}else if(_0x2eda0b[_0xa46a('0x18')]>0x3){var _0x35c92c=/\((.+)\)/;var _0x1257f4=_0x2e3ab3['rx']['match'](_0x35c92c);if(_0x1257f4){_0x2eda0b=_0x1257f4[0x1];}else{_0x2eda0b=null;}}else{_0x2eda0b=null;}_0x2e3ab3['cb'](null,{'code':_0x3f9fe1,'result':_0x2720c4,'extra':_0x2eda0b});}});_0x1ec29a['on'](_0xa46a('0x19'),function(_0x4fdc40){_0x43f37c[_0xa46a('0x1a')]('error',new AGIError(_0xa46a('0x1b'),_0x4fdc40['code']));});_0x1ec29a['on'](_0xa46a('0x1c'),function(){_0x43f37c['emit'](_0xa46a('0x1c'),new AGIError(_0xa46a('0x1d')));});_0x1ec29a['on']('timeout',function(){_0x43f37c[_0xa46a('0x1a')](_0xa46a('0x1e'),new AGIError('E_AGI_SOCKET_TIMEOUT'));_0x1ec29a[_0xa46a('0x1f')]();});_0x1ec29a[_0xa46a('0x20')](_0x2c622e);this[_0xa46a('0x21')]=function(_0x3ea530,_0x441837){var _0x3ea530=_0x3ea530||'',_0x441837=typeof _0x441837=='function'?_0x441837:new Function();_0x2e3ab3={'tx':_0x3ea530,'rx':'','cb':_0x441837};_0x1ec29a['write'](_0x3ea530+'\x0a');},this['close']=function(){_0x1ec29a[_0xa46a('0x1f')]();};}util[_0xa46a('0x22')](AGIChannel,EventEmitter);AGIChannel[_0xa46a('0x23')][_0xa46a('0x24')]=function(_0x63a557){return this[_0xa46a('0x21')][_0xa46a('0x25')](this,_0x63a557);};AGIChannel[_0xa46a('0x23')][_0xa46a('0x26')]=function(){return this[_0xa46a('0x24')](_0xa46a('0x27'));};AGIChannel['prototype'][_0xa46a('0x28')]=function(_0x5df4e7,_0x57dd1e,_0x2ec51a){_0x5df4e7=_0x5df4e7===undefined?_0xa46a('0x29'):_0x5df4e7;_0x57dd1e=_0x57dd1e===undefined?'5':_0x57dd1e;_0x2ec51a=_0x2ec51a===undefined?'1':_0x2ec51a;return this[_0xa46a('0x24')](util[_0xa46a('0x2a')](_0xa46a('0x2b'),_0x5df4e7,_0x57dd1e*0x3e8,_0x2ec51a));};AGIChannel[_0xa46a('0x23')][_0xa46a('0x2c')]=function(_0x1936fb){_0x1936fb=_0x1936fb||'NO\x20MESSAGE';return this['sendRequest'](util[_0xa46a('0x2a')](_0xa46a('0x2d'),_0x1936fb));};AGIChannel['prototype'][_0xa46a('0x2e')]=function(_0x4f7ba5,_0x28780c){if(_['isArray'](_0x28780c)){return this[_0xa46a('0x24')](util[_0xa46a('0x2a')](_0xa46a('0x2f'),_0x4f7ba5,_0x28780c['join'](',')));}return this[_0xa46a('0x24')](util[_0xa46a('0x2a')](_0xa46a('0x2f'),_0x4f7ba5,_0x28780c));};AGIChannel[_0xa46a('0x23')][_0xa46a('0x30')]=function(_0x4aed30){return this['sendRequest'](util['format'](_0xa46a('0x31'),_0x4aed30));};AGIChannel[_0xa46a('0x23')][_0xa46a('0x32')]=function(_0x242330){return this[_0xa46a('0x24')](util[_0xa46a('0x2a')](_0xa46a('0x33'),_0x242330));};AGIChannel[_0xa46a('0x23')][_0xa46a('0x34')]=function(_0xa1026){return this[_0xa46a('0x24')](util[_0xa46a('0x2a')](_0xa46a('0x35'),_0xa1026));};AGIChannel[_0xa46a('0x23')][_0xa46a('0xc')]=function(){return this[_0xa46a('0x24')]('HANGUP');};AGIChannel[_0xa46a('0x23')]['setVariable']=function(_0x39c612,_0x40930d){var _0x12adc6=_[_0xa46a('0x36')](_0x40930d)||_[_0xa46a('0x37')](_0x40930d)?_0x40930d['toString']():_0x40930d;return this[_0xa46a('0x24')](util['format'](_0xa46a('0x38'),_0x39c612,_0x12adc6?_0x12adc6[_0xa46a('0x39')]()[_0xa46a('0x12')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel['prototype'][_0xa46a('0x3a')]=function(_0x33d9b0,_0x5a0429){return this[_0xa46a('0x24')](util['format'](_0xa46a('0x3b'),_0x33d9b0,_0x5a0429));};AGIChannel['prototype'][_0xa46a('0x3c')]=function(_0x52e066,_0x507884){return this[_0xa46a('0x24')](util[_0xa46a('0x2a')]('SAY\x20DIGITS\x20%s\x20%s',_0x52e066,_0x507884));};AGIChannel[_0xa46a('0x23')][_0xa46a('0x3d')]=function(_0x55e060,_0x12ccc3){return this['sendRequest'](util[_0xa46a('0x2a')](_0xa46a('0x3e'),_0x55e060,_0x12ccc3));};AGIChannel['prototype'][_0xa46a('0x3f')]=function(_0x3501c2,_0x1bd8f2,_0xb043bd){_0x1bd8f2=_0x1bd8f2||this['extension'];_0xb043bd=_0xb043bd||0x1;this[_0xa46a('0x30')](_0x3501c2);this['setExtension'](_0x1bd8f2);this[_0xa46a('0x34')](_0xb043bd);return this[_0xa46a('0x2c')](util[_0xa46a('0x2a')](_0xa46a('0x40'),_0x3501c2,_0x1bd8f2,_0xb043bd));};AGIChannel[_0xa46a('0x23')][_0xa46a('0x41')]=function(_0x131c6d){return this[_0xa46a('0x24')](util[_0xa46a('0x2a')](_0xa46a('0x42'),_0x131c6d));};AGIChannel[_0xa46a('0x23')][_0xa46a('0x43')]=function(_0x398517,_0x54bbfb,_0x1d5811,_0x329015,_0x3cd4d1,_0x4af267){_0x54bbfb=_0x54bbfb||_0xa46a('0x44');_0x1d5811=_0x1d5811||'';_0x329015=_0x329015===undefined?-0x1:_0x329015==='-1'?-0x1:_0x329015*0x3e8;_0x3cd4d1=_0x3cd4d1===undefined?'':'s='+_0x3cd4d1;_0x4af267=_0x4af267?_0xa46a('0x45'):'';return this[_0xa46a('0x24')](util['format'](_0xa46a('0x46'),_0x398517,_0x54bbfb,_0x1d5811,_0x329015,_0x4af267,_0x3cd4d1));};AGIChannel['prototype'][_0xa46a('0x47')]=function(_0x2958d1,_0x23a047){_0x23a047=_0x23a047||'';return this[_0xa46a('0x24')](util['format']('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0x2958d1,_0x23a047));};AGIChannel[_0xa46a('0x23')]['agi']=function(_0x385775){return this[_0xa46a('0x2e')](_0xa46a('0x48'),_0x385775);};AGIChannel[_0xa46a('0x23')]['wait']=function(_0x1b545f){return this[_0xa46a('0x2e')](_0xa46a('0x49'),_0x1b545f);};AGIChannel['prototype'][_0xa46a('0x19')]=function(_0x6f05c2,_0xfb54cc){this['noop'](util[_0xa46a('0x2a')](_0xa46a('0x4a'),_0x6f05c2['id'],_0x6f05c2['label'],_0xfb54cc));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xa46a('0x4b')]=AGIChannel;