Built motion from commit (unavailable).|2.5.4
[motion2.git] / server / services / ami / trigger / integration / freshsales.js
index c39f051..eeb676b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x77f7=['recordingFormat','none','[OUTBOUND]','The\x20ticket\x20ID\x20is:\x20%s','Displaying\x20task\x20in\x20a\x20new\x20tab...',']\x20Error\x20running\x20Freshsales\x20integration','inspect','lodash','request-promise','md5','util','moment','bluebird','ioredis','./util','../../../../config/environment','redis','defaults','localhost','socket.io-emitter','GET','headers','info','Getting\x20admin\x20information','users','length','email','adminId','Requested\x20Resource\x20not\x20Found','catch','error','toUpperCase','Getting\x20user\x20list','then','agentEmail','Getting\x20user\x20with\x20email','userEmail','User\x20found:','adminEmail','userId','/api/contacts/filters','Getting\x20contacts\x20filter','filters','forEach','name','All\x20Contacts','Getting\x20contact\x20list','Searching\x20contact\x20with\x20phone','contactNumber','contacts','mobile_number','endUserId','Contact\x20found:','Contact\x20created:','message','/api/contacts','format','YYYY-MM-DDTHH:mm:ss','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','Creating\x20new\x20task','POST','/api/tasks','getString','Subjects','Descriptions','Contact','add','ticketId','task','Task\x20created:','user:%s','emit','trigger:browser:url','Token\x20token=','apiKey','remoteUri','stripTrailingSlash','serverUrl','username','toLowerCase','destcalleridnum','calleridnum','callDirection','queue','unmanaged','outbound','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL'];(function(_0x5360aa,_0x5b840d){var _0x198de6=function(_0x440da6){while(--_0x440da6){_0x5360aa['push'](_0x5360aa['shift']());}};_0x198de6(++_0x5b840d);}(_0x77f7,0xbd));var _0x777f=function(_0x5e475d,_0x198b2b){_0x5e475d=_0x5e475d-0x0;var _0x53e10e=_0x77f7[_0x5e475d];return _0x53e10e;};'use strict';var _=require(_0x777f('0x0'));var rp=require(_0x777f('0x1'));var md5=require(_0x777f('0x2'));var util=require(_0x777f('0x3'));var moment=require(_0x777f('0x4'));var Promise=require(_0x777f('0x5'));var Redis=require(_0x777f('0x6'));var intUtil=require(_0x777f('0x7'));var config=require(_0x777f('0x8'));var logger=require('../../../../config/logger')('freshsales');config[_0x777f('0x9')]=_[_0x777f('0xa')](config[_0x777f('0x9')],{'host':_0x777f('0xb'),'port':0x18eb});var io=require(_0x777f('0xc'))(new Redis(config[_0x777f('0x9')]));function getAdminId(_0x12bff6,_0x27e9ee,_0x2ba1a5,_0x478e59){return new Promise(function(_0x4edde5,_0xd2273){var _0x5c218b=![];var _0x26e215={'method':_0x777f('0xd'),'uri':_0x478e59+'/api/selector/owners','json':!![]};_0x26e215[_0x777f('0xe')]=_0x2ba1a5;logger[_0x777f('0xf')](_0x777f('0x10'));return rp(_0x26e215)['then'](function(_0x4f6746){if(_0x4f6746){var _0xaa421a=_0x4f6746[_0x777f('0x11')];var _0x30f31b=null;for(_0x30f31b=0x0;_0x30f31b<_0xaa421a[_0x777f('0x12')];_0x30f31b++){if(_0xaa421a[_0x30f31b][_0x777f('0x13')]===_0x12bff6['adminEmail']){_0x12bff6[_0x777f('0x14')]=_0xaa421a[_0x30f31b]['id'];_0x5c218b=!![];}}if(_0x5c218b){logger[_0x777f('0xf')]('Admin\x20found:',_0x12bff6[_0x777f('0x14')]);_0x4edde5(_0x12bff6);}else{_0xd2273({'statusCode':0x194,'message':_0x777f('0x15')});}}else{_0xd2273({'statusCode':0x194,'message':_0x777f('0x15')});}})[_0x777f('0x16')](function(_0xf4d60b){logger[_0x777f('0x17')]('['+[_0x27e9ee[_0x777f('0x18')]()]+']',_0xf4d60b['message']);_0xd2273(_0xf4d60b);});});}function getUser(_0x856923,_0x3f6143,_0x1e2af5){return function(_0x1ef1c5){return new Promise(function(_0x361759,_0x3aeb58){var _0x4038e2={'method':'GET','uri':_0x1e2af5+'/api/selector/owners','json':!![]};_0x4038e2[_0x777f('0xe')]=_0x3f6143;logger[_0x777f('0xf')](_0x777f('0x19'));return rp(_0x4038e2)[_0x777f('0x1a')](function(_0xa0c7f1){if(_0xa0c7f1){var _0x1c4b0f=_0xa0c7f1[_0x777f('0x11')];var _0x143f3d=![];var _0x5d31f1=null;if(_0x1ef1c5[_0x777f('0x1b')]!==null){logger['info'](_0x777f('0x1c'),_0x1ef1c5[_0x777f('0x1b')]);_0x1ef1c5[_0x777f('0x1d')]=_0x1ef1c5[_0x777f('0x1b')];for(_0x5d31f1=0x0;_0x5d31f1<_0x1c4b0f[_0x777f('0x12')];_0x5d31f1++){if(_0x1c4b0f[_0x5d31f1][_0x777f('0x13')]===_0x1ef1c5[_0x777f('0x1b')]){_0x143f3d=!![];_0x1ef1c5['userId']=_0x1c4b0f[_0x5d31f1]['id'];logger[_0x777f('0xf')](_0x777f('0x1e'),_0x1ef1c5['userId']);}}}if(!_0x143f3d){logger[_0x777f('0xf')]('Admin\x20selected');_0x1ef1c5[_0x777f('0x1d')]=_0x1ef1c5[_0x777f('0x1f')];_0x1ef1c5[_0x777f('0x20')]=_0x1ef1c5[_0x777f('0x14')];_0x143f3d=!![];}if(_0x143f3d){_0x361759(_0x1ef1c5);}else{_0x3aeb58({'statusCode':0x194,'message':_0x777f('0x15')});}}else{_0x3aeb58({'statusCode':0x194,'message':_0x777f('0x15')});}})[_0x777f('0x16')](function(_0x1c0984){logger[_0x777f('0x17')]('['+[_0x856923['toUpperCase']()]+']',_0x1c0984['message']);_0x3aeb58(_0x1c0984);});});};}function getEndUser(_0x16ca18,_0x37655d,_0x419735){return function(_0x1e7a4b){return new Promise(function(_0x16222c,_0x32007e){var _0x221dda=0x0;var _0x5b0504={'method':_0x777f('0xd'),'uri':_0x419735+_0x777f('0x21'),'json':!![]};_0x5b0504['headers']=_0x37655d;logger[_0x777f('0xf')](_0x777f('0x22'));return rp(_0x5b0504)['then'](function(_0x502924){_0x502924[_0x777f('0x23')][_0x777f('0x24')](function(_0x164792){if(_0x164792[_0x777f('0x25')]===_0x777f('0x26')){_0x221dda=_0x164792['id'];}});})[_0x777f('0x1a')](function(){logger[_0x777f('0xf')](_0x777f('0x27'));var _0x428577={'method':_0x777f('0xd'),'uri':_0x419735+'/api/contacts/view/'+_0x221dda,'json':!![]};_0x428577[_0x777f('0xe')]=_0x37655d;return rp(_0x428577);})[_0x777f('0x1a')](function(_0x38f032){logger[_0x777f('0xf')](_0x777f('0x28'),_0x1e7a4b[_0x777f('0x29')]);if(_0x38f032['contacts'][_0x777f('0x12')]>0x0){var _0x3c19af=_['find'](_0x38f032[_0x777f('0x2a')],function(_0x4e3d35){if(_0x4e3d35['work_number']===_0x1e7a4b[_0x777f('0x29')]||_0x4e3d35[_0x777f('0x2b')]===_0x1e7a4b[_0x777f('0x29')]){return _0x4e3d35;}});if(_0x3c19af){_0x1e7a4b[_0x777f('0x2c')]=_0x3c19af['id'];logger[_0x777f('0xf')](_0x777f('0x2d'),_0x1e7a4b[_0x777f('0x2c')]);_0x16222c(_0x1e7a4b);}else{return createEndUser(_0x1e7a4b,_0x16ca18,_0x37655d,_0x419735)[_0x777f('0x1a')](function(_0x4cd252){logger['info'](_0x777f('0x2e'),_0x1e7a4b[_0x777f('0x2c')]);_0x16222c(_0x4cd252);});}}else{return createEndUser(_0x1e7a4b,_0x16ca18,_0x37655d,_0x419735)[_0x777f('0x1a')](function(_0x23d1e5){logger[_0x777f('0xf')](_0x777f('0x2e'),_0x1e7a4b[_0x777f('0x2c')]);_0x16222c(_0x23d1e5);});}})[_0x777f('0x16')](function(_0x5f33e6){throw new Error(_0x5f33e6[_0x777f('0x2f')]);});});};}function createEndUser(_0x2f7007,_0x3e3780,_0x2975a3,_0x18f6a5){return new Promise(function(_0x351912,_0x2faf9e){var _0x1f32ad=moment();var _0x4d1a32={'method':'POST','uri':_0x18f6a5+_0x777f('0x30'),'body':{'contact':{'last_name':_0x2f7007['contactNumber'],'work_number':_0x2f7007[_0x777f('0x29')],'mobile_number':_0x2f7007[_0x777f('0x29')],'owner_id':_0x2f7007[_0x777f('0x20')],'created_at':_0x1f32ad[_0x777f('0x31')](_0x777f('0x32'))}},'json':!![]};_0x4d1a32['headers']=_0x2975a3;logger[_0x777f('0xf')](_0x777f('0x33'));return rp(_0x4d1a32)[_0x777f('0x1a')](function(_0x3a5d34){_0x2f7007[_0x777f('0x2c')]=_0x3a5d34['contact']['id'];_0x351912(_0x2f7007);})[_0x777f('0x16')](function(_0x26cefc){logger[_0x777f('0x17')]('['+[_0x3e3780[_0x777f('0x18')]()]+']',_0x26cefc[_0x777f('0x2f')]);_0x2faf9e(_0x26cefc[_0x777f('0x2f')]);});});}function getTicket(_0xd81621,_0x2f3464,_0x5e4fc2,_0x4bf42e,_0x2924e9){return function(_0x4a4eb6){logger['info'](_0x777f('0x34'));return new Promise(function(_0x1ce6b4,_0x26caff){var _0x5a94c9=moment();var _0x5aa4bb={'method':_0x777f('0x35'),'uri':_0x5e4fc2+_0x777f('0x36'),'body':{'title':intUtil[_0x777f('0x37')](_0x4bf42e[_0x777f('0x38')],_0x2924e9,'\x20'),'description':intUtil['getString'](_0x4bf42e[_0x777f('0x39')],_0x2924e9,'\x0a'),'owner_id':_0x4a4eb6[_0x777f('0x20')],'creater_id':_0x4a4eb6[_0x777f('0x14')],'targetable_id':_0x4a4eb6[_0x777f('0x2c')],'targetable_type':_0x777f('0x3a'),'created_at':_0x5a94c9[_0x777f('0x31')](_0x777f('0x32')),'due_date':_0x5a94c9[_0x777f('0x3b')](0x1e,'m')[_0x777f('0x31')](_0x777f('0x32'))},'json':!![]};_0x5aa4bb[_0x777f('0xe')]=_0x2f3464;return rp(_0x5aa4bb)[_0x777f('0x1a')](function(_0x3e82c3){_0x4a4eb6[_0x777f('0x3c')]=_0x3e82c3[_0x777f('0x3d')]['id'];logger['info'](_0x777f('0x3e'),_0x4a4eb6[_0x777f('0x3c')]);_0x1ce6b4(_0x4a4eb6);})[_0x777f('0x16')](function(_0x317d5e){logger['error']('['+[_0xd81621[_0x777f('0x18')]()]+']',_0x317d5e[_0x777f('0x2f')]);_0x26caff(_0x317d5e[_0x777f('0x2f')]);});});};}function emit(_0x5bf137,_0x486664,_0x364d41){var _0x521d62={'uri':_0x5bf137+'/contacts/'+_0x364d41};io['to'](util[_0x777f('0x31')](_0x777f('0x3f'),_0x486664))[_0x777f('0x40')](_0x777f('0x41'),_0x521d62);}exports['cs']=function(_0x3ba76d,_0x45ea24,_0x5d428,_0x366a8c,_0x510fba,_0x85e724,_0xc5e862,_0x20d57c){var _0x318ed3={};var _0xc76983={'Authorization':_0x777f('0x42')+_0x85e724[_0x777f('0x43')]};_0x85e724[_0x777f('0x44')]=intUtil[_0x777f('0x45')](_0x85e724[_0x777f('0x44')]);_0x85e724[_0x777f('0x46')]=intUtil[_0x777f('0x45')](_0x85e724[_0x777f('0x46')]);var _0x9e1545=_0x85e724[_0x777f('0x44')];_0x318ed3[_0x777f('0x1f')]=_0x85e724[_0x777f('0x47')];_0x318ed3['contactNumber']=_0x20d57c[_0x777f('0x48')]()==='outbound'?_0x45ea24[_0x777f('0x49')]:_0x45ea24[_0x777f('0x4a')];_0x318ed3[_0x777f('0x4b')]=_0x20d57c===_0x777f('0x4c')||_0x20d57c===_0x777f('0x4d')?_0x777f('0x4c'):_0x777f('0x4e');if(_0x366a8c){_0x318ed3[_0x777f('0x1b')]=_0x366a8c[_0x777f('0x13')];}var _0xcab481=util[_0x777f('0x31')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x85e724[_0x777f('0x46')],_0x45ea24['uniqueid'],md5(_0x45ea24[_0x777f('0x4f')]));if(_0x510fba&&_0x510fba[_0x777f('0x50')]){logger[_0x777f('0xf')](_0x777f('0x51'),_0x777f('0x52'));_0x45ea24[_0x777f('0x53')]=_0xcab481;}else if(_0xc5e862&&_0xc5e862[_0x777f('0x54')]&&_0xc5e862[_0x777f('0x54')]!==_0x777f('0x55')){logger[_0x777f('0xf')](_0x777f('0x56'),_0x777f('0x52'));_0x45ea24['recordingURL']=_0xcab481;}else{_0x45ea24[_0x777f('0x53')]='';}return getAdminId(_0x318ed3,_0x20d57c,_0xc76983,_0x9e1545)['then'](getUser(_0x20d57c,_0xc76983,_0x9e1545))[_0x777f('0x1a')](getEndUser(_0x20d57c,_0xc76983,_0x9e1545))['then'](getTicket(_0x20d57c,_0xc76983,_0x9e1545,_0x5d428,_0x45ea24))['then'](function(_0x533492){logger[_0x777f('0xf')](util[_0x777f('0x31')](_0x777f('0x57'),_0x533492[_0x777f('0x3c')]));if(_0x20d57c!=='unmanaged'){logger[_0x777f('0xf')]('['+[_0x20d57c['toUpperCase']()]+']',_0x777f('0x58'));emit(_0x9e1545,_0x366a8c[_0x777f('0x25')],_0x533492[_0x777f('0x2c')]);}})[_0x777f('0x16')](function(_0x3cd815){logger[_0x777f('0x17')]('['+[_0x20d57c[_0x777f('0x18')]()]+_0x777f('0x59'),util[_0x777f('0x5a')](_0x3cd815,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0xcfc7=['Admin\x20found:','catch','error','toUpperCase','message','agentEmail','Getting\x20user\x20with\x20email','userEmail','userId','User\x20found:','Admin\x20selected','adminEmail','Requested\x20Resource\x20not\x20Found','Getting\x20contacts\x20filter','filters','forEach','Searching\x20contact\x20with\x20phone','contactNumber','contacts','find','work_number','mobile_number','endUserId','Contact\x20created:','POST','/api/contacts','format','YYYY-MM-DDTHH:mm:ss','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','contact','/api/tasks','getString','Subjects','Descriptions','Contact','add','ticketId','Task\x20created:','/contacts/','user:%s','trigger:browser:url','remoteUri','stripTrailingSlash','serverUrl','username','toLowerCase','outbound','destcalleridnum','calleridnum','queue','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingFormat','none','[OUTBOUND]','recordingURL','The\x20ticket\x20ID\x20is:\x20%s','unmanaged','Displaying\x20task\x20in\x20a\x20new\x20tab...','name',']\x20Error\x20running\x20Freshsales\x20integration','inspect','request-promise','md5','util','moment','../../../../config/environment','../../../../config/logger','redis','localhost','socket.io-emitter','GET','/api/selector/owners','headers','Getting\x20admin\x20information','then','users','length','email','adminId','info'];(function(_0x25c0aa,_0x34dd4a){var _0x28a1ab=function(_0x147466){while(--_0x147466){_0x25c0aa['push'](_0x25c0aa['shift']());}};_0x28a1ab(++_0x34dd4a);}(_0xcfc7,0x13d));var _0x7cfc=function(_0x524fc0,_0x1544f6){_0x524fc0=_0x524fc0-0x0;var _0x2469f2=_0xcfc7[_0x524fc0];return _0x2469f2;};'use strict';var _=require('lodash');var rp=require(_0x7cfc('0x0'));var md5=require(_0x7cfc('0x1'));var util=require(_0x7cfc('0x2'));var moment=require(_0x7cfc('0x3'));var Promise=require('bluebird');var Redis=require('ioredis');var intUtil=require('./util');var config=require(_0x7cfc('0x4'));var logger=require(_0x7cfc('0x5'))('freshsales');config[_0x7cfc('0x6')]=_['defaults'](config[_0x7cfc('0x6')],{'host':_0x7cfc('0x7'),'port':0x18eb});var io=require(_0x7cfc('0x8'))(new Redis(config[_0x7cfc('0x6')]));function getAdminId(_0x582a02,_0x59632c,_0x428628,_0x5b87fc){return new Promise(function(_0x103642,_0x2bc01a){var _0x164441=![];var _0x317a09={'method':_0x7cfc('0x9'),'uri':_0x5b87fc+_0x7cfc('0xa'),'json':!![]};_0x317a09[_0x7cfc('0xb')]=_0x428628;logger['info'](_0x7cfc('0xc'));return rp(_0x317a09)[_0x7cfc('0xd')](function(_0x522de0){if(_0x522de0){var _0x1ffe98=_0x522de0[_0x7cfc('0xe')];var _0x2fd14a=null;for(_0x2fd14a=0x0;_0x2fd14a<_0x1ffe98[_0x7cfc('0xf')];_0x2fd14a++){if(_0x1ffe98[_0x2fd14a][_0x7cfc('0x10')]===_0x582a02['adminEmail']){_0x582a02[_0x7cfc('0x11')]=_0x1ffe98[_0x2fd14a]['id'];_0x164441=!![];}}if(_0x164441){logger[_0x7cfc('0x12')](_0x7cfc('0x13'),_0x582a02[_0x7cfc('0x11')]);_0x103642(_0x582a02);}else{_0x2bc01a({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}}else{_0x2bc01a({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}})[_0x7cfc('0x14')](function(_0x2c2a28){logger[_0x7cfc('0x15')]('['+[_0x59632c[_0x7cfc('0x16')]()]+']',_0x2c2a28[_0x7cfc('0x17')]);_0x2bc01a(_0x2c2a28);});});}function getUser(_0x864256,_0x1eb04c,_0x15b49a){return function(_0x3904a7){return new Promise(function(_0x2f2320,_0x17d21a){var _0x592a42={'method':_0x7cfc('0x9'),'uri':_0x15b49a+_0x7cfc('0xa'),'json':!![]};_0x592a42[_0x7cfc('0xb')]=_0x1eb04c;logger[_0x7cfc('0x12')]('Getting\x20user\x20list');return rp(_0x592a42)[_0x7cfc('0xd')](function(_0x3edaba){if(_0x3edaba){var _0x4528ac=_0x3edaba['users'];var _0x234e09=![];var _0x3e0a60=null;if(_0x3904a7[_0x7cfc('0x18')]!==null){logger[_0x7cfc('0x12')](_0x7cfc('0x19'),_0x3904a7['agentEmail']);_0x3904a7[_0x7cfc('0x1a')]=_0x3904a7[_0x7cfc('0x18')];for(_0x3e0a60=0x0;_0x3e0a60<_0x4528ac[_0x7cfc('0xf')];_0x3e0a60++){if(_0x4528ac[_0x3e0a60]['email']===_0x3904a7[_0x7cfc('0x18')]){_0x234e09=!![];_0x3904a7[_0x7cfc('0x1b')]=_0x4528ac[_0x3e0a60]['id'];logger['info'](_0x7cfc('0x1c'),_0x3904a7['userId']);}}}if(!_0x234e09){logger[_0x7cfc('0x12')](_0x7cfc('0x1d'));_0x3904a7[_0x7cfc('0x1a')]=_0x3904a7[_0x7cfc('0x1e')];_0x3904a7[_0x7cfc('0x1b')]=_0x3904a7[_0x7cfc('0x11')];_0x234e09=!![];}if(_0x234e09){_0x2f2320(_0x3904a7);}else{_0x17d21a({'statusCode':0x194,'message':_0x7cfc('0x1f')});}}else{_0x17d21a({'statusCode':0x194,'message':_0x7cfc('0x1f')});}})['catch'](function(_0x42957d){logger['error']('['+[_0x864256[_0x7cfc('0x16')]()]+']',_0x42957d['message']);_0x17d21a(_0x42957d);});});};}function getEndUser(_0x32d7fd,_0x5a3e56,_0x476bb2){return function(_0x22db89){return new Promise(function(_0x5056c0,_0x279353){var _0x3194e3=0x0;var _0x2a5173={'method':_0x7cfc('0x9'),'uri':_0x476bb2+'/api/contacts/filters','json':!![]};_0x2a5173[_0x7cfc('0xb')]=_0x5a3e56;logger[_0x7cfc('0x12')](_0x7cfc('0x20'));return rp(_0x2a5173)[_0x7cfc('0xd')](function(_0x1c9211){_0x1c9211[_0x7cfc('0x21')][_0x7cfc('0x22')](function(_0x28d10a){if(_0x28d10a['name']==='All\x20Contacts'){_0x3194e3=_0x28d10a['id'];}});})[_0x7cfc('0xd')](function(){logger[_0x7cfc('0x12')]('Getting\x20contact\x20list');var _0x29cda1={'method':'GET','uri':_0x476bb2+'/api/contacts/view/'+_0x3194e3,'json':!![]};_0x29cda1[_0x7cfc('0xb')]=_0x5a3e56;return rp(_0x29cda1);})[_0x7cfc('0xd')](function(_0x329cbd){logger[_0x7cfc('0x12')](_0x7cfc('0x23'),_0x22db89[_0x7cfc('0x24')]);if(_0x329cbd[_0x7cfc('0x25')]['length']>0x0){var _0x3304e4=_[_0x7cfc('0x26')](_0x329cbd[_0x7cfc('0x25')],function(_0x59da36){if(_0x59da36[_0x7cfc('0x27')]===_0x22db89[_0x7cfc('0x24')]||_0x59da36[_0x7cfc('0x28')]===_0x22db89[_0x7cfc('0x24')]){return _0x59da36;}});if(_0x3304e4){_0x22db89[_0x7cfc('0x29')]=_0x3304e4['id'];logger[_0x7cfc('0x12')]('Contact\x20found:',_0x22db89[_0x7cfc('0x29')]);_0x5056c0(_0x22db89);}else{return createEndUser(_0x22db89,_0x32d7fd,_0x5a3e56,_0x476bb2)['then'](function(_0x41c253){logger[_0x7cfc('0x12')](_0x7cfc('0x2a'),_0x22db89[_0x7cfc('0x29')]);_0x5056c0(_0x41c253);});}}else{return createEndUser(_0x22db89,_0x32d7fd,_0x5a3e56,_0x476bb2)['then'](function(_0x8d6c02){logger['info'](_0x7cfc('0x2a'),_0x22db89['endUserId']);_0x5056c0(_0x8d6c02);});}})[_0x7cfc('0x14')](function(_0x367a15){throw new Error(_0x367a15[_0x7cfc('0x17')]);});});};}function createEndUser(_0x417ccf,_0x1a5bc2,_0x17fe54,_0x1753e1){return new Promise(function(_0x3b2b58,_0x1a4168){var _0x50529e=moment();var _0x2a6423={'method':_0x7cfc('0x2b'),'uri':_0x1753e1+_0x7cfc('0x2c'),'body':{'contact':{'last_name':_0x417ccf['contactNumber'],'work_number':_0x417ccf[_0x7cfc('0x24')],'mobile_number':_0x417ccf[_0x7cfc('0x24')],'owner_id':_0x417ccf['userId'],'created_at':_0x50529e[_0x7cfc('0x2d')](_0x7cfc('0x2e'))}},'json':!![]};_0x2a6423[_0x7cfc('0xb')]=_0x17fe54;logger['info'](_0x7cfc('0x2f'));return rp(_0x2a6423)[_0x7cfc('0xd')](function(_0x2e6728){_0x417ccf[_0x7cfc('0x29')]=_0x2e6728[_0x7cfc('0x30')]['id'];_0x3b2b58(_0x417ccf);})[_0x7cfc('0x14')](function(_0x4dc36c){logger[_0x7cfc('0x15')]('['+[_0x1a5bc2[_0x7cfc('0x16')]()]+']',_0x4dc36c['message']);_0x1a4168(_0x4dc36c[_0x7cfc('0x17')]);});});}function getTicket(_0x5a7b16,_0x476b69,_0x4f4bba,_0x4529c5,_0x582d19){return function(_0x2b219d){logger['info']('Creating\x20new\x20task');return new Promise(function(_0x1fdfa6,_0x3136cc){var _0x508f1d=moment();var _0x1b3d0a={'method':_0x7cfc('0x2b'),'uri':_0x4f4bba+_0x7cfc('0x31'),'body':{'title':intUtil[_0x7cfc('0x32')](_0x4529c5[_0x7cfc('0x33')],_0x582d19,'\x20'),'description':intUtil['getString'](_0x4529c5[_0x7cfc('0x34')],_0x582d19,'\x0a'),'owner_id':_0x2b219d[_0x7cfc('0x1b')],'creater_id':_0x2b219d[_0x7cfc('0x11')],'targetable_id':_0x2b219d['endUserId'],'targetable_type':_0x7cfc('0x35'),'created_at':_0x508f1d[_0x7cfc('0x2d')]('YYYY-MM-DDTHH:mm:ss'),'due_date':_0x508f1d[_0x7cfc('0x36')](0x1e,'m')[_0x7cfc('0x2d')](_0x7cfc('0x2e'))},'json':!![]};_0x1b3d0a[_0x7cfc('0xb')]=_0x476b69;return rp(_0x1b3d0a)[_0x7cfc('0xd')](function(_0x22a6f1){_0x2b219d[_0x7cfc('0x37')]=_0x22a6f1['task']['id'];logger[_0x7cfc('0x12')](_0x7cfc('0x38'),_0x2b219d['ticketId']);_0x1fdfa6(_0x2b219d);})[_0x7cfc('0x14')](function(_0x2299ab){logger['error']('['+[_0x5a7b16['toUpperCase']()]+']',_0x2299ab[_0x7cfc('0x17')]);_0x3136cc(_0x2299ab[_0x7cfc('0x17')]);});});};}function emit(_0x33e4d2,_0x50cd05,_0x3b18f9){var _0x586199={'uri':_0x33e4d2+_0x7cfc('0x39')+_0x3b18f9};io['to'](util[_0x7cfc('0x2d')](_0x7cfc('0x3a'),_0x50cd05))['emit'](_0x7cfc('0x3b'),_0x586199);}exports['cs']=function(_0x5555bd,_0x29f043,_0xdbf849,_0x26b70d,_0x2b6286,_0x47931b,_0x504072,_0x131e3a){var _0x5a10c1={};var _0x210ebb={'Authorization':'Token\x20token='+_0x47931b['apiKey']};_0x47931b[_0x7cfc('0x3c')]=intUtil[_0x7cfc('0x3d')](_0x47931b['remoteUri']);_0x47931b[_0x7cfc('0x3e')]=intUtil[_0x7cfc('0x3d')](_0x47931b[_0x7cfc('0x3e')]);var _0x41d5d5=_0x47931b[_0x7cfc('0x3c')];_0x5a10c1[_0x7cfc('0x1e')]=_0x47931b[_0x7cfc('0x3f')];_0x5a10c1[_0x7cfc('0x24')]=_0x131e3a[_0x7cfc('0x40')]()===_0x7cfc('0x41')?_0x29f043[_0x7cfc('0x42')]:_0x29f043[_0x7cfc('0x43')];_0x5a10c1['callDirection']=_0x131e3a==='queue'||_0x131e3a==='unmanaged'?_0x7cfc('0x44'):'outbound';if(_0x26b70d){_0x5a10c1['agentEmail']=_0x26b70d[_0x7cfc('0x10')];}var _0x540172=util[_0x7cfc('0x2d')](_0x7cfc('0x45'),_0x47931b[_0x7cfc('0x3e')],_0x29f043[_0x7cfc('0x46')],md5(_0x29f043['uniqueid']));if(_0x2b6286&&_0x2b6286[_0x7cfc('0x47')]){logger[_0x7cfc('0x12')](_0x7cfc('0x48'),_0x7cfc('0x49'));_0x29f043['recordingURL']=_0x540172;}else if(_0x504072&&_0x504072[_0x7cfc('0x4a')]&&_0x504072['recordingFormat']!==_0x7cfc('0x4b')){logger['info'](_0x7cfc('0x4c'),_0x7cfc('0x49'));_0x29f043['recordingURL']=_0x540172;}else{_0x29f043[_0x7cfc('0x4d')]='';}return getAdminId(_0x5a10c1,_0x131e3a,_0x210ebb,_0x41d5d5)[_0x7cfc('0xd')](getUser(_0x131e3a,_0x210ebb,_0x41d5d5))['then'](getEndUser(_0x131e3a,_0x210ebb,_0x41d5d5))[_0x7cfc('0xd')](getTicket(_0x131e3a,_0x210ebb,_0x41d5d5,_0xdbf849,_0x29f043))[_0x7cfc('0xd')](function(_0x3b692c){logger[_0x7cfc('0x12')](util['format'](_0x7cfc('0x4e'),_0x3b692c[_0x7cfc('0x37')]));if(_0x131e3a!==_0x7cfc('0x4f')){logger[_0x7cfc('0x12')]('['+[_0x131e3a['toUpperCase']()]+']',_0x7cfc('0x50'));emit(_0x41d5d5,_0x26b70d[_0x7cfc('0x51')],_0x3b692c[_0x7cfc('0x29')]);}})[_0x7cfc('0x14')](function(_0x1a6b38){logger[_0x7cfc('0x15')]('['+[_0x131e3a[_0x7cfc('0x16')]()]+_0x7cfc('0x52'),util[_0x7cfc('0x53')](_0x1a6b38,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file