Built motion from commit 5293bb2a.|2.6.30
[motion2.git] / server / services / ami / trigger / integration / sugarcrm.js
index f018594..2cfe271 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa50e=['monitor_format','[QUEUE]','uniqueid','recordingURL','calleridname','calleridnum','Ticket\x20created!','The\x20Ticket\x20ID\x20is:','users','contacts','version','%s/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DCalls%26action%3DEditView%26record%3D%s','%s/#bwc/index.php?module=Calls&action=EditView&record=%s','trigger:browser:url','catch','error','outbound','recordingFormat','none','[OUTBOUND]','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','The\x20User\x20ID\x20is:','destcalleridnum','The\x20Enduser\x20ID\x20is:','Fields','Outbound','charAt','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','toUpperCase','request-promise','bluebird','util','ioredis','./util','../../../../config/logger','sugarcrm','redis','defaults','localhost','socket.io-emitter','POST','emit','info','Creating\x20new\x20ticket...','name','getString','Subjects','assigned_user_id','description','date_start','toISOString','slice','replace','duration_hours','parent_id','parent_type','Contacts','parent_name','direction','push','idField','variableName','set_entry','JSON','stringify','Calls','Basic\x20%s','toString','base64','isNil','Getting\x20agent\x20with\x20name','Employees','format','INSTR\x20(\x20users.user_name,\x20\x22%s\x22)\x20>\x200','user_name','entry_list','length','find','name_value_list','value','Agent\x20found!','resolve','Agent\x20not\x20available,\x20using\x20the\x20admin\x20account!','get_entry_list','contacts.phone_home\x20=\x20\x22%s\x22','phone_home','then','Enduser\x20found!','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','<unknown>','Enduser\x20created.','first_name','debug','[HTTP]','merge','map','forEach','type','string','customField','nameField','toLowerCase','custom_fields','content','variable','customVariable','Variable','login','username','password','PLAIN','xCALLY\x20Motion\x20integration','sessionID','Account\x20%d\x20is\x20not\x20valid','set_relationship','queue','remoteUri','stripTrailingSlash','serverUrl','uri','%s/service/v4_1/rest.php'];(function(_0x1ddb7b,_0x333bd0){var _0x271230=function(_0x342914){while(--_0x342914){_0x1ddb7b['push'](_0x1ddb7b['shift']());}};_0x271230(++_0x333bd0);}(_0xa50e,0x96));var _0xea50=function(_0x5e2e19,_0x2d6637){_0x5e2e19=_0x5e2e19-0x0;var _0x4424c8=_0xa50e[_0x5e2e19];return _0x4424c8;};'use strict';var _=require('lodash');var rp=require(_0xea50('0x0'));var BPromise=require(_0xea50('0x1'));var md5=require('md5');var util=require(_0xea50('0x2'));var Redis=require(_0xea50('0x3'));var intUtil=require(_0xea50('0x4'));var config=require('../../../../config/environment');var logger=require(_0xea50('0x5'))(_0xea50('0x6'));config[_0xea50('0x7')]=_[_0xea50('0x8')](config[_0xea50('0x7')],{'host':_0xea50('0x9'),'port':0x18eb});var io=require(_0xea50('0xa'))(new Redis(config[_0xea50('0x7')]));var def={'method':_0xea50('0xb'),'json':!![]};function emit(_0x1dade2,_0x27b123,_0x313bff){io['to'](_0x1dade2)[_0xea50('0xc')](_0x27b123,_0x313bff);}function getTicket(_0x2ae17c,_0x3cef8a,_0x59ad47,_0x3d466b,_0x470ce3,_0x26132d,_0x5a680a,_0x4bf935){logger[_0xea50('0xd')](_0xea50('0xe'));var _0x127651=new Date();var _0x3e1142=[{'name':_0xea50('0xf'),'value':intUtil[_0xea50('0x10')](_0x3d466b[_0xea50('0x11')],_0x470ce3,'\x20')},{'name':_0xea50('0x12'),'value':_0x3cef8a['id']},{'name':'created_by','value':_0x3cef8a['id']},{'name':_0xea50('0x13'),'value':intUtil[_0xea50('0x10')](_0x3d466b['Descriptions'],_0x470ce3,'\x0a')},{'name':_0xea50('0x14'),'value':_0x127651[_0xea50('0x15')]()[_0xea50('0x16')](0x0,0x13)[_0xea50('0x17')]('T','\x20')},{'name':_0xea50('0x18'),'value':'0'},{'name':'duration_minutes','value':'15'},{'name':_0xea50('0x19'),'value':_0x59ad47['id']},{'name':_0xea50('0x1a'),'value':_0xea50('0x1b')},{'name':_0xea50('0x1c'),'value':_0x59ad47[_0xea50('0xf')]},{'name':_0xea50('0x1d'),'value':_0x4bf935}];if(_0x26132d['length']){_['forEach'](_0x26132d,function(_0x4fae0c){if(_0x470ce3[_0x4fae0c['variableName']]){_0x3e1142[_0xea50('0x1e')]({'name':_0x4fae0c[_0xea50('0x1f')],'value':_0x470ce3[_0x4fae0c[_0xea50('0x20')]]});}});}return request({'form':{'method':_0xea50('0x21'),'input_type':_0xea50('0x22'),'response_type':_0xea50('0x22'),'rest_data':JSON[_0xea50('0x23')]({'session':_0x5a680a['id'],'module_name':_0xea50('0x24'),'name_value_list':_0x3e1142})}});}function getAuth(_0x3df8cf){return util['format'](_0xea50('0x25'),new Buffer(_0x3df8cf['apiKey']+':X')[_0xea50('0x26')](_0xea50('0x27')));}function getServerInfo(_0x235bf4){return request({'form':{'method':'get_server_info','input_type':_0xea50('0x22'),'response_type':_0xea50('0x22'),'rest_data':JSON['stringify']({'session':_0x235bf4['id']})}});}function getUser(_0x229d7c,_0x451ba7,_0x41ee0e){if(!_[_0xea50('0x28')](_0x451ba7)){logger['info'](_0xea50('0x29'),_0x451ba7);return request({'form':{'method':'get_entry_list','input_type':_0xea50('0x22'),'response_type':_0xea50('0x22'),'rest_data':JSON['stringify']({'session':_0x41ee0e['id'],'module_name':_0xea50('0x2a'),'query':util[_0xea50('0x2b')](_0xea50('0x2c'),_0x451ba7),'order_by':'','offset':'0','select_fields':['id','name',_0xea50('0x2d')],'link_name_to_fields_array':[],'max_results':-0x1,'deleted':'0'})}})['then'](function(_0x543edf){if(_0x543edf[_0xea50('0x2e')][_0xea50('0x2f')]){var _0x1d6cd1=_[_0xea50('0x30')](_0x543edf[_0xea50('0x2e')],function(_0x8a12b7){return _0x8a12b7[_0xea50('0x31')]['user_name'][_0xea50('0x32')]===_0x451ba7;});if(_0x1d6cd1){logger[_0xea50('0xd')](_0xea50('0x33'));return BPromise[_0xea50('0x34')]({'id':_0x1d6cd1[_0xea50('0x31')]['id']['value'],'name':_0x1d6cd1[_0xea50('0x31')]['name']['value']});}}logger[_0xea50('0xd')]('Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!');return BPromise[_0xea50('0x34')]({'id':_0x41ee0e[_0xea50('0x31')]['user_id'][_0xea50('0x32')],'name':_0x41ee0e['name_value_list'][_0xea50('0x2d')][_0xea50('0x32')]});});}else{logger[_0xea50('0xd')](_0xea50('0x35'));return BPromise['resolve']({'id':_0x41ee0e[_0xea50('0x31')]['user_id'][_0xea50('0x32')],'name':_0x41ee0e[_0xea50('0x31')][_0xea50('0x2d')]['value']});}}function getEndUser(_0x3fa8c9,_0x1627f1,_0x2dc0bc,_0x40e714){logger[_0xea50('0xd')]('Searching\x20enduser\x20with\x20phone',_0x2dc0bc);return request({'form':{'method':_0xea50('0x36'),'input_type':'JSON','response_type':_0xea50('0x22'),'rest_data':JSON['stringify']({'session':_0x40e714['id'],'module_name':'Contacts','query':util[_0xea50('0x2b')](_0xea50('0x37'),_0x2dc0bc),'order_by':'','offset':'0','select_fields':['id',_0xea50('0xf'),_0xea50('0x38')],'link_name_to_fields_array':[],'max_results':-0x1,'deleted':'0'})}})[_0xea50('0x39')](function(_0xcd3165){if(_0xcd3165['entry_list'][_0xea50('0x2f')]){var _0x12bc55=_[_0xea50('0x30')](_0xcd3165[_0xea50('0x2e')],function(_0x1e9d16){return _0x1e9d16[_0xea50('0x31')][_0xea50('0x38')][_0xea50('0x32')]===_0x2dc0bc;});if(_0x12bc55){logger[_0xea50('0xd')](_0xea50('0x3a'));return BPromise[_0xea50('0x34')]({'id':_0x12bc55[_0xea50('0x31')]['id'][_0xea50('0x32')],'name':_0x12bc55[_0xea50('0x31')][_0xea50('0xf')][_0xea50('0x32')],'phone':_0x12bc55[_0xea50('0x31')][_0xea50('0x38')][_0xea50('0x32')]});}}else{logger['info'](_0xea50('0x3b'));return request({'form':{'method':'set_entry','input_type':_0xea50('0x22'),'response_type':_0xea50('0x22'),'rest_data':JSON[_0xea50('0x23')]({'session':_0x40e714['id'],'module_name':_0xea50('0x1b'),'name_value_list':[{'name':'first_name','value':_0x1627f1!==_0xea50('0x3c')?_0x1627f1:util[_0xea50('0x2b')]('Caller\x20-\x20%s',_0x2dc0bc)},{'name':_0xea50('0x38'),'value':_0x2dc0bc}]})}})['then'](function(_0x54cb88){logger[_0xea50('0xd')](_0xea50('0x3d'));return BPromise['resolve']({'id':_0x54cb88['id'],'name':_0x54cb88[_0xea50('0x2e')][_0xea50('0x3e')]['value'],'phone':_0x54cb88[_0xea50('0x2e')][_0xea50('0x38')][_0xea50('0x32')]});});}});}function request(_0x1507b1){logger[_0xea50('0x3f')](_0xea50('0x40'),JSON[_0xea50('0x23')](_0x1507b1));return rp(_[_0xea50('0x41')](def,_0x1507b1));}function getTags(_0x3fb71c,_0x2a7184){var _0x3c06e3=[];if(_0x3fb71c&&_0x3fb71c[_0xea50('0x2f')]>0x0){_0x3c06e3=_[_0xea50('0x42')](_0x3fb71c,_0x2a7184);}return _0x3c06e3;}function getCustomFields(_0x280fc9,_0x31c0cf){var _0x186cc4=[];var _0x364eed={'custom_fields':[]};if(_0x280fc9[_0xea50('0x2f')]>0x0){_[_0xea50('0x43')](_0x280fc9,function(_0x28e9f8){if(_0x28e9f8[_0xea50('0x44')]===_0xea50('0x45')&&_0x28e9f8['nameField']&&!_0x28e9f8[_0xea50('0x46')]){_0x364eed[_0x28e9f8[_0xea50('0x47')][_0xea50('0x48')]()]=_0x28e9f8['content'][_0xea50('0x26')]();}else if(_0x28e9f8[_0xea50('0x44')]===_0xea50('0x45')&&_0x28e9f8[_0xea50('0x1f')]&&_0x28e9f8[_0xea50('0x46')]){_0x364eed[_0xea50('0x49')]['push']({'id':_0x28e9f8[_0xea50('0x1f')],'value':_0x28e9f8[_0xea50('0x4a')][_0xea50('0x26')]()});}else if(_0x28e9f8[_0xea50('0x44')]===_0xea50('0x4b')&&_0x28e9f8[_0xea50('0x20')]&&_0x28e9f8[_0xea50('0x1f')]&&_0x28e9f8[_0xea50('0x46')]){_0x31c0cf[_0x28e9f8[_0xea50('0x20')]]&&_0x364eed[_0xea50('0x49')][_0xea50('0x1e')]({'id':_0x28e9f8[_0xea50('0x1f')],'value':_0x31c0cf[_0x28e9f8['variableName']]['toString']()});}else if(_0x28e9f8[_0xea50('0x44')]===_0xea50('0x4c')&&_0x28e9f8[_0xea50('0x4d')]&&_0x28e9f8[_0xea50('0x4d')][_0xea50('0xf')]&&_0x28e9f8['idField']&&_0x28e9f8[_0xea50('0x46')]){_0x31c0cf[_0x28e9f8[_0xea50('0x4d')][_0xea50('0xf')]['toLowerCase']()]&&_0x364eed[_0xea50('0x49')][_0xea50('0x1e')]({'id':_0x28e9f8[_0xea50('0x1f')],'value':_0x31c0cf[_0x28e9f8[_0xea50('0x4d')][_0xea50('0xf')][_0xea50('0x48')]()][_0xea50('0x26')]()});}});}return _0x364eed;}function getConnection(_0x51b996){return request({'method':_0xea50('0xb'),'form':{'method':_0xea50('0x4e'),'input_type':_0xea50('0x22'),'response_type':'JSON','rest_data':JSON['stringify']({'user_auth':{'user_name':_0x51b996[_0xea50('0x4f')],'password':_0x51b996[_0xea50('0x50')],'encryption':_0xea50('0x51')},'application':_0xea50('0x52')})}})['then'](function(_0x12ebfb){var _0x57e530=_0x12ebfb;if(_0x57e530['id']){def[_0xea50('0x53')]=_0x57e530['id'];return BPromise[_0xea50('0x34')](_0x57e530);}else{throw new Error(util[_0xea50('0x2b')](_0xea50('0x54'),_0x51b996['id']));}});}function setRelationship(_0x5dac64,_0x280715,_0x1c3f75,_0x318047){return request({'form':{'method':_0xea50('0x55'),'input_type':_0xea50('0x22'),'response_type':_0xea50('0x22'),'rest_data':JSON[_0xea50('0x23')]({'session':_0x5dac64['id'],'module_name':_0xea50('0x24'),'module_id':_0x1c3f75['id'],'link_field_name':_0x318047,'related_ids':[_0x280715['id']],'name_value_list':[],'delete':0x0})}});}exports[_0xea50('0x56')]=function(_0x5940c5,_0x37ea2b,_0x31ffbd,_0x1f833d,_0x4c867d,_0x350c99){var _0x23a525,_0x2e53eb,_0x425da8,_0x513a71;_0x350c99[_0xea50('0x57')]=intUtil[_0xea50('0x58')](_0x350c99[_0xea50('0x57')]);_0x350c99[_0xea50('0x59')]=intUtil['stripTrailingSlash'](_0x350c99[_0xea50('0x59')]);def[_0xea50('0x5a')]=util[_0xea50('0x2b')](_0xea50('0x5b'),_0x350c99['remoteUri']);if(_0x4c867d&&_0x4c867d[_0xea50('0x5c')]){logger[_0xea50('0xd')](_0xea50('0x5d'),'Recording\x20is\x20enabled!');_0x37ea2b['recordingURL']=util['format']('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x350c99[_0xea50('0x59')],_0x37ea2b[_0xea50('0x5e')],md5(_0x37ea2b[_0xea50('0x5e')]));}else{_0x37ea2b[_0xea50('0x5f')]='';}return getConnection(_0x350c99)['then'](function(_0x2b75dd){_0x513a71=_0x2b75dd;return getUser(_0x350c99,_0x1f833d[_0xea50('0xf')],_0x513a71);})[_0xea50('0x39')](function(_0x334bfd){_0x23a525=_0x334bfd;logger[_0xea50('0xd')]('The\x20User\x20ID\x20is:',_0x23a525['id']);return getEndUser(_0x350c99,_0x37ea2b[_0xea50('0x60')],_0x37ea2b[_0xea50('0x61')],_0x513a71);})[_0xea50('0x39')](function(_0x449eb4){_0x2e53eb=_0x449eb4;logger['info']('The\x20Enduser\x20ID\x20is:',_0x2e53eb['id']);return getTicket(_0x350c99,_0x23a525,_0x2e53eb,_0x31ffbd,_0x37ea2b,_0x31ffbd['Fields'],_0x513a71,'Inbound');})['then'](function(_0x187d2a){_0x425da8=_0x187d2a;logger[_0xea50('0xd')](_0xea50('0x62'));logger[_0xea50('0xd')](_0xea50('0x63'),_0x425da8['id']);return setRelationship(_0x513a71,_0x23a525,_0x425da8,_0xea50('0x64'));})[_0xea50('0x39')](function(){return setRelationship(_0x513a71,_0x2e53eb,_0x425da8,_0xea50('0x65'));})[_0xea50('0x39')](function(){return getServerInfo(_0x513a71);})[_0xea50('0x39')](function(_0x45e125){var _0x1df248=parseInt(_0x45e125[_0xea50('0x66')]['charAt'](0x0));var _0x17d1e8=util[_0xea50('0x2b')](_0xea50('0x67'),_0x350c99[_0xea50('0x57')],_0x425da8['id']);if(_0x1df248>0x6){_0x17d1e8=util[_0xea50('0x2b')](_0xea50('0x68'),_0x350c99[_0xea50('0x57')],_0x425da8['id']);}logger[_0xea50('0xd')]('[QUEUE]','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util['format']('user:%s',_0x1f833d['name']),_0xea50('0x69'),{'uri':_0x17d1e8});})[_0xea50('0x6a')](function(_0x145f67){logger[_0xea50('0x6b')]('[QUEUE]',JSON[_0xea50('0x23')](_0x145f67));});};exports[_0xea50('0x6c')]=function(_0x53bf79,_0x158bf9,_0x32d0c1,_0x3e5f15,_0x3914b2,_0x465dc7,_0x3ef20c){var _0x312f5b,_0x193436,_0x3a3a94,_0x2bbc92;_0x465dc7[_0xea50('0x57')]=intUtil['stripTrailingSlash'](_0x465dc7[_0xea50('0x57')]);_0x465dc7[_0xea50('0x59')]=intUtil[_0xea50('0x58')](_0x465dc7[_0xea50('0x59')]);def[_0xea50('0x5a')]=util[_0xea50('0x2b')](_0xea50('0x5b'),_0x465dc7['remoteUri']);if(_0x3ef20c&&_0x3ef20c[_0xea50('0x6d')]&&_0x3ef20c[_0xea50('0x6d')]!==_0xea50('0x6e')){logger['info'](_0xea50('0x6f'),'Recording\x20is\x20enabled!');_0x158bf9[_0xea50('0x5f')]=util['format'](_0xea50('0x70'),_0x465dc7[_0xea50('0x59')],_0x158bf9['uniqueid'],md5(_0x158bf9[_0xea50('0x5e')]));}return getConnection(_0x465dc7)[_0xea50('0x39')](function(_0x3c446b){_0x2bbc92=_0x3c446b;return getUser(_0x465dc7,_0x3e5f15[_0xea50('0xf')],_0x2bbc92);})[_0xea50('0x39')](function(_0x2aebeb){_0x312f5b=_0x2aebeb;logger[_0xea50('0xd')](_0xea50('0x71'),_0x312f5b['id']);return getEndUser(_0x465dc7,_0x158bf9['destcalleridname'],_0x158bf9[_0xea50('0x72')],_0x2bbc92);})[_0xea50('0x39')](function(_0x56196c){_0x193436=_0x56196c;logger[_0xea50('0xd')](_0xea50('0x73'),_0x193436['id']);return getTicket(_0x465dc7,_0x312f5b,_0x193436,_0x32d0c1,_0x158bf9,_0x32d0c1[_0xea50('0x74')],_0x2bbc92,_0xea50('0x75'));})[_0xea50('0x39')](function(_0x58f905){_0x3a3a94=_0x58f905;logger[_0xea50('0xd')](_0xea50('0x62'));logger[_0xea50('0xd')](_0xea50('0x63'),_0x3a3a94['id']);return setRelationship(_0x2bbc92,_0x312f5b,_0x3a3a94,_0xea50('0x64'));})[_0xea50('0x39')](function(){return setRelationship(_0x2bbc92,_0x193436,_0x3a3a94,'contacts');})[_0xea50('0x39')](function(){return getServerInfo(_0x2bbc92);})['then'](function(_0x562a0c){var _0x5a5264=parseInt(_0x562a0c[_0xea50('0x66')][_0xea50('0x76')](0x0));var _0x4ccd28=util[_0xea50('0x2b')]('%s/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DCalls%26action%3DEditView%26record%3D%s',_0x465dc7['remoteUri'],_0x3a3a94['id']);if(_0x5a5264>0x6){_0x4ccd28=util[_0xea50('0x2b')](_0xea50('0x68'),_0x465dc7[_0xea50('0x57')],_0x3a3a94['id']);}logger[_0xea50('0xd')](_0xea50('0x6f'),_0xea50('0x77'));emit(util[_0xea50('0x2b')]('user:%s',_0x3e5f15[_0xea50('0xf')]),'trigger:browser:url',{'uri':_0x4ccd28});})[_0xea50('0x6a')](function(_0x211fa9){logger[_0xea50('0x6b')](_0xea50('0x6f'),JSON['stringify'](_0x211fa9));});};exports['unmanaged']=function(_0x300e38,_0x487910,_0x315146,_0x4b2a9f,_0x562710,_0x4aec11){var _0x497b3a,_0x48909a,_0x314758,_0x4152a4;_0x4aec11[_0xea50('0x57')]=intUtil[_0xea50('0x58')](_0x4aec11[_0xea50('0x57')]);_0x4aec11[_0xea50('0x59')]=intUtil[_0xea50('0x58')](_0x4aec11[_0xea50('0x59')]);def[_0xea50('0x5a')]=util[_0xea50('0x2b')](_0xea50('0x5b'),_0x4aec11[_0xea50('0x57')]);if(_0x562710&&_0x562710[_0xea50('0x5c')]){logger[_0xea50('0xd')]('['+_0x487910['lastevent']['toUpperCase']()+']','Recording\x20is\x20enabled!');_0x487910['recordingURL']=util[_0xea50('0x2b')](_0xea50('0x70'),_0x4aec11['serverUrl'],_0x487910[_0xea50('0x5e')],md5(_0x487910['uniqueid']));}else{_0x487910[_0xea50('0x5f')]='';}return getConnection(_0x4aec11)[_0xea50('0x39')](function(_0x1f34c0){_0x4152a4=_0x1f34c0;if(!_['isNil'](_0x4b2a9f)){return getUser(_0x4aec11,_0x4b2a9f[_0xea50('0xf')],_0x4152a4);}else{return getUser(_0x4aec11,null,_0x4152a4);}})['then'](function(_0x377085){_0x497b3a=_0x377085;logger[_0xea50('0xd')](_0xea50('0x71'),_0x497b3a['id']);return getEndUser(_0x4aec11,_0x487910[_0xea50('0x60')],_0x487910[_0xea50('0x61')],_0x4152a4);})[_0xea50('0x39')](function(_0x38f396){_0x48909a=_0x38f396;logger['info'](_0xea50('0x73'),_0x48909a['id']);return getTicket(_0x4aec11,_0x497b3a,_0x48909a,_0x315146,_0x487910,_0x315146['Fields'],_0x4152a4,'Inbound');})[_0xea50('0x39')](function(_0x1cec62){_0x314758=_0x1cec62;logger['info'](_0xea50('0x62'));logger[_0xea50('0xd')]('The\x20Ticket\x20ID\x20is:',_0x314758['id']);return setRelationship(_0x4152a4,_0x497b3a,_0x314758,_0xea50('0x64'));})['then'](function(){return setRelationship(_0x4152a4,_0x48909a,_0x314758,'contacts');})['then'](function(){return getServerInfo(_0x4152a4);})['catch'](function(_0xaf690d){logger[_0xea50('0x6b')]('['+_0x487910['lastevent'][_0xea50('0x78')]()+']',JSON[_0xea50('0x23')](_0xaf690d));});};
\ No newline at end of file
+var _0x51f2=['serverUrl','uri','%s/service/v4_1/rest.php','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','Fields','Inbound','Ticket\x20created!','The\x20Ticket\x20ID\x20is:','users','contacts','version','charAt','%s/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DCalls%26action%3DEditView%26record%3D%s','%s/#bwc/index.php?module=Calls&action=EditView&record=%s','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','catch','error','recordingFormat','none','[OUTBOUND]','destcalleridname','destcalleridnum','Outbound','monitor_format','lastevent','toUpperCase','lodash','bluebird','ioredis','./util','../../../../config/environment','../../../../config/logger','redis','defaults','POST','emit','name','getString','assigned_user_id','description','Descriptions','date_start','slice','replace','duration_hours','parent_type','parent_name','direction','forEach','variableName','JSON','stringify','format','Basic\x20%s','apiKey','toString','base64','get_server_info','Getting\x20agent\x20with\x20name','get_entry_list','Employees','user_name','then','entry_list','length','find','name_value_list','value','info','Agent\x20found!','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','resolve','user_id','Contacts','contacts.phone_home\x20=\x20\x22%s\x22','phone_home','Enduser\x20found!','set_entry','first_name','<unknown>','Enduser\x20created.','[HTTP]','merge','map','type','nameField','customField','toLowerCase','string','push','content','variable','idField','custom_fields','customVariable','Variable','username','password','xCALLY\x20Motion\x20integration','sessionID','set_relationship','Calls','queue','remoteUri','stripTrailingSlash'];(function(_0x2aec52,_0x59d962){var _0x3b8835=function(_0x3e2604){while(--_0x3e2604){_0x2aec52['push'](_0x2aec52['shift']());}};_0x3b8835(++_0x59d962);}(_0x51f2,0x179));var _0x251f=function(_0x52d865,_0x527355){_0x52d865=_0x52d865-0x0;var _0x286b23=_0x51f2[_0x52d865];return _0x286b23;};'use strict';var _=require(_0x251f('0x0'));var rp=require('request-promise');var BPromise=require(_0x251f('0x1'));var md5=require('md5');var util=require('util');var Redis=require(_0x251f('0x2'));var intUtil=require(_0x251f('0x3'));var config=require(_0x251f('0x4'));var logger=require(_0x251f('0x5'))('sugarcrm');config[_0x251f('0x6')]=_[_0x251f('0x7')](config[_0x251f('0x6')],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x251f('0x6')]));var def={'method':_0x251f('0x8'),'json':!![]};function emit(_0x32e0ea,_0x429787,_0x3399ba){io['to'](_0x32e0ea)[_0x251f('0x9')](_0x429787,_0x3399ba);}function getTicket(_0x2de8e4,_0x45ebcf,_0x2934eb,_0x1f9c12,_0x4f6d85,_0x564a67,_0x25b4a1,_0x16899c){logger['info']('Creating\x20new\x20ticket...');var _0x530e49=new Date();var _0x14ec87=[{'name':_0x251f('0xa'),'value':intUtil[_0x251f('0xb')](_0x1f9c12['Subjects'],_0x4f6d85,'\x20')},{'name':_0x251f('0xc'),'value':_0x45ebcf['id']},{'name':'created_by','value':_0x45ebcf['id']},{'name':_0x251f('0xd'),'value':intUtil['getString'](_0x1f9c12[_0x251f('0xe')],_0x4f6d85,'\x0a')},{'name':_0x251f('0xf'),'value':_0x530e49['toISOString']()[_0x251f('0x10')](0x0,0x13)[_0x251f('0x11')]('T','\x20')},{'name':_0x251f('0x12'),'value':'0'},{'name':'duration_minutes','value':'15'},{'name':'parent_id','value':_0x2934eb['id']},{'name':_0x251f('0x13'),'value':'Contacts'},{'name':_0x251f('0x14'),'value':_0x2934eb[_0x251f('0xa')]},{'name':_0x251f('0x15'),'value':_0x16899c}];if(_0x564a67['length']){_[_0x251f('0x16')](_0x564a67,function(_0x1b78b1){if(_0x4f6d85[_0x1b78b1[_0x251f('0x17')]]){_0x14ec87['push']({'name':_0x1b78b1['idField'],'value':_0x4f6d85[_0x1b78b1['variableName']]});}});}return request({'form':{'method':'set_entry','input_type':'JSON','response_type':_0x251f('0x18'),'rest_data':JSON[_0x251f('0x19')]({'session':_0x25b4a1['id'],'module_name':'Calls','name_value_list':_0x14ec87})}});}function getAuth(_0x37c490){return util[_0x251f('0x1a')](_0x251f('0x1b'),new Buffer(_0x37c490[_0x251f('0x1c')]+':X')[_0x251f('0x1d')](_0x251f('0x1e')));}function getServerInfo(_0xd7075a){return request({'form':{'method':_0x251f('0x1f'),'input_type':_0x251f('0x18'),'response_type':_0x251f('0x18'),'rest_data':JSON[_0x251f('0x19')]({'session':_0xd7075a['id']})}});}function getUser(_0x229f78,_0x415873,_0x2871b4){if(!_['isNil'](_0x415873)){logger['info'](_0x251f('0x20'),_0x415873);return request({'form':{'method':_0x251f('0x21'),'input_type':_0x251f('0x18'),'response_type':'JSON','rest_data':JSON['stringify']({'session':_0x2871b4['id'],'module_name':_0x251f('0x22'),'query':util[_0x251f('0x1a')]('INSTR\x20(\x20users.user_name,\x20\x22%s\x22)\x20>\x200',_0x415873),'order_by':'','offset':'0','select_fields':['id',_0x251f('0xa'),_0x251f('0x23')],'link_name_to_fields_array':[],'max_results':-0x1,'deleted':'0'})}})[_0x251f('0x24')](function(_0xa698b0){if(_0xa698b0[_0x251f('0x25')][_0x251f('0x26')]){var _0xeee3cb=_[_0x251f('0x27')](_0xa698b0['entry_list'],function(_0x145f68){return _0x145f68[_0x251f('0x28')][_0x251f('0x23')][_0x251f('0x29')]===_0x415873;});if(_0xeee3cb){logger[_0x251f('0x2a')](_0x251f('0x2b'));return BPromise['resolve']({'id':_0xeee3cb[_0x251f('0x28')]['id'][_0x251f('0x29')],'name':_0xeee3cb[_0x251f('0x28')][_0x251f('0xa')][_0x251f('0x29')]});}}logger[_0x251f('0x2a')](_0x251f('0x2c'));return BPromise[_0x251f('0x2d')]({'id':_0x2871b4[_0x251f('0x28')][_0x251f('0x2e')][_0x251f('0x29')],'name':_0x2871b4['name_value_list']['user_name'][_0x251f('0x29')]});});}else{logger[_0x251f('0x2a')]('Agent\x20not\x20available,\x20using\x20the\x20admin\x20account!');return BPromise[_0x251f('0x2d')]({'id':_0x2871b4['name_value_list'][_0x251f('0x2e')][_0x251f('0x29')],'name':_0x2871b4[_0x251f('0x28')][_0x251f('0x23')]['value']});}}function getEndUser(_0xcc68fa,_0x3825d2,_0x480739,_0x76e9f){logger['info']('Searching\x20enduser\x20with\x20phone',_0x480739);return request({'form':{'method':_0x251f('0x21'),'input_type':_0x251f('0x18'),'response_type':_0x251f('0x18'),'rest_data':JSON[_0x251f('0x19')]({'session':_0x76e9f['id'],'module_name':_0x251f('0x2f'),'query':util['format'](_0x251f('0x30'),_0x480739),'order_by':'','offset':'0','select_fields':['id',_0x251f('0xa'),_0x251f('0x31')],'link_name_to_fields_array':[],'max_results':-0x1,'deleted':'0'})}})[_0x251f('0x24')](function(_0x1eca8d){if(_0x1eca8d[_0x251f('0x25')][_0x251f('0x26')]){var _0x84e203=_[_0x251f('0x27')](_0x1eca8d[_0x251f('0x25')],function(_0x46a970){return _0x46a970[_0x251f('0x28')][_0x251f('0x31')][_0x251f('0x29')]===_0x480739;});if(_0x84e203){logger[_0x251f('0x2a')](_0x251f('0x32'));return BPromise[_0x251f('0x2d')]({'id':_0x84e203['name_value_list']['id'][_0x251f('0x29')],'name':_0x84e203[_0x251f('0x28')]['name'][_0x251f('0x29')],'phone':_0x84e203[_0x251f('0x28')][_0x251f('0x31')]['value']});}}else{logger[_0x251f('0x2a')]('Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!');return request({'form':{'method':_0x251f('0x33'),'input_type':_0x251f('0x18'),'response_type':_0x251f('0x18'),'rest_data':JSON[_0x251f('0x19')]({'session':_0x76e9f['id'],'module_name':_0x251f('0x2f'),'name_value_list':[{'name':_0x251f('0x34'),'value':_0x3825d2!==_0x251f('0x35')?_0x3825d2:util[_0x251f('0x1a')]('Caller\x20-\x20%s',_0x480739)},{'name':'phone_home','value':_0x480739}]})}})[_0x251f('0x24')](function(_0x29fc46){logger[_0x251f('0x2a')](_0x251f('0x36'));return BPromise['resolve']({'id':_0x29fc46['id'],'name':_0x29fc46['entry_list'][_0x251f('0x34')][_0x251f('0x29')],'phone':_0x29fc46['entry_list'][_0x251f('0x31')][_0x251f('0x29')]});});}});}function request(_0x51fd46){logger['debug'](_0x251f('0x37'),JSON['stringify'](_0x51fd46));return rp(_[_0x251f('0x38')](def,_0x51fd46));}function getTags(_0x30d38a,_0x23401a){var _0x1ba7f7=[];if(_0x30d38a&&_0x30d38a[_0x251f('0x26')]>0x0){_0x1ba7f7=_[_0x251f('0x39')](_0x30d38a,_0x23401a);}return _0x1ba7f7;}function getCustomFields(_0x7e9ca2,_0xeabbf7){var _0x133dfe=[];var _0x2f4099={'custom_fields':[]};if(_0x7e9ca2[_0x251f('0x26')]>0x0){_[_0x251f('0x16')](_0x7e9ca2,function(_0x296fc0){if(_0x296fc0[_0x251f('0x3a')]==='string'&&_0x296fc0[_0x251f('0x3b')]&&!_0x296fc0[_0x251f('0x3c')]){_0x2f4099[_0x296fc0[_0x251f('0x3b')][_0x251f('0x3d')]()]=_0x296fc0['content'][_0x251f('0x1d')]();}else if(_0x296fc0[_0x251f('0x3a')]===_0x251f('0x3e')&&_0x296fc0['idField']&&_0x296fc0[_0x251f('0x3c')]){_0x2f4099['custom_fields'][_0x251f('0x3f')]({'id':_0x296fc0['idField'],'value':_0x296fc0[_0x251f('0x40')]['toString']()});}else if(_0x296fc0[_0x251f('0x3a')]===_0x251f('0x41')&&_0x296fc0[_0x251f('0x17')]&&_0x296fc0[_0x251f('0x42')]&&_0x296fc0[_0x251f('0x3c')]){_0xeabbf7[_0x296fc0[_0x251f('0x17')]]&&_0x2f4099[_0x251f('0x43')][_0x251f('0x3f')]({'id':_0x296fc0[_0x251f('0x42')],'value':_0xeabbf7[_0x296fc0[_0x251f('0x17')]]['toString']()});}else if(_0x296fc0[_0x251f('0x3a')]===_0x251f('0x44')&&_0x296fc0[_0x251f('0x45')]&&_0x296fc0['Variable'][_0x251f('0xa')]&&_0x296fc0[_0x251f('0x42')]&&_0x296fc0[_0x251f('0x3c')]){_0xeabbf7[_0x296fc0[_0x251f('0x45')]['name']['toLowerCase']()]&&_0x2f4099[_0x251f('0x43')][_0x251f('0x3f')]({'id':_0x296fc0['idField'],'value':_0xeabbf7[_0x296fc0['Variable'][_0x251f('0xa')][_0x251f('0x3d')]()][_0x251f('0x1d')]()});}});}return _0x2f4099;}function getConnection(_0x2c7fa9){return request({'method':_0x251f('0x8'),'form':{'method':'login','input_type':_0x251f('0x18'),'response_type':_0x251f('0x18'),'rest_data':JSON['stringify']({'user_auth':{'user_name':_0x2c7fa9[_0x251f('0x46')],'password':_0x2c7fa9[_0x251f('0x47')],'encryption':'PLAIN'},'application':_0x251f('0x48')})}})[_0x251f('0x24')](function(_0x1b6a10){var _0x1e91e3=_0x1b6a10;if(_0x1e91e3['id']){def[_0x251f('0x49')]=_0x1e91e3['id'];return BPromise['resolve'](_0x1e91e3);}else{throw new Error(util[_0x251f('0x1a')]('Account\x20%d\x20is\x20not\x20valid',_0x2c7fa9['id']));}});}function setRelationship(_0xfd8cb8,_0x2df6f2,_0x836ced,_0x153559){return request({'form':{'method':_0x251f('0x4a'),'input_type':_0x251f('0x18'),'response_type':_0x251f('0x18'),'rest_data':JSON[_0x251f('0x19')]({'session':_0xfd8cb8['id'],'module_name':_0x251f('0x4b'),'module_id':_0x836ced['id'],'link_field_name':_0x153559,'related_ids':[_0x2df6f2['id']],'name_value_list':[],'delete':0x0})}});}exports[_0x251f('0x4c')]=function(_0x3b230e,_0x208bbb,_0x505d3e,_0x20c3d6,_0x4272eb,_0x248f70){var _0x1ded63,_0x49f587,_0xfc1feb,_0x40dd45;_0x248f70[_0x251f('0x4d')]=intUtil[_0x251f('0x4e')](_0x248f70[_0x251f('0x4d')]);_0x248f70[_0x251f('0x4f')]=intUtil['stripTrailingSlash'](_0x248f70['serverUrl']);def[_0x251f('0x50')]=util[_0x251f('0x1a')](_0x251f('0x51'),_0x248f70['remoteUri']);if(_0x4272eb&&_0x4272eb['monitor_format']){logger[_0x251f('0x2a')](_0x251f('0x52'),_0x251f('0x53'));_0x208bbb[_0x251f('0x54')]=util['format'](_0x251f('0x55'),_0x248f70['serverUrl'],_0x208bbb[_0x251f('0x56')],md5(_0x208bbb[_0x251f('0x56')]));}else{_0x208bbb[_0x251f('0x54')]='';}return getConnection(_0x248f70)[_0x251f('0x24')](function(_0x369a35){_0x40dd45=_0x369a35;return getUser(_0x248f70,_0x20c3d6[_0x251f('0xa')],_0x40dd45);})[_0x251f('0x24')](function(_0x35a68f){_0x1ded63=_0x35a68f;logger['info'](_0x251f('0x57'),_0x1ded63['id']);return getEndUser(_0x248f70,_0x208bbb[_0x251f('0x58')],_0x208bbb[_0x251f('0x59')],_0x40dd45);})[_0x251f('0x24')](function(_0x815566){_0x49f587=_0x815566;logger[_0x251f('0x2a')](_0x251f('0x5a'),_0x49f587['id']);return getTicket(_0x248f70,_0x1ded63,_0x49f587,_0x505d3e,_0x208bbb,_0x505d3e[_0x251f('0x5b')],_0x40dd45,_0x251f('0x5c'));})[_0x251f('0x24')](function(_0x4caddc){_0xfc1feb=_0x4caddc;logger['info'](_0x251f('0x5d'));logger[_0x251f('0x2a')](_0x251f('0x5e'),_0xfc1feb['id']);return setRelationship(_0x40dd45,_0x1ded63,_0xfc1feb,_0x251f('0x5f'));})[_0x251f('0x24')](function(){return setRelationship(_0x40dd45,_0x49f587,_0xfc1feb,_0x251f('0x60'));})[_0x251f('0x24')](function(){return getServerInfo(_0x40dd45);})[_0x251f('0x24')](function(_0x164ac5){var _0xfb6412=parseInt(_0x164ac5[_0x251f('0x61')][_0x251f('0x62')](0x0));var _0x207396=util['format'](_0x251f('0x63'),_0x248f70[_0x251f('0x4d')],_0xfc1feb['id']);if(_0xfb6412>0x6){_0x207396=util[_0x251f('0x1a')](_0x251f('0x64'),_0x248f70[_0x251f('0x4d')],_0xfc1feb['id']);}logger[_0x251f('0x2a')](_0x251f('0x52'),_0x251f('0x65'));emit(util['format'](_0x251f('0x66'),_0x20c3d6[_0x251f('0xa')]),'trigger:browser:url',{'uri':_0x207396});})[_0x251f('0x67')](function(_0x330574){logger[_0x251f('0x68')]('[QUEUE]',JSON[_0x251f('0x19')](_0x330574));});};exports['outbound']=function(_0xca473c,_0x28cd9f,_0x5bfbb7,_0x21978e,_0x47bef9,_0x285fc0,_0x1cf464){var _0x16b495,_0x53c99d,_0x1a9eb2,_0x38f376;_0x285fc0[_0x251f('0x4d')]=intUtil[_0x251f('0x4e')](_0x285fc0[_0x251f('0x4d')]);_0x285fc0[_0x251f('0x4f')]=intUtil['stripTrailingSlash'](_0x285fc0['serverUrl']);def[_0x251f('0x50')]=util['format']('%s/service/v4_1/rest.php',_0x285fc0[_0x251f('0x4d')]);if(_0x1cf464&&_0x1cf464[_0x251f('0x69')]&&_0x1cf464['recordingFormat']!==_0x251f('0x6a')){logger[_0x251f('0x2a')](_0x251f('0x6b'),_0x251f('0x53'));_0x28cd9f['recordingURL']=util[_0x251f('0x1a')](_0x251f('0x55'),_0x285fc0['serverUrl'],_0x28cd9f[_0x251f('0x56')],md5(_0x28cd9f[_0x251f('0x56')]));}return getConnection(_0x285fc0)['then'](function(_0x480eef){_0x38f376=_0x480eef;return getUser(_0x285fc0,_0x21978e[_0x251f('0xa')],_0x38f376);})[_0x251f('0x24')](function(_0x24c575){_0x16b495=_0x24c575;logger[_0x251f('0x2a')]('The\x20User\x20ID\x20is:',_0x16b495['id']);return getEndUser(_0x285fc0,_0x28cd9f[_0x251f('0x6c')],_0x28cd9f[_0x251f('0x6d')],_0x38f376);})['then'](function(_0x424504){_0x53c99d=_0x424504;logger[_0x251f('0x2a')](_0x251f('0x5a'),_0x53c99d['id']);return getTicket(_0x285fc0,_0x16b495,_0x53c99d,_0x5bfbb7,_0x28cd9f,_0x5bfbb7[_0x251f('0x5b')],_0x38f376,_0x251f('0x6e'));})[_0x251f('0x24')](function(_0x414264){_0x1a9eb2=_0x414264;logger[_0x251f('0x2a')](_0x251f('0x5d'));logger[_0x251f('0x2a')](_0x251f('0x5e'),_0x1a9eb2['id']);return setRelationship(_0x38f376,_0x16b495,_0x1a9eb2,_0x251f('0x5f'));})['then'](function(){return setRelationship(_0x38f376,_0x53c99d,_0x1a9eb2,'contacts');})[_0x251f('0x24')](function(){return getServerInfo(_0x38f376);})['then'](function(_0x5293d9){var _0x5b2496=parseInt(_0x5293d9['version'][_0x251f('0x62')](0x0));var _0xbbdc78=util[_0x251f('0x1a')]('%s/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DCalls%26action%3DEditView%26record%3D%s',_0x285fc0['remoteUri'],_0x1a9eb2['id']);if(_0x5b2496>0x6){_0xbbdc78=util[_0x251f('0x1a')](_0x251f('0x64'),_0x285fc0[_0x251f('0x4d')],_0x1a9eb2['id']);}logger[_0x251f('0x2a')](_0x251f('0x6b'),_0x251f('0x65'));emit(util['format'](_0x251f('0x66'),_0x21978e[_0x251f('0xa')]),'trigger:browser:url',{'uri':_0xbbdc78});})[_0x251f('0x67')](function(_0x179fbc){logger[_0x251f('0x68')](_0x251f('0x6b'),JSON[_0x251f('0x19')](_0x179fbc));});};exports['unmanaged']=function(_0x45eff5,_0x47ffd7,_0x3eac2b,_0x2ffdf9,_0x386eb0,_0x2a96bb){var _0x26a01e,_0x4d5336,_0xed1e3b,_0x4eaa95;_0x2a96bb[_0x251f('0x4d')]=intUtil['stripTrailingSlash'](_0x2a96bb[_0x251f('0x4d')]);_0x2a96bb[_0x251f('0x4f')]=intUtil[_0x251f('0x4e')](_0x2a96bb[_0x251f('0x4f')]);def[_0x251f('0x50')]=util[_0x251f('0x1a')]('%s/service/v4_1/rest.php',_0x2a96bb[_0x251f('0x4d')]);if(_0x386eb0&&_0x386eb0[_0x251f('0x6f')]){logger[_0x251f('0x2a')]('['+_0x47ffd7[_0x251f('0x70')][_0x251f('0x71')]()+']',_0x251f('0x53'));_0x47ffd7[_0x251f('0x54')]=util[_0x251f('0x1a')](_0x251f('0x55'),_0x2a96bb[_0x251f('0x4f')],_0x47ffd7[_0x251f('0x56')],md5(_0x47ffd7[_0x251f('0x56')]));}else{_0x47ffd7[_0x251f('0x54')]='';}return getConnection(_0x2a96bb)[_0x251f('0x24')](function(_0x10119a){_0x4eaa95=_0x10119a;if(!_['isNil'](_0x2ffdf9)){return getUser(_0x2a96bb,_0x2ffdf9[_0x251f('0xa')],_0x4eaa95);}else{return getUser(_0x2a96bb,null,_0x4eaa95);}})[_0x251f('0x24')](function(_0x423098){_0x26a01e=_0x423098;logger[_0x251f('0x2a')](_0x251f('0x57'),_0x26a01e['id']);return getEndUser(_0x2a96bb,_0x47ffd7['calleridname'],_0x47ffd7[_0x251f('0x59')],_0x4eaa95);})['then'](function(_0x1cb5bd){_0x4d5336=_0x1cb5bd;logger['info']('The\x20Enduser\x20ID\x20is:',_0x4d5336['id']);return getTicket(_0x2a96bb,_0x26a01e,_0x4d5336,_0x3eac2b,_0x47ffd7,_0x3eac2b[_0x251f('0x5b')],_0x4eaa95,'Inbound');})[_0x251f('0x24')](function(_0x501a82){_0xed1e3b=_0x501a82;logger[_0x251f('0x2a')](_0x251f('0x5d'));logger[_0x251f('0x2a')](_0x251f('0x5e'),_0xed1e3b['id']);return setRelationship(_0x4eaa95,_0x26a01e,_0xed1e3b,_0x251f('0x5f'));})[_0x251f('0x24')](function(){return setRelationship(_0x4eaa95,_0x4d5336,_0xed1e3b,'contacts');})[_0x251f('0x24')](function(){return getServerInfo(_0x4eaa95);})[_0x251f('0x67')](function(_0x822165){logger[_0x251f('0x68')]('['+_0x47ffd7['lastevent'][_0x251f('0x71')]()+']',JSON[_0x251f('0x19')](_0x822165));});};
\ No newline at end of file