Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / services / ami / trigger / integration / desk.js
index 8e4e680..b37c860 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x38af=['name','priority','phone','Motion','Tags','Descriptions','/api/v2/users/%d','user','getString','%s/customers/%d/cases','stripTrailingSlash','serverUrl','monitor_format','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','Authorization','email','calleridnum','Ticket\x20created!','The\x20Ticket\x20ID\x20is:','integrationTab','[QUEUE]','Displaying\x20ticket\x20to\x20agent...','user:%s','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','trigger:browser:url','catch','error','recordingFormat','none','Recording\x20is\x20enabled!','uniqueid','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','The\x20Enduser\x20ID\x20is:','newTab','%s/agent/tickets/%s','Desk\x20account\x20type\x20not\x20recognized','[OUTBOUND]','lastevent','toUpperCase','lodash','request-promise','md5','ioredis','../../../../config/logger','desk','redis','defaults','localhost','socket.io-emitter','emit','application/json','info','Getting\x20agent\x20with\x20email','format','remoteUri','total_entries','find','_embedded','entries','then','Agent\x20found!','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me','Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!','[HTTP]','stringify','GET','authType','basic','username','password','token','%s/token:%s','Basic\x20%s','toString','base64','Searching\x20enduser\x20with\x20phone','Enduser\x20found!','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','%s/customers','POST','length','picklist','type','nameField','toLowerCase','includes','idField','custom_fields','content','variable','variableName','customVariable','Variable'];(function(_0x1dc59e,_0x424444){var _0x476887=function(_0x1e1d96){while(--_0x1e1d96){_0x1dc59e['push'](_0x1dc59e['shift']());}};_0x476887(++_0x424444);}(_0x38af,0x1ae));var _0xf38a=function(_0x578328,_0x5f5a8e){_0x578328=_0x578328-0x0;var _0x32b4b1=_0x38af[_0x578328];return _0x32b4b1;};'use strict';var _=require(_0xf38a('0x0'));var rp=require(_0xf38a('0x1'));var md5=require(_0xf38a('0x2'));var util=require('util');var Redis=require(_0xf38a('0x3'));var intUtil=require('./util');var config=require('../../../../config/environment');var logger=require(_0xf38a('0x4'))(_0xf38a('0x5'));config[_0xf38a('0x6')]=_[_0xf38a('0x7')](config['redis'],{'host':_0xf38a('0x8'),'port':0x18eb});var io=require(_0xf38a('0x9'))(new Redis(config['redis']));function emit(_0x380b84,_0x2242d0,_0x398f20){io['to'](_0x380b84)[_0xf38a('0xa')](_0x2242d0,_0x398f20);}var headers={'Content-Type':_0xf38a('0xb'),'Accept':_0xf38a('0xb')};function getUser(_0x645fb6,_0x3a4294){if(intUtil['validateEmail'](_0x3a4294)===!![]){logger[_0xf38a('0xc')](_0xf38a('0xd'),_0x3a4294);return request({'uri':util[_0xf38a('0xe')]('%s/users',_0x645fb6[_0xf38a('0xf')])})['then'](function(_0x40e2e1){if(_0x40e2e1[_0xf38a('0x10')]){return _[_0xf38a('0x11')](_0x40e2e1[_0xf38a('0x12')][_0xf38a('0x13')],{'email':_0x3a4294});}})[_0xf38a('0x14')](function(_0x17a893){if(_0x17a893){logger[_0xf38a('0xc')](_0xf38a('0x15'));return _0x17a893;}else{logger[_0xf38a('0xc')](_0xf38a('0x16'));return request({'uri':util['format'](_0xf38a('0x17'),_0x645fb6[_0xf38a('0xf')])});}});}else{logger['info'](_0xf38a('0x18'));return request({'uri':util[_0xf38a('0xe')](_0xf38a('0x17'),_0x645fb6[_0xf38a('0xf')])});}}function request(_0x7ab6c7){logger['debug'](_0xf38a('0x19'),JSON[_0xf38a('0x1a')](_0x7ab6c7));return rp(_[_0xf38a('0x7')](_0x7ab6c7,{'method':_0xf38a('0x1b'),'headers':headers,'json':!![]}));}function getAuth(_0x43bbd5){var _0x36428b;if(_0x43bbd5[_0xf38a('0x1c')]===_0xf38a('0x1d')){_0x36428b=util[_0xf38a('0xe')]('%s:%s',_0x43bbd5[_0xf38a('0x1e')],_0x43bbd5[_0xf38a('0x1f')]);}else if(_0x43bbd5['authType']===_0xf38a('0x20')){_0x36428b=util[_0xf38a('0xe')](_0xf38a('0x21'),_0x43bbd5[_0xf38a('0x1e')],_0x43bbd5[_0xf38a('0x20')]);}return util[_0xf38a('0xe')](_0xf38a('0x22'),new Buffer(_0x36428b)[_0xf38a('0x23')](_0xf38a('0x24')));}function getEndUser(_0x44f09e,_0x18e815,_0x2ec0c9){logger[_0xf38a('0xc')](_0xf38a('0x25'),_0x2ec0c9);return request({'uri':util[_0xf38a('0xe')]('%s/customers/search',_0x44f09e[_0xf38a('0xf')]),'qs':{'phone':_0x2ec0c9}})['then'](function(_0x56016f){if(_0x56016f['total_entries']){logger[_0xf38a('0xc')](_0xf38a('0x26'));return _0x56016f[_0xf38a('0x12')][_0xf38a('0x13')][0x0];}else{logger[_0xf38a('0xc')](_0xf38a('0x27'));return request({'uri':util[_0xf38a('0xe')](_0xf38a('0x28'),_0x44f09e[_0xf38a('0xf')]),'method':_0xf38a('0x29'),'body':{'first_name':_0x18e815,'title':_0x18e815,'phone_numbers':[{'type':'work','value':_0x2ec0c9}]}});}});}function getTags(_0x175e83,_0x2e5790){var _0x50101c=[];if(_0x175e83&&_0x175e83[_0xf38a('0x2a')]>0x0){_0x50101c=_['map'](_0x175e83,_0x2e5790);}return _0x50101c;}function getCustomFields(_0x8a3914,_0x876d6a){var _0xc1a16a=[];var _0x57f06b={'custom_fields':{}};if(_0x8a3914[_0xf38a('0x2a')]>0x0){_['forEach'](_0x8a3914,function(_0x1f1771){if(_['includes'](['string',_0xf38a('0x2b')],_0x1f1771[_0xf38a('0x2c')])&&_0x1f1771[_0xf38a('0x2d')]&&!_0x1f1771['customField']){_0x57f06b[_0x1f1771[_0xf38a('0x2d')][_0xf38a('0x2e')]()]=_0x1f1771['content'][_0xf38a('0x23')]();}else if(_[_0xf38a('0x2f')](['string',_0xf38a('0x2b')],_0x1f1771[_0xf38a('0x2c')])&&_0x1f1771[_0xf38a('0x30')]&&_0x1f1771['customField']){_0x57f06b[_0xf38a('0x31')][_0x1f1771['idField']]=_0x1f1771[_0xf38a('0x32')][_0xf38a('0x23')]();}else if(_0x1f1771[_0xf38a('0x2c')]===_0xf38a('0x33')&&_0x1f1771[_0xf38a('0x34')]&&_0x1f1771[_0xf38a('0x30')]&&_0x1f1771['customField']){_0x876d6a[_0x1f1771[_0xf38a('0x34')]]&&(_0x57f06b[_0xf38a('0x31')][_0x1f1771['idField']]=_0x876d6a[_0x1f1771[_0xf38a('0x34')]][_0xf38a('0x23')]());}else if(_0x1f1771[_0xf38a('0x2c')]===_0xf38a('0x35')&&_0x1f1771[_0xf38a('0x36')]&&_0x1f1771['Variable'][_0xf38a('0x37')]&&_0x1f1771[_0xf38a('0x30')]&&_0x1f1771['customField']){_0x876d6a[_0x1f1771[_0xf38a('0x36')][_0xf38a('0x37')][_0xf38a('0x2e')]()]&&(_0x57f06b[_0xf38a('0x31')][_0x1f1771[_0xf38a('0x30')]]=_0x876d6a[_0x1f1771['Variable'][_0xf38a('0x37')]['toLowerCase']()]['toString']());}});}if(_0x57f06b[_0xf38a('0x38')]){_0x57f06b['priority']=Number(_0x57f06b['priority']);}return _0x57f06b;}function getTicket(_0xeb6db9,_0x165b46,_0x31280b,_0x17cb9b,_0x381ee9){logger[_0xf38a('0xc')]('Creating\x20new\x20ticket...');var _0x1ac95a=_['merge']({'subject':intUtil['getString'](_0x17cb9b['Subjects'],_0x381ee9,'\x20'),'type':_0xf38a('0x39'),'status':'new','labels':['xCALLY',_0xf38a('0x3a'),'CTI']['concat'](getTags(_0x17cb9b[_0xf38a('0x3b')],_0xf38a('0x37'))),'description':intUtil['getString'](_0x17cb9b[_0xf38a('0x3c')],_0x381ee9,'\x0a'),'_links':{'assigned_user':{'href':util[_0xf38a('0xe')](_0xf38a('0x3d'),_0x165b46['id']),'class':_0xf38a('0x3e')}},'message':{'direction':'in','body':intUtil[_0xf38a('0x3f')](_0x17cb9b['Descriptions'],_0x381ee9,'\x0a')}},getCustomFields(_0x17cb9b['Fields'],_0x381ee9));return request({'uri':util['format'](_0xf38a('0x40'),_0xeb6db9['remoteUri'],_0x31280b['id']),'method':_0xf38a('0x29'),'body':_0x1ac95a});}exports['queue']=function(_0x23d217,_0x79ed5f,_0x25e12d,_0x5d0372,_0xe1a503,_0x400840){var _0x27564e,_0x4b01ba;_0x400840[_0xf38a('0xf')]=intUtil[_0xf38a('0x41')](_0x400840[_0xf38a('0xf')]);_0x400840['serverUrl']=intUtil[_0xf38a('0x41')](_0x400840[_0xf38a('0x42')]);if(_0xe1a503&&_0xe1a503[_0xf38a('0x43')]){logger[_0xf38a('0xc')]('[QUEUE]','Recording\x20is\x20enabled!');_0x79ed5f[_0xf38a('0x44')]=util[_0xf38a('0xe')](_0xf38a('0x45'),_0x400840[_0xf38a('0x42')],_0x79ed5f['uniqueid'],md5(_0x79ed5f['uniqueid']));}else{_0x79ed5f[_0xf38a('0x44')]='';}headers[_0xf38a('0x46')]=getAuth(_0x400840);return getUser(_0x400840,_0x5d0372[_0xf38a('0x47')])[_0xf38a('0x14')](function(_0x570e0b){_0x27564e=_0x570e0b;logger[_0xf38a('0xc')]('The\x20User\x20ID\x20is:',_0x27564e['id']);return getEndUser(_0x400840,_0x79ed5f['calleridname'],_0x79ed5f[_0xf38a('0x48')]);})[_0xf38a('0x14')](function(_0x3c531a){_0x4b01ba=_0x3c531a;logger[_0xf38a('0xc')]('The\x20Enduser\x20ID\x20is:',_0x4b01ba['id']);return getTicket(_0x400840,_0x27564e,_0x4b01ba,_0x25e12d,_0x79ed5f);})[_0xf38a('0x14')](function(_0x4d4640){if(_0x4d4640){logger['info'](_0xf38a('0x49'));logger[_0xf38a('0xc')](_0xf38a('0x4a'),_0x4d4640['id']);switch(_0x400840[_0xf38a('0x2c')]){case _0xf38a('0x4b'):logger[_0xf38a('0xc')](_0xf38a('0x4c'),_0xf38a('0x4d'));emit(util[_0xf38a('0xe')](_0xf38a('0x4e'),_0x5d0372['name']),'trigger:desk:display',{'recordId':_0x4d4640['id']});break;case'newTab':logger['info'](_0xf38a('0x4c'),_0xf38a('0x4f'));emit(util[_0xf38a('0xe')]('user:%s',_0x5d0372[_0xf38a('0x37')]),_0xf38a('0x50'),{'uri':util['format']('https://xcally.desk.com/web/agent/case/%d',_0x4d4640['id'])});break;default:logger['error'](_0xf38a('0x4c'),'Desk\x20account\x20type\x20not\x20recognized');}}})[_0xf38a('0x51')](function(_0x11e8f5){console[_0xf38a('0x52')](_0x11e8f5);logger[_0xf38a('0x52')]('[QUEUE]',JSON[_0xf38a('0x1a')](_0x11e8f5));});};exports['outbound']=function(_0x244067,_0x5d1c26,_0x384bc7,_0xfce155,_0x147fdc,_0x17dc6c,_0x1cf646){var _0x8d7cb1,_0x3e1bab;_0x17dc6c[_0xf38a('0xf')]=intUtil[_0xf38a('0x41')](_0x17dc6c['remoteUri']);_0x17dc6c[_0xf38a('0x42')]=intUtil['stripTrailingSlash'](_0x17dc6c[_0xf38a('0x42')]);if(_0x1cf646&&_0x1cf646['recordingFormat']&&_0x1cf646[_0xf38a('0x53')]!==_0xf38a('0x54')){logger['info']('[OUTBOUND]',_0xf38a('0x55'));_0x5d1c26[_0xf38a('0x44')]=util[_0xf38a('0xe')](_0xf38a('0x45'),_0x17dc6c['serverUrl'],_0x5d1c26[_0xf38a('0x56')],md5(_0x5d1c26[_0xf38a('0x56')]));}headers[_0xf38a('0x46')]=getAuth(_0x17dc6c);return getUser(_0x17dc6c,_0xfce155[_0xf38a('0x47')])[_0xf38a('0x14')](function(_0xf9b59b){_0x8d7cb1=_0xf9b59b;logger[_0xf38a('0xc')](_0xf38a('0x57'),_0x8d7cb1['id']);return getEndUser(_0x17dc6c,_0x5d1c26[_0xf38a('0x58')],_0x5d1c26[_0xf38a('0x59')]);})['then'](function(_0x56579d){_0x3e1bab=_0x56579d;logger[_0xf38a('0xc')](_0xf38a('0x5a'),_0x3e1bab['id']);return getTicket(_0x17dc6c,_0x8d7cb1,_0x3e1bab,_0x384bc7,_0x5d1c26);})['then'](function(_0x4b53cc){if(_0x4b53cc){logger[_0xf38a('0xc')](_0xf38a('0x49'));logger[_0xf38a('0xc')](_0xf38a('0x4a'),_0x4b53cc['id']);switch(_0x17dc6c['type']){case'integrationTab':logger['info'](_0xf38a('0x4c'),_0xf38a('0x4d'));emit(util[_0xf38a('0xe')](_0xf38a('0x4e'),_0xfce155[_0xf38a('0x37')]),'trigger:desk:display',{'recordId':_0x4b53cc['id']});break;case _0xf38a('0x5b'):logger[_0xf38a('0xc')](_0xf38a('0x4c'),_0xf38a('0x4f'));emit(util[_0xf38a('0xe')](_0xf38a('0x4e'),_0xfce155['name']),_0xf38a('0x50'),{'uri':util[_0xf38a('0xe')](_0xf38a('0x5c'),_0x17dc6c['remoteUri'],_0x4b53cc['id'])});break;default:logger['error']('[OUTBOUND]',_0xf38a('0x5d'));}}})['catch'](function(_0x3200b7){logger['error'](_0xf38a('0x5e'),JSON[_0xf38a('0x1a')](_0x3200b7));});};exports['unmanaged']=function(_0x4861ce,_0x334b46,_0x33f595,_0x145695,_0x51b121,_0x5e8163){var _0x45a330,_0xf078a5;_0x5e8163[_0xf38a('0xf')]=intUtil['stripTrailingSlash'](_0x5e8163[_0xf38a('0xf')]);_0x5e8163['serverUrl']=intUtil[_0xf38a('0x41')](_0x5e8163['serverUrl']);if(_0x51b121&&_0x51b121[_0xf38a('0x43')]){logger[_0xf38a('0xc')]('['+_0x334b46[_0xf38a('0x5f')]['toUpperCase']()+']','Recording\x20is\x20enabled!');_0x334b46['recordingURL']=util[_0xf38a('0xe')](_0xf38a('0x45'),_0x5e8163['serverUrl'],_0x334b46[_0xf38a('0x56')],md5(_0x334b46[_0xf38a('0x56')]));}else{_0x334b46[_0xf38a('0x44')]='';}headers[_0xf38a('0x46')]=getAuth(_0x5e8163);return getUser(_0x5e8163)[_0xf38a('0x14')](function(_0x5e78bc){_0x45a330=_0x5e78bc;logger[_0xf38a('0xc')](_0xf38a('0x57'),_0x45a330['id']);return getEndUser(_0x5e8163,_0x334b46['calleridname'],_0x334b46['calleridnum']);})[_0xf38a('0x14')](function(_0x1bdb59){_0xf078a5=_0x1bdb59;logger[_0xf38a('0xc')](_0xf38a('0x5a'),_0xf078a5['id']);return getTicket(_0x5e8163,_0x45a330,_0xf078a5,_0x33f595,_0x334b46);})['then'](function(_0x41c687){if(_0x41c687){logger[_0xf38a('0xc')]('Ticket\x20created!');logger[_0xf38a('0xc')](_0xf38a('0x4a'),_0x41c687['id']);}})[_0xf38a('0x51')](function(_0x4cfc32){logger['error']('['+_0x334b46[_0xf38a('0x5f')][_0xf38a('0x60')]()+']',JSON[_0xf38a('0x1a')](_0x4cfc32));});};
\ No newline at end of file
+var _0x8dce=['defaults','localhost','redis','application/json','validateEmail','Getting\x20agent\x20with\x20email','format','%s/users','then','total_entries','find','_embedded','entries','info','Agent\x20found!','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me','remoteUri','debug','[HTTP]','stringify','authType','%s:%s','username','password','token','%s/token:%s','Basic\x20%s','toString','base64','Searching\x20enduser\x20with\x20phone','%s/customers/search','Enduser\x20found!','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','%s/customers','POST','work','length','map','forEach','includes','string','type','nameField','toLowerCase','content','picklist','idField','customField','variable','variableName','custom_fields','Variable','name','priority','Creating\x20new\x20ticket...','merge','getString','Subjects','phone','xCALLY','Tags','Descriptions','/api/v2/users/%d','user','Fields','queue','stripTrailingSlash','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','serverUrl','uniqueid','Authorization','The\x20User\x20ID\x20is:','calleridnum','The\x20Enduser\x20ID\x20is:','Ticket\x20created!','The\x20Ticket\x20ID\x20is:','integrationTab','Displaying\x20ticket\x20to\x20agent...','user:%s','trigger:desk:display','newTab','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','https://xcally.desk.com/web/agent/case/%d','error','catch','recordingFormat','none','email','destcalleridname','destcalleridnum','trigger:browser:url','[OUTBOUND]','Desk\x20account\x20type\x20not\x20recognized','monitor_format','lastevent','toUpperCase','calleridname','lodash','util','ioredis','./util','../../../../config/environment','../../../../config/logger','desk'];(function(_0x6e48d8,_0x282ed8){var _0x342f70=function(_0x12c0aa){while(--_0x12c0aa){_0x6e48d8['push'](_0x6e48d8['shift']());}};_0x342f70(++_0x282ed8);}(_0x8dce,0x1a9));var _0xe8dc=function(_0x185642,_0x1be278){_0x185642=_0x185642-0x0;var _0x3050a4=_0x8dce[_0x185642];return _0x3050a4;};'use strict';var _=require(_0xe8dc('0x0'));var rp=require('request-promise');var md5=require('md5');var util=require(_0xe8dc('0x1'));var Redis=require(_0xe8dc('0x2'));var intUtil=require(_0xe8dc('0x3'));var config=require(_0xe8dc('0x4'));var logger=require(_0xe8dc('0x5'))(_0xe8dc('0x6'));config['redis']=_[_0xe8dc('0x7')](config['redis'],{'host':_0xe8dc('0x8'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xe8dc('0x9')]));function emit(_0x216f8a,_0x1230df,_0x4b00b6){io['to'](_0x216f8a)['emit'](_0x1230df,_0x4b00b6);}var headers={'Content-Type':_0xe8dc('0xa'),'Accept':_0xe8dc('0xa')};function getUser(_0x81539f,_0x3a244d){if(intUtil[_0xe8dc('0xb')](_0x3a244d)===!![]){logger['info'](_0xe8dc('0xc'),_0x3a244d);return request({'uri':util[_0xe8dc('0xd')](_0xe8dc('0xe'),_0x81539f['remoteUri'])})[_0xe8dc('0xf')](function(_0x32326f){if(_0x32326f[_0xe8dc('0x10')]){return _[_0xe8dc('0x11')](_0x32326f[_0xe8dc('0x12')][_0xe8dc('0x13')],{'email':_0x3a244d});}})[_0xe8dc('0xf')](function(_0x4b82f6){if(_0x4b82f6){logger[_0xe8dc('0x14')](_0xe8dc('0x15'));return _0x4b82f6;}else{logger[_0xe8dc('0x14')](_0xe8dc('0x16'));return request({'uri':util['format'](_0xe8dc('0x17'),_0x81539f[_0xe8dc('0x18')])});}});}else{logger[_0xe8dc('0x14')]('Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!');return request({'uri':util[_0xe8dc('0xd')]('%s/users/me',_0x81539f['remoteUri'])});}}function request(_0x1d390f){logger[_0xe8dc('0x19')](_0xe8dc('0x1a'),JSON[_0xe8dc('0x1b')](_0x1d390f));return rp(_[_0xe8dc('0x7')](_0x1d390f,{'method':'GET','headers':headers,'json':!![]}));}function getAuth(_0x571dc1){var _0x3afb8e;if(_0x571dc1[_0xe8dc('0x1c')]==='basic'){_0x3afb8e=util[_0xe8dc('0xd')](_0xe8dc('0x1d'),_0x571dc1[_0xe8dc('0x1e')],_0x571dc1[_0xe8dc('0x1f')]);}else if(_0x571dc1[_0xe8dc('0x1c')]===_0xe8dc('0x20')){_0x3afb8e=util['format'](_0xe8dc('0x21'),_0x571dc1[_0xe8dc('0x1e')],_0x571dc1['token']);}return util[_0xe8dc('0xd')](_0xe8dc('0x22'),new Buffer(_0x3afb8e)[_0xe8dc('0x23')](_0xe8dc('0x24')));}function getEndUser(_0x2d1b8e,_0x4c6ba0,_0x3c342f){logger[_0xe8dc('0x14')](_0xe8dc('0x25'),_0x3c342f);return request({'uri':util[_0xe8dc('0xd')](_0xe8dc('0x26'),_0x2d1b8e[_0xe8dc('0x18')]),'qs':{'phone':_0x3c342f}})[_0xe8dc('0xf')](function(_0x575f3b){if(_0x575f3b[_0xe8dc('0x10')]){logger[_0xe8dc('0x14')](_0xe8dc('0x27'));return _0x575f3b[_0xe8dc('0x12')][_0xe8dc('0x13')][0x0];}else{logger[_0xe8dc('0x14')](_0xe8dc('0x28'));return request({'uri':util[_0xe8dc('0xd')](_0xe8dc('0x29'),_0x2d1b8e[_0xe8dc('0x18')]),'method':_0xe8dc('0x2a'),'body':{'first_name':_0x4c6ba0,'title':_0x4c6ba0,'phone_numbers':[{'type':_0xe8dc('0x2b'),'value':_0x3c342f}]}});}});}function getTags(_0x15fc90,_0x520eba){var _0x209ec7=[];if(_0x15fc90&&_0x15fc90[_0xe8dc('0x2c')]>0x0){_0x209ec7=_[_0xe8dc('0x2d')](_0x15fc90,_0x520eba);}return _0x209ec7;}function getCustomFields(_0x255863,_0x4f1804){var _0x1faf56=[];var _0x4f62f2={'custom_fields':{}};if(_0x255863[_0xe8dc('0x2c')]>0x0){_[_0xe8dc('0x2e')](_0x255863,function(_0x2b3445){if(_[_0xe8dc('0x2f')]([_0xe8dc('0x30'),'picklist'],_0x2b3445[_0xe8dc('0x31')])&&_0x2b3445[_0xe8dc('0x32')]&&!_0x2b3445['customField']){_0x4f62f2[_0x2b3445[_0xe8dc('0x32')][_0xe8dc('0x33')]()]=_0x2b3445[_0xe8dc('0x34')][_0xe8dc('0x23')]();}else if(_[_0xe8dc('0x2f')]([_0xe8dc('0x30'),_0xe8dc('0x35')],_0x2b3445[_0xe8dc('0x31')])&&_0x2b3445[_0xe8dc('0x36')]&&_0x2b3445[_0xe8dc('0x37')]){_0x4f62f2['custom_fields'][_0x2b3445[_0xe8dc('0x36')]]=_0x2b3445[_0xe8dc('0x34')]['toString']();}else if(_0x2b3445[_0xe8dc('0x31')]===_0xe8dc('0x38')&&_0x2b3445[_0xe8dc('0x39')]&&_0x2b3445['idField']&&_0x2b3445[_0xe8dc('0x37')]){_0x4f1804[_0x2b3445['variableName']]&&(_0x4f62f2[_0xe8dc('0x3a')][_0x2b3445[_0xe8dc('0x36')]]=_0x4f1804[_0x2b3445[_0xe8dc('0x39')]][_0xe8dc('0x23')]());}else if(_0x2b3445[_0xe8dc('0x31')]==='customVariable'&&_0x2b3445['Variable']&&_0x2b3445[_0xe8dc('0x3b')][_0xe8dc('0x3c')]&&_0x2b3445[_0xe8dc('0x36')]&&_0x2b3445['customField']){_0x4f1804[_0x2b3445[_0xe8dc('0x3b')][_0xe8dc('0x3c')][_0xe8dc('0x33')]()]&&(_0x4f62f2['custom_fields'][_0x2b3445[_0xe8dc('0x36')]]=_0x4f1804[_0x2b3445[_0xe8dc('0x3b')][_0xe8dc('0x3c')][_0xe8dc('0x33')]()][_0xe8dc('0x23')]());}});}if(_0x4f62f2['priority']){_0x4f62f2['priority']=Number(_0x4f62f2[_0xe8dc('0x3d')]);}return _0x4f62f2;}function getTicket(_0x17381e,_0x42ea59,_0x16d4f1,_0x22251e,_0x378852){logger[_0xe8dc('0x14')](_0xe8dc('0x3e'));var _0x4c9d6b=_[_0xe8dc('0x3f')]({'subject':intUtil[_0xe8dc('0x40')](_0x22251e[_0xe8dc('0x41')],_0x378852,'\x20'),'type':_0xe8dc('0x42'),'status':'new','labels':[_0xe8dc('0x43'),'Motion','CTI']['concat'](getTags(_0x22251e[_0xe8dc('0x44')],_0xe8dc('0x3c'))),'description':intUtil['getString'](_0x22251e[_0xe8dc('0x45')],_0x378852,'\x0a'),'_links':{'assigned_user':{'href':util[_0xe8dc('0xd')](_0xe8dc('0x46'),_0x42ea59['id']),'class':_0xe8dc('0x47')}},'message':{'direction':'in','body':intUtil[_0xe8dc('0x40')](_0x22251e[_0xe8dc('0x45')],_0x378852,'\x0a')}},getCustomFields(_0x22251e[_0xe8dc('0x48')],_0x378852));return request({'uri':util['format']('%s/customers/%d/cases',_0x17381e[_0xe8dc('0x18')],_0x16d4f1['id']),'method':_0xe8dc('0x2a'),'body':_0x4c9d6b});}exports[_0xe8dc('0x49')]=function(_0x5914e2,_0x11c6be,_0x25be2f,_0x544293,_0x2f8c04,_0x15ba80){var _0x434460,_0x48d48b;_0x15ba80['remoteUri']=intUtil['stripTrailingSlash'](_0x15ba80['remoteUri']);_0x15ba80['serverUrl']=intUtil[_0xe8dc('0x4a')](_0x15ba80['serverUrl']);if(_0x2f8c04&&_0x2f8c04['monitor_format']){logger[_0xe8dc('0x14')](_0xe8dc('0x4b'),_0xe8dc('0x4c'));_0x11c6be[_0xe8dc('0x4d')]=util[_0xe8dc('0xd')](_0xe8dc('0x4e'),_0x15ba80[_0xe8dc('0x4f')],_0x11c6be[_0xe8dc('0x50')],md5(_0x11c6be[_0xe8dc('0x50')]));}else{_0x11c6be[_0xe8dc('0x4d')]='';}headers[_0xe8dc('0x51')]=getAuth(_0x15ba80);return getUser(_0x15ba80,_0x544293['email'])[_0xe8dc('0xf')](function(_0x46dcb5){_0x434460=_0x46dcb5;logger['info'](_0xe8dc('0x52'),_0x434460['id']);return getEndUser(_0x15ba80,_0x11c6be['calleridname'],_0x11c6be[_0xe8dc('0x53')]);})[_0xe8dc('0xf')](function(_0xe35a2e){_0x48d48b=_0xe35a2e;logger[_0xe8dc('0x14')](_0xe8dc('0x54'),_0x48d48b['id']);return getTicket(_0x15ba80,_0x434460,_0x48d48b,_0x25be2f,_0x11c6be);})[_0xe8dc('0xf')](function(_0x55fdce){if(_0x55fdce){logger[_0xe8dc('0x14')](_0xe8dc('0x55'));logger['info'](_0xe8dc('0x56'),_0x55fdce['id']);switch(_0x15ba80[_0xe8dc('0x31')]){case _0xe8dc('0x57'):logger[_0xe8dc('0x14')](_0xe8dc('0x4b'),_0xe8dc('0x58'));emit(util['format'](_0xe8dc('0x59'),_0x544293[_0xe8dc('0x3c')]),_0xe8dc('0x5a'),{'recordId':_0x55fdce['id']});break;case _0xe8dc('0x5b'):logger[_0xe8dc('0x14')](_0xe8dc('0x4b'),_0xe8dc('0x5c'));emit(util['format'](_0xe8dc('0x59'),_0x544293[_0xe8dc('0x3c')]),'trigger:browser:url',{'uri':util[_0xe8dc('0xd')](_0xe8dc('0x5d'),_0x55fdce['id'])});break;default:logger[_0xe8dc('0x5e')](_0xe8dc('0x4b'),'Desk\x20account\x20type\x20not\x20recognized');}}})[_0xe8dc('0x5f')](function(_0x2bca35){console[_0xe8dc('0x5e')](_0x2bca35);logger[_0xe8dc('0x5e')](_0xe8dc('0x4b'),JSON[_0xe8dc('0x1b')](_0x2bca35));});};exports['outbound']=function(_0x53eb3c,_0x38a7db,_0x177449,_0x975659,_0x236a07,_0x407bd8,_0x26f1a5){var _0x55e6ae,_0x385b8c;_0x407bd8[_0xe8dc('0x18')]=intUtil[_0xe8dc('0x4a')](_0x407bd8['remoteUri']);_0x407bd8[_0xe8dc('0x4f')]=intUtil[_0xe8dc('0x4a')](_0x407bd8['serverUrl']);if(_0x26f1a5&&_0x26f1a5[_0xe8dc('0x60')]&&_0x26f1a5[_0xe8dc('0x60')]!==_0xe8dc('0x61')){logger[_0xe8dc('0x14')]('[OUTBOUND]',_0xe8dc('0x4c'));_0x38a7db[_0xe8dc('0x4d')]=util[_0xe8dc('0xd')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x407bd8['serverUrl'],_0x38a7db['uniqueid'],md5(_0x38a7db[_0xe8dc('0x50')]));}headers[_0xe8dc('0x51')]=getAuth(_0x407bd8);return getUser(_0x407bd8,_0x975659[_0xe8dc('0x62')])[_0xe8dc('0xf')](function(_0x3b56f8){_0x55e6ae=_0x3b56f8;logger[_0xe8dc('0x14')](_0xe8dc('0x52'),_0x55e6ae['id']);return getEndUser(_0x407bd8,_0x38a7db[_0xe8dc('0x63')],_0x38a7db[_0xe8dc('0x64')]);})[_0xe8dc('0xf')](function(_0x34fdd2){_0x385b8c=_0x34fdd2;logger[_0xe8dc('0x14')](_0xe8dc('0x54'),_0x385b8c['id']);return getTicket(_0x407bd8,_0x55e6ae,_0x385b8c,_0x177449,_0x38a7db);})[_0xe8dc('0xf')](function(_0x5be99d){if(_0x5be99d){logger[_0xe8dc('0x14')](_0xe8dc('0x55'));logger[_0xe8dc('0x14')](_0xe8dc('0x56'),_0x5be99d['id']);switch(_0x407bd8[_0xe8dc('0x31')]){case'integrationTab':logger[_0xe8dc('0x14')](_0xe8dc('0x4b'),_0xe8dc('0x58'));emit(util['format']('user:%s',_0x975659['name']),_0xe8dc('0x5a'),{'recordId':_0x5be99d['id']});break;case _0xe8dc('0x5b'):logger['info'](_0xe8dc('0x4b'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0xe8dc('0xd')](_0xe8dc('0x59'),_0x975659[_0xe8dc('0x3c')]),_0xe8dc('0x65'),{'uri':util[_0xe8dc('0xd')]('%s/agent/tickets/%s',_0x407bd8[_0xe8dc('0x18')],_0x5be99d['id'])});break;default:logger[_0xe8dc('0x5e')](_0xe8dc('0x66'),_0xe8dc('0x67'));}}})[_0xe8dc('0x5f')](function(_0x26f81c){logger[_0xe8dc('0x5e')](_0xe8dc('0x66'),JSON[_0xe8dc('0x1b')](_0x26f81c));});};exports['unmanaged']=function(_0x518f25,_0x4b671f,_0x53b2e3,_0x1df75d,_0x2393f0,_0x42d660){var _0x165ede,_0x4e93d9;_0x42d660[_0xe8dc('0x18')]=intUtil[_0xe8dc('0x4a')](_0x42d660[_0xe8dc('0x18')]);_0x42d660[_0xe8dc('0x4f')]=intUtil[_0xe8dc('0x4a')](_0x42d660[_0xe8dc('0x4f')]);if(_0x2393f0&&_0x2393f0[_0xe8dc('0x68')]){logger['info']('['+_0x4b671f[_0xe8dc('0x69')][_0xe8dc('0x6a')]()+']','Recording\x20is\x20enabled!');_0x4b671f[_0xe8dc('0x4d')]=util[_0xe8dc('0xd')](_0xe8dc('0x4e'),_0x42d660['serverUrl'],_0x4b671f[_0xe8dc('0x50')],md5(_0x4b671f[_0xe8dc('0x50')]));}else{_0x4b671f[_0xe8dc('0x4d')]='';}headers['Authorization']=getAuth(_0x42d660);return getUser(_0x42d660)[_0xe8dc('0xf')](function(_0x3205f3){_0x165ede=_0x3205f3;logger['info'](_0xe8dc('0x52'),_0x165ede['id']);return getEndUser(_0x42d660,_0x4b671f[_0xe8dc('0x6b')],_0x4b671f['calleridnum']);})[_0xe8dc('0xf')](function(_0x45d201){_0x4e93d9=_0x45d201;logger[_0xe8dc('0x14')](_0xe8dc('0x54'),_0x4e93d9['id']);return getTicket(_0x42d660,_0x165ede,_0x4e93d9,_0x53b2e3,_0x4b671f);})[_0xe8dc('0xf')](function(_0x4cd0c4){if(_0x4cd0c4){logger['info']('Ticket\x20created!');logger['info']('The\x20Ticket\x20ID\x20is:',_0x4cd0c4['id']);}})['catch'](function(_0x104863){logger['error']('['+_0x4b671f[_0xe8dc('0x69')][_0xe8dc('0x6a')]()+']',JSON[_0xe8dc('0x1b')](_0x104863));});};
\ No newline at end of file