Built motion from commit (unavailable).|2.0.84
[motion2.git] / server / services / ami / trigger / integration / zoho.js
index c84ab5e..ed29140 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xbdb0=['trigger:browser:url','https://crm.%s/crm/EntityInfo.do?module=Calls&id=%s','recordingFormat','Recording\x20is\x20enabled!','destcalleridname','destcalleridnum','Outbound','[OUTBOUND]','catch','abandoned','monitor_format','[ABANDONED]','lodash','request-promise','md5','./util','xml2json','entities','moment','../../../../config/environment','zoho','defaults','localhost','socket.io-emitter','redis','emit','application/json','merge','inbound','outbound','starttime','format','YYYY-MM-DD\x20HH:mm:ss','getString','Fields','lastevent','called','Call\x20Result','Called','complete','connect','Answered','Rejected','talktime','Call\x20Duration','utc','mm:ss','endtime','diff','CONTACTID','LEADID','SEMODULE','Leads','SEID','<Calls><row\x20no=\x221\x22>','hasOwnProperty','<FL\x20val=\x22%s\x22>%s</FL>','encodeXML','POST','host','authToken','crmapi','then','parse','response','result','recorddetail','info','Call\x20created!','Error\x20on\x20call\x20creation:\x20','stringify','Getting\x20agent\x20with\x20email','GET','https://crm.%s/crm/private/json/Users/getUsers','AllUsers','users','find','user','Standard','Agent\x20found!','Using\x20the\x20admin\x20account!','Administrator','error','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','Searching\x20enduser\x20with\x20phone','https://crm.%s/crm/private/json/Contacts/searchRecords','((Phone:%s))','row','Contacts','length','val','content','https://crm.%s/crm/private/json/Leads/searchRecords','https://crm.%s/crm/private/xml/Leads/insertRecords','Enduser\x20created.','https://crm.%s/crm/private/json/Leads/getRecordById','Error\x20on\x20Lead\x20creation:\x20','Error\x20on\x20Lead\x20retrieve:\x20','debug','[HTTP]','forEach','type','string','idField','toString','variableName','customVariable','Variable','name','toLowerCase','indexOf','split','queue','[QUEUE]','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','serverUrl','uniqueid','recordingURL','email','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','Inbound','The\x20Call\x20ID\x20is:','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s'];(function(_0x31bee2,_0xbddb9c){var _0x11acfe=function(_0xdf65d2){while(--_0xdf65d2){_0x31bee2['push'](_0x31bee2['shift']());}};_0x11acfe(++_0xbddb9c);}(_0xbdb0,0x189));var _0x0bdb=function(_0x468a77,_0x1382be){_0x468a77=_0x468a77-0x0;var _0x2d1c33=_0xbdb0[_0x468a77];return _0x2d1c33;};'use strict';var _=require(_0x0bdb('0x0'));var rp=require(_0x0bdb('0x1'));var md5=require(_0x0bdb('0x2'));var util=require('util');var intUtil=require(_0x0bdb('0x3'));var parser=require(_0x0bdb('0x4'));var entities=require(_0x0bdb('0x5'));var moment=require(_0x0bdb('0x6'));var config=require(_0x0bdb('0x7'));var logger=require('../../../../config/logger')(_0x0bdb('0x8'));config['redis']=_[_0x0bdb('0x9')](config['redis'],{'host':_0x0bdb('0xa'),'port':0x18eb});var io=require(_0x0bdb('0xb'))(config[_0x0bdb('0xc')]);function emit(_0x3afa5e,_0x3889d4,_0xc8984d){io['to'](_0x3afa5e)[_0x0bdb('0xd')](_0x3889d4,_0xc8984d);}var headers={'Content-Type':'application/json','Accept':_0x0bdb('0xe')};function getCall(_0x5f5a16,_0x4cd1fc,_0x3306a5,_0x4a9579,_0x55ce82,_0x3712d4){logger['info']('Creating\x20new\x20call...');var _0x7870ce=_[_0x0bdb('0xf')]({'SMOWNERID':_0x4cd1fc['id'],'Call Type':_0x3712d4||_0x0bdb('0x10'),'Call Start Time':(_0x3712d4===_0x0bdb('0x11')?_0x55ce82[_0x0bdb('0x12')]:_0x55ce82['agentcalledAt'])||moment()[_0x0bdb('0x13')](_0x0bdb('0x14')),'Subject':intUtil[_0x0bdb('0x15')](_0x4a9579['Subjects'],_0x55ce82,'\x20'),'Description':intUtil['getString'](_0x4a9579['Descriptions'],_0x55ce82,'\x0a')},getCustomFields(_0x4a9579[_0x0bdb('0x16')],_0x55ce82));switch(_0x55ce82[_0x0bdb('0x17')]){case _0x0bdb('0x18'):_0x7870ce[_0x0bdb('0x19')]=_0x0bdb('0x1a');break;case _0x0bdb('0x1b'):case _0x0bdb('0x1c'):_0x7870ce[_0x0bdb('0x19')]=_0x0bdb('0x1d');break;case'rejected':_0x7870ce['Call\x20Result']=_0x0bdb('0x1e');break;case'abandoned':_0x7870ce['Call\x20Result']='Abandoned';break;default:}if(_0x55ce82[_0x0bdb('0x1f')]){_0x7870ce[_0x0bdb('0x20')]=moment[_0x0bdb('0x21')](parseInt(_0x55ce82['talktime'])*0x3e8)[_0x0bdb('0x13')](_0x0bdb('0x22'));}else if(_0x55ce82['answertime']&&_0x55ce82[_0x0bdb('0x23')]){_0x7870ce['Call\x20Duration']=moment[_0x0bdb('0x21')](moment(_0x55ce82['endtime'],_0x0bdb('0x14'))[_0x0bdb('0x24')](moment(_0x55ce82[_0x0bdb('0x12')],'YYYY-MM-DD\x20HH:mm:ss')))[_0x0bdb('0x13')](_0x0bdb('0x22'));}if(_0x3306a5['CONTACTID']){_0x7870ce[_0x0bdb('0x25')]=_0x3306a5[_0x0bdb('0x25')];}else if(_0x3306a5[_0x0bdb('0x26')]){_0x7870ce[_0x0bdb('0x27')]=_0x0bdb('0x28');_0x7870ce[_0x0bdb('0x29')]=_0x3306a5[_0x0bdb('0x26')];}var _0x128959=_0x0bdb('0x2a');for(var _0x41eb9a in _0x7870ce){if(_0x7870ce[_0x0bdb('0x2b')](_0x41eb9a)){_0x128959+=util[_0x0bdb('0x13')](_0x0bdb('0x2c'),entities[_0x0bdb('0x2d')](_0x41eb9a),entities['encodeXML'](_0x7870ce[_0x41eb9a]));}}_0x128959+='</row></Calls>';return request({'method':_0x0bdb('0x2e'),'uri':util['format']('https://crm.%s/crm/private/xml/Calls/insertRecords',_0x5f5a16[_0x0bdb('0x2f')]),'qs':{'authtoken':_0x5f5a16[_0x0bdb('0x30')],'scope':_0x0bdb('0x31'),'xmlData':_0x128959},'json':!![]})[_0x0bdb('0x32')](function(_0x6271d9){_0x6271d9=JSON[_0x0bdb('0x33')](parser['toJson'](_0x6271d9));if(_0x6271d9['response']){if(_0x6271d9[_0x0bdb('0x34')][_0x0bdb('0x35')]&&_0x6271d9['response']['result'][_0x0bdb('0x36')]){logger[_0x0bdb('0x37')](_0x0bdb('0x38'));return{'id':_0x6271d9[_0x0bdb('0x34')]['result']['recorddetail']['FL'][0x0]['$t']};}}throw new Error(_0x0bdb('0x39')+JSON[_0x0bdb('0x3a')](_0x6271d9));});}function getUser(_0x463045,_0x3cdd87){_0x3cdd87&&logger[_0x0bdb('0x37')](_0x0bdb('0x3b'),_0x3cdd87);return request({'method':_0x0bdb('0x3c'),'uri':util['format'](_0x0bdb('0x3d'),_0x463045['host']),'qs':{'type':_0x0bdb('0x3e'),'authtoken':_0x463045[_0x0bdb('0x30')],'scope':_0x0bdb('0x31')},'json':!![]})[_0x0bdb('0x32')](function(_0xba8d98){if(_0xba8d98[_0x0bdb('0x3f')]&&_0xba8d98[_0x0bdb('0x3f')]['user']){var _0x496844;if(_0x3cdd87){_0x496844=_[_0x0bdb('0x40')](_0xba8d98['users'][_0x0bdb('0x41')],{'email':_0x3cdd87,'profile':_0x0bdb('0x42')});}if(_0x496844){logger[_0x0bdb('0x37')](_0x0bdb('0x43'));}else{logger[_0x0bdb('0x37')](_0x0bdb('0x44'));_0x496844=_['find'](_0xba8d98[_0x0bdb('0x3f')][_0x0bdb('0x41')],{'profile':_0x0bdb('0x45')});}return _0x496844;}else{logger[_0x0bdb('0x46')]('The\x20failing\x20result\x20is',JSON[_0x0bdb('0x3a')](_0xba8d98));throw new Error(_0x0bdb('0x47')+JSON[_0x0bdb('0x3a')](_0xba8d98));}});}function getEndUser(_0x23ace5,_0x445353,_0x15cc71){logger[_0x0bdb('0x37')](_0x0bdb('0x48'),_0x15cc71);return request({'method':_0x0bdb('0x3c'),'uri':util['format'](_0x0bdb('0x49'),_0x23ace5[_0x0bdb('0x2f')]),'qs':{'authtoken':_0x23ace5[_0x0bdb('0x30')],'scope':_0x0bdb('0x31'),'criteria':util['format'](_0x0bdb('0x4a'),_0x15cc71)},'json':!![]})[_0x0bdb('0x32')](function(_0x4f60c5){if(_0x4f60c5[_0x0bdb('0x34')]&&_0x4f60c5[_0x0bdb('0x34')][_0x0bdb('0x35')]){logger[_0x0bdb('0x37')]('Enduser\x20found\x20in\x20Contacts!');var _0x279c14={};var _0x3b2aec=_0x4f60c5[_0x0bdb('0x34')][_0x0bdb('0x35')]['Contacts'][_0x0bdb('0x4b')]['no']?_0x4f60c5[_0x0bdb('0x34')][_0x0bdb('0x35')][_0x0bdb('0x4c')][_0x0bdb('0x4b')]['FL']:_0x4f60c5[_0x0bdb('0x34')][_0x0bdb('0x35')][_0x0bdb('0x4c')]['row'][0x0]['FL'];for(var _0x273c9f=0x0,_0x4eeda4=_0x3b2aec[_0x0bdb('0x4d')];_0x273c9f<_0x4eeda4;_0x273c9f++){_0x279c14[_0x3b2aec[_0x273c9f][_0x0bdb('0x4e')]]=_0x3b2aec[_0x273c9f][_0x0bdb('0x4f')];}return _0x279c14;}else{return request({'method':_0x0bdb('0x3c'),'uri':util[_0x0bdb('0x13')](_0x0bdb('0x50'),_0x23ace5[_0x0bdb('0x2f')]),'qs':{'authtoken':_0x23ace5[_0x0bdb('0x30')],'scope':_0x0bdb('0x31'),'criteria':util[_0x0bdb('0x13')]('((Phone:%s))',_0x15cc71)},'json':!![]})[_0x0bdb('0x32')](function(_0x1d733f){if(_0x1d733f[_0x0bdb('0x34')]&&_0x1d733f['response'][_0x0bdb('0x35')]){logger[_0x0bdb('0x37')]('Enduser\x20found\x20in\x20Leads!');var _0x1ec822={};var _0x246730=_0x1d733f[_0x0bdb('0x34')]['result'][_0x0bdb('0x28')][_0x0bdb('0x4b')]['no']?_0x1d733f['response']['result'][_0x0bdb('0x28')][_0x0bdb('0x4b')]['FL']:_0x1d733f['response'][_0x0bdb('0x35')][_0x0bdb('0x28')]['row'][0x0]['FL'];for(var _0x40bc29=0x0,_0x5054a8=_0x246730[_0x0bdb('0x4d')];_0x40bc29<_0x5054a8;_0x40bc29++){_0x1ec822[_0x246730[_0x40bc29][_0x0bdb('0x4e')]]=_0x246730[_0x40bc29][_0x0bdb('0x4f')];}return _0x1ec822;}else{logger['info']('Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!');_0x445353=getName(_0x445353);return request({'method':_0x0bdb('0x2e'),'uri':util['format'](_0x0bdb('0x51'),_0x23ace5[_0x0bdb('0x2f')]),'qs':{'authtoken':_0x23ace5[_0x0bdb('0x30')],'scope':'crmapi','xmlData':util[_0x0bdb('0x13')]('<Leads><row\x20no=\x221\x22><FL\x20val=\x22First\x20Name\x22>%s</FL><FL\x20val=\x22Last\x20Name\x22>%s</FL><FL\x20val=\x22Phone\x22>%s</FL></row></Leads>',entities[_0x0bdb('0x2d')](_0x445353[0x0]),entities[_0x0bdb('0x2d')](_0x445353[0x1]),_0x15cc71)},'json':!![]})['then'](function(_0x3daa03){_0x3daa03=JSON['parse'](parser['toJson'](_0x3daa03));if(_0x3daa03['response']){if(_0x3daa03[_0x0bdb('0x34')][_0x0bdb('0x35')]&&_0x3daa03[_0x0bdb('0x34')][_0x0bdb('0x35')][_0x0bdb('0x36')]){logger['info'](_0x0bdb('0x52'));return request({'method':_0x0bdb('0x3c'),'uri':util[_0x0bdb('0x13')](_0x0bdb('0x53'),_0x23ace5[_0x0bdb('0x2f')]),'qs':{'authtoken':_0x23ace5[_0x0bdb('0x30')],'scope':_0x0bdb('0x31'),'id':_0x3daa03[_0x0bdb('0x34')][_0x0bdb('0x35')][_0x0bdb('0x36')]['FL'][0x0]['$t']},'json':!![]});}}throw new Error(_0x0bdb('0x54')+JSON[_0x0bdb('0x3a')](_0x3daa03));})[_0x0bdb('0x32')](function(_0x4faed9){if(_0x4faed9[_0x0bdb('0x34')]){if(_0x4faed9[_0x0bdb('0x34')][_0x0bdb('0x35')]){var _0x1a8728={};for(var _0x5da01c=0x0,_0x36244a=_0x4faed9['response'][_0x0bdb('0x35')][_0x0bdb('0x28')][_0x0bdb('0x4b')]['FL'][_0x0bdb('0x4d')];_0x5da01c<_0x36244a;_0x5da01c++){_0x1a8728[_0x4faed9['response'][_0x0bdb('0x35')]['Leads'][_0x0bdb('0x4b')]['FL'][_0x5da01c][_0x0bdb('0x4e')]]=_0x4faed9['response'][_0x0bdb('0x35')]['Leads'][_0x0bdb('0x4b')]['FL'][_0x5da01c][_0x0bdb('0x4f')];}return _0x1a8728;}}throw new Error(_0x0bdb('0x55')+JSON['stringify'](_0x4faed9));});}});}});}function request(_0x14cf48){logger[_0x0bdb('0x56')](_0x0bdb('0x57'),JSON[_0x0bdb('0x3a')](_0x14cf48));return rp(_0x14cf48);}function getCustomFields(_0x2b95e8,_0x4ebc69){var _0x9baab9={};if(_0x2b95e8['length']>0x0){_[_0x0bdb('0x58')](_0x2b95e8,function(_0x2827ea){if(_0x2827ea[_0x0bdb('0x59')]===_0x0bdb('0x5a')&&_0x2827ea[_0x0bdb('0x5b')]){_0x9baab9[_0x2827ea[_0x0bdb('0x5b')]]=_0x2827ea['content'][_0x0bdb('0x5c')]();}else if(_0x2827ea['type']==='variable'&&_0x2827ea[_0x0bdb('0x5d')]&&_0x2827ea[_0x0bdb('0x5b')]&&_0x4ebc69[_0x2827ea[_0x0bdb('0x5d')]]){_0x9baab9[_0x2827ea[_0x0bdb('0x5b')]]=_0x4ebc69[_0x2827ea[_0x0bdb('0x5d')]][_0x0bdb('0x5c')]();}else if(_0x2827ea[_0x0bdb('0x59')]===_0x0bdb('0x5e')&&_0x2827ea['Variable']&&_0x2827ea[_0x0bdb('0x5f')][_0x0bdb('0x60')]&&_0x2827ea[_0x0bdb('0x5b')]&&_0x4ebc69[_0x2827ea[_0x0bdb('0x5f')][_0x0bdb('0x60')]['toLowerCase']()]){_0x9baab9[_0x2827ea[_0x0bdb('0x5b')]]=_0x4ebc69[_0x2827ea[_0x0bdb('0x5f')][_0x0bdb('0x60')][_0x0bdb('0x61')]()][_0x0bdb('0x5c')]();}});}return _0x9baab9;}function getName(_0x33cf6f){if(_0x33cf6f[_0x0bdb('0x62')]('\x20')>0x0){var _0x2f3f9d=_0x33cf6f[_0x0bdb('0x63')](/ (.+)/);if(_0x2f3f9d[0x1]){return _0x2f3f9d;}}return[_0x33cf6f,_0x33cf6f];}exports[_0x0bdb('0x64')]=function(_0x288e22,_0xae7db9,_0xfc2724,_0x3ddb06,_0x47ea51,_0x3527c5){var _0x5496f7,_0x4fab30;if(_0x47ea51&&_0x47ea51['monitor_format']){logger[_0x0bdb('0x37')](_0x0bdb('0x65'),'Recording\x20is\x20enabled!');_0xae7db9['recordingURL']=util['format'](_0x0bdb('0x66'),_0x3527c5[_0x0bdb('0x67')],_0xae7db9[_0x0bdb('0x68')],md5(_0xae7db9[_0x0bdb('0x68')]));}else{_0xae7db9[_0x0bdb('0x69')]='';}return getUser(_0x3527c5,_0x3ddb06[_0x0bdb('0x6a')])[_0x0bdb('0x32')](function(_0x26a98d){_0x5496f7=_0x26a98d;logger[_0x0bdb('0x37')](_0x0bdb('0x6b'),_0x5496f7['id']);return getEndUser(_0x3527c5,_0xae7db9[_0x0bdb('0x6c')],_0xae7db9[_0x0bdb('0x6d')]);})[_0x0bdb('0x32')](function(_0x414646){_0x4fab30=_0x414646;logger[_0x0bdb('0x37')](_0x0bdb('0x6e'),_0x4fab30['CONTACTID']||_0x4fab30[_0x0bdb('0x26')]);return getCall(_0x3527c5,_0x5496f7,_0x4fab30,_0xfc2724,_0xae7db9,_0x0bdb('0x6f'));})[_0x0bdb('0x32')](function(_0x3579a0){if(_0x3579a0){logger['info'](_0x0bdb('0x70'),_0x3579a0['id']);logger[_0x0bdb('0x37')](_0x0bdb('0x65'),_0x0bdb('0x71'));emit(util['format'](_0x0bdb('0x72'),_0x3ddb06[_0x0bdb('0x60')]),_0x0bdb('0x73'),{'uri':util[_0x0bdb('0x13')](_0x0bdb('0x74'),_0x3527c5[_0x0bdb('0x2f')],_0x3579a0['id'])});}})['catch'](function(_0xf5d267){logger[_0x0bdb('0x46')](_0x0bdb('0x65'),JSON[_0x0bdb('0x3a')](_0xf5d267));});};exports[_0x0bdb('0x11')]=function(_0x2cc1e9,_0x359f6d,_0x5c6db3,_0x4a4da2,_0x303d6f,_0x4765e8,_0xa08087){var _0x117117,_0x4789cc;if(_0xa08087&&_0xa08087[_0x0bdb('0x75')]&&_0xa08087[_0x0bdb('0x75')]!=='none'){logger[_0x0bdb('0x37')]('[OUTBOUND]',_0x0bdb('0x76'));_0x359f6d[_0x0bdb('0x69')]=util[_0x0bdb('0x13')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x4765e8['serverUrl'],_0x359f6d['uniqueid'],md5(_0x359f6d[_0x0bdb('0x68')]));}return getUser(_0x4765e8,_0x4a4da2[_0x0bdb('0x6a')])[_0x0bdb('0x32')](function(_0x452e93){_0x117117=_0x452e93;logger[_0x0bdb('0x37')]('The\x20User\x20ID\x20is:',_0x117117['id']);return getEndUser(_0x4765e8,_0x359f6d[_0x0bdb('0x77')],_0x359f6d[_0x0bdb('0x78')]);})[_0x0bdb('0x32')](function(_0x2ae3ad){_0x4789cc=_0x2ae3ad;logger[_0x0bdb('0x37')](_0x0bdb('0x6e'),_0x4789cc[_0x0bdb('0x25')]||_0x4789cc['LEADID']);return getCall(_0x4765e8,_0x117117,_0x4789cc,_0x5c6db3,_0x359f6d,_0x0bdb('0x79'));})[_0x0bdb('0x32')](function(_0x14eda4){if(_0x14eda4){logger[_0x0bdb('0x37')](_0x0bdb('0x70'),_0x14eda4['id']);logger[_0x0bdb('0x37')](_0x0bdb('0x7a'),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0x0bdb('0x13')]('user:%s',_0x4a4da2[_0x0bdb('0x60')]),_0x0bdb('0x73'),{'uri':util[_0x0bdb('0x13')](_0x0bdb('0x74'),_0x4765e8[_0x0bdb('0x2f')],_0x14eda4['id'])});}})[_0x0bdb('0x7b')](function(_0x3b3c75){logger['error'](_0x0bdb('0x7a'),JSON[_0x0bdb('0x3a')](_0x3b3c75));});};exports[_0x0bdb('0x7c')]=function(_0x429756,_0x16aecf,_0x44a8ca,_0x1fb59e,_0x39e274,_0x3e6eec){var _0x12cb9a,_0x18155c;if(_0x39e274&&_0x39e274[_0x0bdb('0x7d')]){logger[_0x0bdb('0x37')](_0x0bdb('0x7e'),_0x0bdb('0x76'));_0x16aecf[_0x0bdb('0x69')]=util[_0x0bdb('0x13')](_0x0bdb('0x66'),_0x3e6eec[_0x0bdb('0x67')],_0x16aecf['uniqueid'],md5(_0x16aecf[_0x0bdb('0x68')]));}else{_0x16aecf[_0x0bdb('0x69')]='';}return getUser(_0x3e6eec)[_0x0bdb('0x32')](function(_0x35112d){_0x12cb9a=_0x35112d;logger[_0x0bdb('0x37')](_0x0bdb('0x6b'),_0x12cb9a['id']);return getEndUser(_0x3e6eec,_0x16aecf[_0x0bdb('0x6c')],_0x16aecf[_0x0bdb('0x6d')]);})[_0x0bdb('0x32')](function(_0x3a2bc5){_0x18155c=_0x3a2bc5;logger['info']('The\x20Enduser\x20ID\x20is:',_0x18155c[_0x0bdb('0x25')]||_0x18155c[_0x0bdb('0x26')]);return getCall(_0x3e6eec,_0x12cb9a,_0x18155c,_0x44a8ca,_0x16aecf,'Inbound');})[_0x0bdb('0x32')](function(_0x80b351){if(_0x80b351){logger[_0x0bdb('0x37')](_0x0bdb('0x70'),_0x80b351['id']);}})[_0x0bdb('0x7b')](function(_0x299d3b){logger[_0x0bdb('0x46')]('[ABANDONED]',JSON[_0x0bdb('0x3a')](_0x299d3b));});};
\ No newline at end of file
+var _0x5fc3=['[HTTP]','forEach','string','idField','toString','type','variable','variableName','customVariable','Variable','name','toLowerCase','split','queue','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','serverUrl','uniqueid','recordingURL','calleridname','Inbound','The\x20Call\x20ID\x20is:','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','https://crm.%s/crm/EntityInfo.do?module=Calls&id=%s','outbound','recordingFormat','none','[OUTBOUND]','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','email','destcalleridname','The\x20Enduser\x20ID\x20is:','Outbound','catch','[ABANDONED]','The\x20User\x20ID\x20is:','calleridnum','lodash','request-promise','util','./util','xml2json','entities','moment','../../../../config/environment','../../../../config/logger','zoho','redis','socket.io-emitter','emit','application/json','info','Creating\x20new\x20call...','inbound','starttime','agentcalledAt','format','YYYY-MM-DD\x20HH:mm:ss','getString','lastevent','called','Call\x20Result','Called','complete','connect','Answered','rejected','Rejected','abandoned','talktime','Call\x20Duration','utc','mm:ss','answertime','endtime','diff','CONTACTID','SEMODULE','Leads','LEADID','<Calls><row\x20no=\x221\x22>','hasOwnProperty','<FL\x20val=\x22%s\x22>%s</FL>','encodeXML','POST','https://crm.%s/crm/private/xml/Calls/insertRecords','host','crmapi','then','parse','toJson','response','result','recorddetail','Error\x20on\x20call\x20creation:\x20','stringify','Getting\x20agent\x20with\x20email','GET','authToken','users','find','user','Standard','Using\x20the\x20admin\x20account!','error','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','Searching\x20enduser\x20with\x20phone','https://crm.%s/crm/private/json/Contacts/searchRecords','((Phone:%s))','Enduser\x20found\x20in\x20Contacts!','Contacts','row','length','val','content','https://crm.%s/crm/private/json/Leads/searchRecords','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','https://crm.%s/crm/private/xml/Leads/insertRecords','<Leads><row\x20no=\x221\x22><FL\x20val=\x22First\x20Name\x22>%s</FL><FL\x20val=\x22Last\x20Name\x22>%s</FL><FL\x20val=\x22Phone\x22>%s</FL></row></Leads>','Enduser\x20created.','https://crm.%s/crm/private/json/Leads/getRecordById','Error\x20on\x20Lead\x20creation:\x20','Error\x20on\x20Lead\x20retrieve:\x20','debug'];(function(_0x1e6737,_0x3a00b9){var _0x13209b=function(_0x161523){while(--_0x161523){_0x1e6737['push'](_0x1e6737['shift']());}};_0x13209b(++_0x3a00b9);}(_0x5fc3,0xa8));var _0x35fc=function(_0x269ee8,_0x477226){_0x269ee8=_0x269ee8-0x0;var _0x4d98bd=_0x5fc3[_0x269ee8];return _0x4d98bd;};'use strict';var _=require(_0x35fc('0x0'));var rp=require(_0x35fc('0x1'));var md5=require('md5');var util=require(_0x35fc('0x2'));var intUtil=require(_0x35fc('0x3'));var parser=require(_0x35fc('0x4'));var entities=require(_0x35fc('0x5'));var moment=require(_0x35fc('0x6'));var Redis=require('ioredis');var config=require(_0x35fc('0x7'));var logger=require(_0x35fc('0x8'))(_0x35fc('0x9'));config['redis']=_['defaults'](config[_0x35fc('0xa')],{'host':'localhost','port':0x18eb});var io=require(_0x35fc('0xb'))(new Redis(config[_0x35fc('0xa')]));function emit(_0xc72d93,_0x1e5f90,_0x34ff19){io['to'](_0xc72d93)[_0x35fc('0xc')](_0x1e5f90,_0x34ff19);}var headers={'Content-Type':_0x35fc('0xd'),'Accept':'application/json'};function getCall(_0x1083a9,_0x2a1084,_0x4fdca1,_0x471549,_0x33f491,_0x5021d4){logger[_0x35fc('0xe')](_0x35fc('0xf'));var _0x5469f5=_['merge']({'SMOWNERID':_0x2a1084['id'],'Call Type':_0x5021d4||_0x35fc('0x10'),'Call Start Time':(_0x5021d4==='outbound'?_0x33f491[_0x35fc('0x11')]:_0x33f491[_0x35fc('0x12')])||moment()[_0x35fc('0x13')](_0x35fc('0x14')),'Subject':intUtil[_0x35fc('0x15')](_0x471549['Subjects'],_0x33f491,'\x20'),'Description':intUtil['getString'](_0x471549['Descriptions'],_0x33f491,'\x0a')},getCustomFields(_0x471549['Fields'],_0x33f491));switch(_0x33f491[_0x35fc('0x16')]){case _0x35fc('0x17'):_0x5469f5[_0x35fc('0x18')]=_0x35fc('0x19');break;case _0x35fc('0x1a'):case _0x35fc('0x1b'):_0x5469f5['Call\x20Result']=_0x35fc('0x1c');break;case _0x35fc('0x1d'):_0x5469f5['Call\x20Result']=_0x35fc('0x1e');break;case _0x35fc('0x1f'):_0x5469f5[_0x35fc('0x18')]='Abandoned';break;default:}if(_0x33f491[_0x35fc('0x20')]){_0x5469f5[_0x35fc('0x21')]=moment[_0x35fc('0x22')](parseInt(_0x33f491['talktime'])*0x3e8)[_0x35fc('0x13')](_0x35fc('0x23'));}else if(_0x33f491[_0x35fc('0x24')]&&_0x33f491[_0x35fc('0x25')]){_0x5469f5[_0x35fc('0x21')]=moment[_0x35fc('0x22')](moment(_0x33f491[_0x35fc('0x25')],_0x35fc('0x14'))[_0x35fc('0x26')](moment(_0x33f491[_0x35fc('0x11')],'YYYY-MM-DD\x20HH:mm:ss')))[_0x35fc('0x13')](_0x35fc('0x23'));}if(_0x4fdca1[_0x35fc('0x27')]){_0x5469f5[_0x35fc('0x27')]=_0x4fdca1[_0x35fc('0x27')];}else if(_0x4fdca1['LEADID']){_0x5469f5[_0x35fc('0x28')]=_0x35fc('0x29');_0x5469f5['SEID']=_0x4fdca1[_0x35fc('0x2a')];}var _0x5a93df=_0x35fc('0x2b');for(var _0x51cfec in _0x5469f5){if(_0x5469f5[_0x35fc('0x2c')](_0x51cfec)){_0x5a93df+=util['format'](_0x35fc('0x2d'),entities[_0x35fc('0x2e')](_0x51cfec),entities['encodeXML'](_0x5469f5[_0x51cfec]));}}_0x5a93df+='</row></Calls>';return request({'method':_0x35fc('0x2f'),'uri':util['format'](_0x35fc('0x30'),_0x1083a9[_0x35fc('0x31')]),'qs':{'authtoken':_0x1083a9['authToken'],'scope':_0x35fc('0x32'),'xmlData':_0x5a93df},'json':!![]})[_0x35fc('0x33')](function(_0x383837){_0x383837=JSON[_0x35fc('0x34')](parser[_0x35fc('0x35')](_0x383837));if(_0x383837[_0x35fc('0x36')]){if(_0x383837[_0x35fc('0x36')][_0x35fc('0x37')]&&_0x383837['response'][_0x35fc('0x37')][_0x35fc('0x38')]){logger[_0x35fc('0xe')]('Call\x20created!');return{'id':_0x383837[_0x35fc('0x36')][_0x35fc('0x37')][_0x35fc('0x38')]['FL'][0x0]['$t']};}}throw new Error(_0x35fc('0x39')+JSON[_0x35fc('0x3a')](_0x383837));});}function getUser(_0x103181,_0x222ddb){_0x222ddb&&logger[_0x35fc('0xe')](_0x35fc('0x3b'),_0x222ddb);return request({'method':_0x35fc('0x3c'),'uri':util['format']('https://crm.%s/crm/private/json/Users/getUsers',_0x103181[_0x35fc('0x31')]),'qs':{'type':'AllUsers','authtoken':_0x103181[_0x35fc('0x3d')],'scope':_0x35fc('0x32')},'json':!![]})[_0x35fc('0x33')](function(_0x227471){if(_0x227471[_0x35fc('0x3e')]&&_0x227471[_0x35fc('0x3e')]['user']){var _0x3fe193;if(_0x222ddb){_0x3fe193=_[_0x35fc('0x3f')](_0x227471[_0x35fc('0x3e')][_0x35fc('0x40')],{'email':_0x222ddb,'profile':_0x35fc('0x41')});}if(_0x3fe193){logger[_0x35fc('0xe')]('Agent\x20found!');}else{logger[_0x35fc('0xe')](_0x35fc('0x42'));_0x3fe193=_[_0x35fc('0x3f')](_0x227471['users'][_0x35fc('0x40')],{'profile':'Administrator'});}return _0x3fe193;}else{logger[_0x35fc('0x43')](_0x35fc('0x44'),JSON[_0x35fc('0x3a')](_0x227471));throw new Error(_0x35fc('0x45')+JSON['stringify'](_0x227471));}});}function getEndUser(_0x54fcf1,_0x59e4fb,_0x20f5fe){logger['info'](_0x35fc('0x46'),_0x20f5fe);return request({'method':'GET','uri':util[_0x35fc('0x13')](_0x35fc('0x47'),_0x54fcf1[_0x35fc('0x31')]),'qs':{'authtoken':_0x54fcf1[_0x35fc('0x3d')],'scope':_0x35fc('0x32'),'criteria':util[_0x35fc('0x13')](_0x35fc('0x48'),_0x20f5fe)},'json':!![]})['then'](function(_0x4467f8){if(_0x4467f8[_0x35fc('0x36')]&&_0x4467f8['response'][_0x35fc('0x37')]){logger[_0x35fc('0xe')](_0x35fc('0x49'));var _0x1d2ffe={};var _0x813866=_0x4467f8[_0x35fc('0x36')]['result'][_0x35fc('0x4a')][_0x35fc('0x4b')]['no']?_0x4467f8[_0x35fc('0x36')]['result'][_0x35fc('0x4a')][_0x35fc('0x4b')]['FL']:_0x4467f8['response'][_0x35fc('0x37')][_0x35fc('0x4a')][_0x35fc('0x4b')][0x0]['FL'];for(var _0x41e199=0x0,_0x331439=_0x813866[_0x35fc('0x4c')];_0x41e199<_0x331439;_0x41e199++){_0x1d2ffe[_0x813866[_0x41e199][_0x35fc('0x4d')]]=_0x813866[_0x41e199][_0x35fc('0x4e')];}return _0x1d2ffe;}else{return request({'method':'GET','uri':util['format'](_0x35fc('0x4f'),_0x54fcf1[_0x35fc('0x31')]),'qs':{'authtoken':_0x54fcf1['authToken'],'scope':'crmapi','criteria':util['format'](_0x35fc('0x48'),_0x20f5fe)},'json':!![]})[_0x35fc('0x33')](function(_0x4e56ed){if(_0x4e56ed[_0x35fc('0x36')]&&_0x4e56ed[_0x35fc('0x36')][_0x35fc('0x37')]){logger[_0x35fc('0xe')]('Enduser\x20found\x20in\x20Leads!');var _0x57105c={};var _0x5bf2f4=_0x4e56ed['response']['result'][_0x35fc('0x29')][_0x35fc('0x4b')]['no']?_0x4e56ed['response'][_0x35fc('0x37')]['Leads'][_0x35fc('0x4b')]['FL']:_0x4e56ed[_0x35fc('0x36')][_0x35fc('0x37')][_0x35fc('0x29')][_0x35fc('0x4b')][0x0]['FL'];for(var _0x5d3d0f=0x0,_0x64d381=_0x5bf2f4[_0x35fc('0x4c')];_0x5d3d0f<_0x64d381;_0x5d3d0f++){_0x57105c[_0x5bf2f4[_0x5d3d0f]['val']]=_0x5bf2f4[_0x5d3d0f][_0x35fc('0x4e')];}return _0x57105c;}else{logger[_0x35fc('0xe')](_0x35fc('0x50'));_0x59e4fb=getName(_0x59e4fb);return request({'method':_0x35fc('0x2f'),'uri':util['format'](_0x35fc('0x51'),_0x54fcf1['host']),'qs':{'authtoken':_0x54fcf1['authToken'],'scope':_0x35fc('0x32'),'xmlData':util[_0x35fc('0x13')](_0x35fc('0x52'),entities[_0x35fc('0x2e')](_0x59e4fb[0x0]),entities[_0x35fc('0x2e')](_0x59e4fb[0x1]),_0x20f5fe)},'json':!![]})[_0x35fc('0x33')](function(_0x405320){_0x405320=JSON[_0x35fc('0x34')](parser['toJson'](_0x405320));if(_0x405320[_0x35fc('0x36')]){if(_0x405320[_0x35fc('0x36')][_0x35fc('0x37')]&&_0x405320[_0x35fc('0x36')][_0x35fc('0x37')][_0x35fc('0x38')]){logger[_0x35fc('0xe')](_0x35fc('0x53'));return request({'method':_0x35fc('0x3c'),'uri':util[_0x35fc('0x13')](_0x35fc('0x54'),_0x54fcf1[_0x35fc('0x31')]),'qs':{'authtoken':_0x54fcf1[_0x35fc('0x3d')],'scope':_0x35fc('0x32'),'id':_0x405320['response']['result'][_0x35fc('0x38')]['FL'][0x0]['$t']},'json':!![]});}}throw new Error(_0x35fc('0x55')+JSON[_0x35fc('0x3a')](_0x405320));})[_0x35fc('0x33')](function(_0x3ee296){if(_0x3ee296[_0x35fc('0x36')]){if(_0x3ee296['response']['result']){var _0x388521={};for(var _0x19b2ce=0x0,_0x395d63=_0x3ee296[_0x35fc('0x36')]['result'][_0x35fc('0x29')][_0x35fc('0x4b')]['FL']['length'];_0x19b2ce<_0x395d63;_0x19b2ce++){_0x388521[_0x3ee296[_0x35fc('0x36')][_0x35fc('0x37')]['Leads'][_0x35fc('0x4b')]['FL'][_0x19b2ce][_0x35fc('0x4d')]]=_0x3ee296[_0x35fc('0x36')][_0x35fc('0x37')]['Leads']['row']['FL'][_0x19b2ce]['content'];}return _0x388521;}}throw new Error(_0x35fc('0x56')+JSON[_0x35fc('0x3a')](_0x3ee296));});}});}});}function request(_0x5ce231){logger[_0x35fc('0x57')](_0x35fc('0x58'),JSON[_0x35fc('0x3a')](_0x5ce231));return rp(_0x5ce231);}function getCustomFields(_0x145854,_0x46c59b){var _0x538be0={};if(_0x145854[_0x35fc('0x4c')]>0x0){_[_0x35fc('0x59')](_0x145854,function(_0x39d470){if(_0x39d470['type']===_0x35fc('0x5a')&&_0x39d470[_0x35fc('0x5b')]){_0x538be0[_0x39d470['idField']]=_0x39d470[_0x35fc('0x4e')][_0x35fc('0x5c')]();}else if(_0x39d470[_0x35fc('0x5d')]===_0x35fc('0x5e')&&_0x39d470[_0x35fc('0x5f')]&&_0x39d470[_0x35fc('0x5b')]&&_0x46c59b[_0x39d470[_0x35fc('0x5f')]]){_0x538be0[_0x39d470[_0x35fc('0x5b')]]=_0x46c59b[_0x39d470['variableName']][_0x35fc('0x5c')]();}else if(_0x39d470[_0x35fc('0x5d')]===_0x35fc('0x60')&&_0x39d470['Variable']&&_0x39d470[_0x35fc('0x61')]['name']&&_0x39d470['idField']&&_0x46c59b[_0x39d470['Variable'][_0x35fc('0x62')][_0x35fc('0x63')]()]){_0x538be0[_0x39d470[_0x35fc('0x5b')]]=_0x46c59b[_0x39d470[_0x35fc('0x61')][_0x35fc('0x62')]['toLowerCase']()]['toString']();}});}return _0x538be0;}function getName(_0x5353ea){if(_0x5353ea['indexOf']('\x20')>0x0){var _0x51d231=_0x5353ea[_0x35fc('0x64')](/ (.+)/);if(_0x51d231[0x1]){return _0x51d231;}}return[_0x5353ea,_0x5353ea];}exports[_0x35fc('0x65')]=function(_0xd470e8,_0x3ef680,_0x511e8b,_0x458eb8,_0x20b042,_0x390e16){var _0x1b0063,_0x37bea1;if(_0x20b042&&_0x20b042[_0x35fc('0x66')]){logger[_0x35fc('0xe')](_0x35fc('0x67'),_0x35fc('0x68'));_0x3ef680['recordingURL']=util[_0x35fc('0x13')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x390e16[_0x35fc('0x69')],_0x3ef680[_0x35fc('0x6a')],md5(_0x3ef680[_0x35fc('0x6a')]));}else{_0x3ef680[_0x35fc('0x6b')]='';}return getUser(_0x390e16,_0x458eb8['email'])[_0x35fc('0x33')](function(_0x4af592){_0x1b0063=_0x4af592;logger['info']('The\x20User\x20ID\x20is:',_0x1b0063['id']);return getEndUser(_0x390e16,_0x3ef680[_0x35fc('0x6c')],_0x3ef680['calleridnum']);})[_0x35fc('0x33')](function(_0x48c7a5){_0x37bea1=_0x48c7a5;logger[_0x35fc('0xe')]('The\x20Enduser\x20ID\x20is:',_0x37bea1[_0x35fc('0x27')]||_0x37bea1[_0x35fc('0x2a')]);return getCall(_0x390e16,_0x1b0063,_0x37bea1,_0x511e8b,_0x3ef680,_0x35fc('0x6d'));})[_0x35fc('0x33')](function(_0x5c2ec0){if(_0x5c2ec0){logger[_0x35fc('0xe')](_0x35fc('0x6e'),_0x5c2ec0['id']);logger[_0x35fc('0xe')]('[QUEUE]',_0x35fc('0x6f'));emit(util[_0x35fc('0x13')](_0x35fc('0x70'),_0x458eb8[_0x35fc('0x62')]),_0x35fc('0x71'),{'uri':util[_0x35fc('0x13')](_0x35fc('0x72'),_0x390e16[_0x35fc('0x31')],_0x5c2ec0['id'])});}})['catch'](function(_0x28a44b){logger[_0x35fc('0x43')](_0x35fc('0x67'),JSON['stringify'](_0x28a44b));});};exports[_0x35fc('0x73')]=function(_0x1b76f0,_0x586729,_0x4d09d4,_0x3969d3,_0x4835c2,_0x223ad3,_0x2dbc81){var _0x43638e,_0x10952a;if(_0x2dbc81&&_0x2dbc81[_0x35fc('0x74')]&&_0x2dbc81[_0x35fc('0x74')]!==_0x35fc('0x75')){logger[_0x35fc('0xe')](_0x35fc('0x76'),_0x35fc('0x68'));_0x586729[_0x35fc('0x6b')]=util[_0x35fc('0x13')](_0x35fc('0x77'),_0x223ad3[_0x35fc('0x69')],_0x586729[_0x35fc('0x6a')],md5(_0x586729[_0x35fc('0x6a')]));}return getUser(_0x223ad3,_0x3969d3[_0x35fc('0x78')])[_0x35fc('0x33')](function(_0x3b2160){_0x43638e=_0x3b2160;logger[_0x35fc('0xe')]('The\x20User\x20ID\x20is:',_0x43638e['id']);return getEndUser(_0x223ad3,_0x586729[_0x35fc('0x79')],_0x586729['destcalleridnum']);})[_0x35fc('0x33')](function(_0x6c5ef){_0x10952a=_0x6c5ef;logger[_0x35fc('0xe')](_0x35fc('0x7a'),_0x10952a[_0x35fc('0x27')]||_0x10952a[_0x35fc('0x2a')]);return getCall(_0x223ad3,_0x43638e,_0x10952a,_0x4d09d4,_0x586729,_0x35fc('0x7b'));})[_0x35fc('0x33')](function(_0x2fed7b){if(_0x2fed7b){logger[_0x35fc('0xe')](_0x35fc('0x6e'),_0x2fed7b['id']);logger['info'](_0x35fc('0x76'),_0x35fc('0x6f'));emit(util[_0x35fc('0x13')](_0x35fc('0x70'),_0x3969d3[_0x35fc('0x62')]),_0x35fc('0x71'),{'uri':util['format'](_0x35fc('0x72'),_0x223ad3[_0x35fc('0x31')],_0x2fed7b['id'])});}})[_0x35fc('0x7c')](function(_0x23206d){logger[_0x35fc('0x43')](_0x35fc('0x76'),JSON[_0x35fc('0x3a')](_0x23206d));});};exports[_0x35fc('0x1f')]=function(_0xa92234,_0x5f23d8,_0x28f02b,_0x5539f0,_0x1c7d01,_0x23be75){var _0x52272e,_0x1ce050;if(_0x1c7d01&&_0x1c7d01[_0x35fc('0x66')]){logger[_0x35fc('0xe')](_0x35fc('0x7d'),_0x35fc('0x68'));_0x5f23d8[_0x35fc('0x6b')]=util[_0x35fc('0x13')](_0x35fc('0x77'),_0x23be75[_0x35fc('0x69')],_0x5f23d8['uniqueid'],md5(_0x5f23d8['uniqueid']));}else{_0x5f23d8['recordingURL']='';}return getUser(_0x23be75)['then'](function(_0x160a6f){_0x52272e=_0x160a6f;logger[_0x35fc('0xe')](_0x35fc('0x7e'),_0x52272e['id']);return getEndUser(_0x23be75,_0x5f23d8[_0x35fc('0x6c')],_0x5f23d8[_0x35fc('0x7f')]);})['then'](function(_0x226fdf){_0x1ce050=_0x226fdf;logger[_0x35fc('0xe')](_0x35fc('0x7a'),_0x1ce050[_0x35fc('0x27')]||_0x1ce050['LEADID']);return getCall(_0x23be75,_0x52272e,_0x1ce050,_0x28f02b,_0x5f23d8,_0x35fc('0x6d'));})[_0x35fc('0x33')](function(_0x32b2df){if(_0x32b2df){logger['info'](_0x35fc('0x6e'),_0x32b2df['id']);}})[_0x35fc('0x7c')](function(_0x319033){logger[_0x35fc('0x43')](_0x35fc('0x7d'),JSON[_0x35fc('0x3a')](_0x319033));});};
\ No newline at end of file