Built motion from commit 9e1399f3.|2.5.37
[motion2.git] / server / services / ami / trigger / integration / desk.js
index 922b494..9c1581c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa0ba=['emit','application/json','validateEmail','info','Getting\x20agent\x20with\x20email','format','%s/users','remoteUri','then','total_entries','find','_embedded','entries','Agent\x20found!','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me','debug','[HTTP]','defaults','GET','authType','%s:%s','username','token','%s/token:%s','Basic\x20%s','toString','base64','%s/customers/search','Enduser\x20found!','POST','work','length','map','forEach','includes','picklist','type','nameField','toLowerCase','content','customField','custom_fields','variable','variableName','idField','customVariable','Variable','name','priority','Creating\x20new\x20ticket...','merge','getString','Subjects','xCALLY','Motion','CTI','concat','Tags','Descriptions','/api/v2/users/%d','user','Fields','%s/customers/%d/cases','queue','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','recordingURL','uniqueid','email','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','integrationTab','Displaying\x20ticket\x20to\x20agent...','user:%s','trigger:desk:display','newTab','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','trigger:browser:url','https://xcally.desk.com/web/agent/case/%d','error','Desk\x20account\x20type\x20not\x20recognized','catch','stringify','recordingFormat','none','[OUTBOUND]','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','Ticket\x20created!','%s/agent/tickets/%s','unmanaged','lastevent','Authorization','lodash','request-promise','md5','util','ioredis','./util','../../../../config/environment','desk','redis','localhost'];(function(_0xa00268,_0x551d5a){var _0x38e5eb=function(_0x1962de){while(--_0x1962de){_0xa00268['push'](_0xa00268['shift']());}};_0x38e5eb(++_0x551d5a);}(_0xa0ba,0x140));var _0xaa0b=function(_0x2d994d,_0x168a27){_0x2d994d=_0x2d994d-0x0;var _0xd54be4=_0xa0ba[_0x2d994d];return _0xd54be4;};'use strict';var _=require(_0xaa0b('0x0'));var rp=require(_0xaa0b('0x1'));var md5=require(_0xaa0b('0x2'));var util=require(_0xaa0b('0x3'));var Redis=require(_0xaa0b('0x4'));var intUtil=require(_0xaa0b('0x5'));var config=require(_0xaa0b('0x6'));var logger=require('../../../../config/logger')(_0xaa0b('0x7'));config[_0xaa0b('0x8')]=_['defaults'](config['redis'],{'host':_0xaa0b('0x9'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function emit(_0x195226,_0x3ce11f,_0x46f7bb){io['to'](_0x195226)[_0xaa0b('0xa')](_0x3ce11f,_0x46f7bb);}var headers={'Content-Type':_0xaa0b('0xb'),'Accept':_0xaa0b('0xb')};function getUser(_0x2eecea,_0x4581ed){if(intUtil[_0xaa0b('0xc')](_0x4581ed)===!![]){logger[_0xaa0b('0xd')](_0xaa0b('0xe'),_0x4581ed);return request({'uri':util[_0xaa0b('0xf')](_0xaa0b('0x10'),_0x2eecea[_0xaa0b('0x11')])})[_0xaa0b('0x12')](function(_0xa9fb57){if(_0xa9fb57[_0xaa0b('0x13')]){return _[_0xaa0b('0x14')](_0xa9fb57[_0xaa0b('0x15')][_0xaa0b('0x16')],{'email':_0x4581ed});}})[_0xaa0b('0x12')](function(_0x48d0c7){if(_0x48d0c7){logger[_0xaa0b('0xd')](_0xaa0b('0x17'));return _0x48d0c7;}else{logger[_0xaa0b('0xd')](_0xaa0b('0x18'));return request({'uri':util[_0xaa0b('0xf')]('%s/users/me',_0x2eecea[_0xaa0b('0x11')])});}});}else{logger[_0xaa0b('0xd')]('Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!');return request({'uri':util[_0xaa0b('0xf')](_0xaa0b('0x19'),_0x2eecea['remoteUri'])});}}function request(_0x176047){logger[_0xaa0b('0x1a')](_0xaa0b('0x1b'),JSON['stringify'](_0x176047));return rp(_[_0xaa0b('0x1c')](_0x176047,{'method':_0xaa0b('0x1d'),'headers':headers,'json':!![]}));}function getAuth(_0x2458dc){var _0x44a1bf;if(_0x2458dc[_0xaa0b('0x1e')]==='basic'){_0x44a1bf=util[_0xaa0b('0xf')](_0xaa0b('0x1f'),_0x2458dc[_0xaa0b('0x20')],_0x2458dc['password']);}else if(_0x2458dc[_0xaa0b('0x1e')]===_0xaa0b('0x21')){_0x44a1bf=util['format'](_0xaa0b('0x22'),_0x2458dc[_0xaa0b('0x20')],_0x2458dc[_0xaa0b('0x21')]);}return util[_0xaa0b('0xf')](_0xaa0b('0x23'),new Buffer(_0x44a1bf)[_0xaa0b('0x24')](_0xaa0b('0x25')));}function getEndUser(_0x14fc28,_0x59d68f,_0x119c17){logger[_0xaa0b('0xd')]('Searching\x20enduser\x20with\x20phone',_0x119c17);return request({'uri':util[_0xaa0b('0xf')](_0xaa0b('0x26'),_0x14fc28[_0xaa0b('0x11')]),'qs':{'phone':_0x119c17}})[_0xaa0b('0x12')](function(_0x23a402){if(_0x23a402['total_entries']){logger[_0xaa0b('0xd')](_0xaa0b('0x27'));return _0x23a402[_0xaa0b('0x15')][_0xaa0b('0x16')][0x0];}else{logger[_0xaa0b('0xd')]('Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!');return request({'uri':util[_0xaa0b('0xf')]('%s/customers',_0x14fc28[_0xaa0b('0x11')]),'method':_0xaa0b('0x28'),'body':{'first_name':_0x59d68f,'title':_0x59d68f,'phone_numbers':[{'type':_0xaa0b('0x29'),'value':_0x119c17}]}});}});}function getTags(_0x186029,_0x17c971){var _0x3f654c=[];if(_0x186029&&_0x186029[_0xaa0b('0x2a')]>0x0){_0x3f654c=_[_0xaa0b('0x2b')](_0x186029,_0x17c971);}return _0x3f654c;}function getCustomFields(_0x1bcd59,_0x241d17){var _0x2d9991=[];var _0x6fc96b={'custom_fields':{}};if(_0x1bcd59[_0xaa0b('0x2a')]>0x0){_[_0xaa0b('0x2c')](_0x1bcd59,function(_0x4f4dae){if(_[_0xaa0b('0x2d')](['string',_0xaa0b('0x2e')],_0x4f4dae[_0xaa0b('0x2f')])&&_0x4f4dae['nameField']&&!_0x4f4dae['customField']){_0x6fc96b[_0x4f4dae[_0xaa0b('0x30')][_0xaa0b('0x31')]()]=_0x4f4dae[_0xaa0b('0x32')][_0xaa0b('0x24')]();}else if(_[_0xaa0b('0x2d')](['string',_0xaa0b('0x2e')],_0x4f4dae['type'])&&_0x4f4dae['idField']&&_0x4f4dae[_0xaa0b('0x33')]){_0x6fc96b[_0xaa0b('0x34')][_0x4f4dae['idField']]=_0x4f4dae[_0xaa0b('0x32')]['toString']();}else if(_0x4f4dae[_0xaa0b('0x2f')]===_0xaa0b('0x35')&&_0x4f4dae[_0xaa0b('0x36')]&&_0x4f4dae[_0xaa0b('0x37')]&&_0x4f4dae[_0xaa0b('0x33')]){_0x241d17[_0x4f4dae[_0xaa0b('0x36')]]&&(_0x6fc96b[_0xaa0b('0x34')][_0x4f4dae[_0xaa0b('0x37')]]=_0x241d17[_0x4f4dae['variableName']][_0xaa0b('0x24')]());}else if(_0x4f4dae['type']===_0xaa0b('0x38')&&_0x4f4dae[_0xaa0b('0x39')]&&_0x4f4dae[_0xaa0b('0x39')]['name']&&_0x4f4dae[_0xaa0b('0x37')]&&_0x4f4dae['customField']){_0x241d17[_0x4f4dae[_0xaa0b('0x39')][_0xaa0b('0x3a')][_0xaa0b('0x31')]()]&&(_0x6fc96b['custom_fields'][_0x4f4dae[_0xaa0b('0x37')]]=_0x241d17[_0x4f4dae['Variable']['name']['toLowerCase']()][_0xaa0b('0x24')]());}});}if(_0x6fc96b[_0xaa0b('0x3b')]){_0x6fc96b['priority']=Number(_0x6fc96b[_0xaa0b('0x3b')]);}return _0x6fc96b;}function getTicket(_0x546f9e,_0x20b09f,_0x46c9a9,_0x273857,_0x2f1c6e){logger[_0xaa0b('0xd')](_0xaa0b('0x3c'));var _0x28a04d=_[_0xaa0b('0x3d')]({'subject':intUtil[_0xaa0b('0x3e')](_0x273857[_0xaa0b('0x3f')],_0x2f1c6e,'\x20'),'type':'phone','status':'new','labels':[_0xaa0b('0x40'),_0xaa0b('0x41'),_0xaa0b('0x42')][_0xaa0b('0x43')](getTags(_0x273857[_0xaa0b('0x44')],_0xaa0b('0x3a'))),'description':intUtil[_0xaa0b('0x3e')](_0x273857[_0xaa0b('0x45')],_0x2f1c6e,'\x0a'),'_links':{'assigned_user':{'href':util[_0xaa0b('0xf')](_0xaa0b('0x46'),_0x20b09f['id']),'class':_0xaa0b('0x47')}},'message':{'direction':'in','body':intUtil[_0xaa0b('0x3e')](_0x273857[_0xaa0b('0x45')],_0x2f1c6e,'\x0a')}},getCustomFields(_0x273857[_0xaa0b('0x48')],_0x2f1c6e));return request({'uri':util[_0xaa0b('0xf')](_0xaa0b('0x49'),_0x546f9e[_0xaa0b('0x11')],_0x46c9a9['id']),'method':_0xaa0b('0x28'),'body':_0x28a04d});}exports[_0xaa0b('0x4a')]=function(_0x24de48,_0xc7481c,_0x58497a,_0x5460d4,_0x268b25,_0x54d1a4){var _0x2f90b6,_0x2a126d;_0x54d1a4[_0xaa0b('0x11')]=intUtil[_0xaa0b('0x4b')](_0x54d1a4[_0xaa0b('0x11')]);_0x54d1a4['serverUrl']=intUtil['stripTrailingSlash'](_0x54d1a4[_0xaa0b('0x4c')]);if(_0x268b25&&_0x268b25[_0xaa0b('0x4d')]){logger['info'](_0xaa0b('0x4e'),'Recording\x20is\x20enabled!');_0xc7481c[_0xaa0b('0x4f')]=util[_0xaa0b('0xf')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x54d1a4[_0xaa0b('0x4c')],_0xc7481c['uniqueid'],md5(_0xc7481c[_0xaa0b('0x50')]));}else{_0xc7481c['recordingURL']='';}headers['Authorization']=getAuth(_0x54d1a4);return getUser(_0x54d1a4,_0x5460d4[_0xaa0b('0x51')])[_0xaa0b('0x12')](function(_0x2e195d){_0x2f90b6=_0x2e195d;logger[_0xaa0b('0xd')]('The\x20User\x20ID\x20is:',_0x2f90b6['id']);return getEndUser(_0x54d1a4,_0xc7481c[_0xaa0b('0x52')],_0xc7481c[_0xaa0b('0x53')]);})[_0xaa0b('0x12')](function(_0x2c9a71){_0x2a126d=_0x2c9a71;logger[_0xaa0b('0xd')](_0xaa0b('0x54'),_0x2a126d['id']);return getTicket(_0x54d1a4,_0x2f90b6,_0x2a126d,_0x58497a,_0xc7481c);})[_0xaa0b('0x12')](function(_0x2b8f42){if(_0x2b8f42){logger[_0xaa0b('0xd')]('Ticket\x20created!');logger['info'](_0xaa0b('0x55'),_0x2b8f42['id']);switch(_0x54d1a4[_0xaa0b('0x2f')]){case _0xaa0b('0x56'):logger['info'](_0xaa0b('0x4e'),_0xaa0b('0x57'));emit(util['format'](_0xaa0b('0x58'),_0x5460d4['name']),_0xaa0b('0x59'),{'recordId':_0x2b8f42['id']});break;case _0xaa0b('0x5a'):logger['info'](_0xaa0b('0x4e'),_0xaa0b('0x5b'));emit(util[_0xaa0b('0xf')](_0xaa0b('0x58'),_0x5460d4[_0xaa0b('0x3a')]),_0xaa0b('0x5c'),{'uri':util[_0xaa0b('0xf')](_0xaa0b('0x5d'),_0x2b8f42['id'])});break;default:logger[_0xaa0b('0x5e')]('[QUEUE]',_0xaa0b('0x5f'));}}})[_0xaa0b('0x60')](function(_0x370d14){console[_0xaa0b('0x5e')](_0x370d14);logger[_0xaa0b('0x5e')]('[QUEUE]',JSON[_0xaa0b('0x61')](_0x370d14));});};exports['outbound']=function(_0x589ab9,_0x59d351,_0x5bd3ff,_0x2ca471,_0x3df98f,_0x7ad990,_0x1248ae){var _0x2665f4,_0x5f50da;_0x7ad990[_0xaa0b('0x11')]=intUtil[_0xaa0b('0x4b')](_0x7ad990['remoteUri']);_0x7ad990['serverUrl']=intUtil[_0xaa0b('0x4b')](_0x7ad990[_0xaa0b('0x4c')]);if(_0x1248ae&&_0x1248ae['recordingFormat']&&_0x1248ae[_0xaa0b('0x62')]!==_0xaa0b('0x63')){logger[_0xaa0b('0xd')](_0xaa0b('0x64'),'Recording\x20is\x20enabled!');_0x59d351[_0xaa0b('0x4f')]=util['format'](_0xaa0b('0x65'),_0x7ad990['serverUrl'],_0x59d351[_0xaa0b('0x50')],md5(_0x59d351[_0xaa0b('0x50')]));}headers['Authorization']=getAuth(_0x7ad990);return getUser(_0x7ad990,_0x2ca471['email'])[_0xaa0b('0x12')](function(_0x160a9c){_0x2665f4=_0x160a9c;logger[_0xaa0b('0xd')](_0xaa0b('0x66'),_0x2665f4['id']);return getEndUser(_0x7ad990,_0x59d351[_0xaa0b('0x67')],_0x59d351[_0xaa0b('0x68')]);})[_0xaa0b('0x12')](function(_0x3f4ff3){_0x5f50da=_0x3f4ff3;logger[_0xaa0b('0xd')](_0xaa0b('0x54'),_0x5f50da['id']);return getTicket(_0x7ad990,_0x2665f4,_0x5f50da,_0x5bd3ff,_0x59d351);})[_0xaa0b('0x12')](function(_0x8eebaa){if(_0x8eebaa){logger[_0xaa0b('0xd')](_0xaa0b('0x69'));logger[_0xaa0b('0xd')](_0xaa0b('0x55'),_0x8eebaa['id']);switch(_0x7ad990['type']){case _0xaa0b('0x56'):logger[_0xaa0b('0xd')]('[QUEUE]',_0xaa0b('0x57'));emit(util[_0xaa0b('0xf')]('user:%s',_0x2ca471[_0xaa0b('0x3a')]),_0xaa0b('0x59'),{'recordId':_0x8eebaa['id']});break;case _0xaa0b('0x5a'):logger[_0xaa0b('0xd')](_0xaa0b('0x4e'),_0xaa0b('0x5b'));emit(util[_0xaa0b('0xf')](_0xaa0b('0x58'),_0x2ca471['name']),_0xaa0b('0x5c'),{'uri':util[_0xaa0b('0xf')](_0xaa0b('0x6a'),_0x7ad990['remoteUri'],_0x8eebaa['id'])});break;default:logger[_0xaa0b('0x5e')](_0xaa0b('0x64'),_0xaa0b('0x5f'));}}})[_0xaa0b('0x60')](function(_0x1fe2fa){logger['error'](_0xaa0b('0x64'),JSON[_0xaa0b('0x61')](_0x1fe2fa));});};exports[_0xaa0b('0x6b')]=function(_0x5d8b68,_0x18776e,_0x1711b1,_0x28d95e,_0x1ed055,_0x397c94){var _0x57d4fb,_0x98bec5;_0x397c94[_0xaa0b('0x11')]=intUtil[_0xaa0b('0x4b')](_0x397c94[_0xaa0b('0x11')]);_0x397c94[_0xaa0b('0x4c')]=intUtil[_0xaa0b('0x4b')](_0x397c94['serverUrl']);if(_0x1ed055&&_0x1ed055['monitor_format']){logger[_0xaa0b('0xd')]('['+_0x18776e[_0xaa0b('0x6c')]['toUpperCase']()+']','Recording\x20is\x20enabled!');_0x18776e[_0xaa0b('0x4f')]=util[_0xaa0b('0xf')](_0xaa0b('0x65'),_0x397c94[_0xaa0b('0x4c')],_0x18776e[_0xaa0b('0x50')],md5(_0x18776e[_0xaa0b('0x50')]));}else{_0x18776e[_0xaa0b('0x4f')]='';}headers[_0xaa0b('0x6d')]=getAuth(_0x397c94);return getUser(_0x397c94)[_0xaa0b('0x12')](function(_0x3471dd){_0x57d4fb=_0x3471dd;logger[_0xaa0b('0xd')](_0xaa0b('0x66'),_0x57d4fb['id']);return getEndUser(_0x397c94,_0x18776e['calleridname'],_0x18776e[_0xaa0b('0x53')]);})[_0xaa0b('0x12')](function(_0x30ca15){_0x98bec5=_0x30ca15;logger[_0xaa0b('0xd')](_0xaa0b('0x54'),_0x98bec5['id']);return getTicket(_0x397c94,_0x57d4fb,_0x98bec5,_0x1711b1,_0x18776e);})[_0xaa0b('0x12')](function(_0x4658f2){if(_0x4658f2){logger[_0xaa0b('0xd')](_0xaa0b('0x69'));logger[_0xaa0b('0xd')]('The\x20Ticket\x20ID\x20is:',_0x4658f2['id']);}})['catch'](function(_0x445ac0){logger[_0xaa0b('0x5e')]('['+_0x18776e[_0xaa0b('0x6c')]['toUpperCase']()+']',JSON[_0xaa0b('0x61')](_0x445ac0));});};
\ No newline at end of file
+var _0x7217=['format','%s/users','remoteUri','then','total_entries','find','entries','info','Agent\x20found!','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me','debug','stringify','GET','authType','basic','%s:%s','username','password','token','Basic\x20%s','base64','Searching\x20enduser\x20with\x20phone','%s/customers/search','Enduser\x20found!','_embedded','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','length','map','forEach','string','picklist','nameField','customField','content','toString','includes','idField','custom_fields','variable','variableName','type','customVariable','Variable','name','toLowerCase','priority','Creating\x20new\x20ticket...','merge','getString','new','xCALLY','Motion','CTI','Tags','Descriptions','user','%s/customers/%d/cases','queue','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','Authorization','email','The\x20User\x20ID\x20is:','calleridnum','The\x20Enduser\x20ID\x20is:','Ticket\x20created!','integrationTab','Displaying\x20ticket\x20to\x20agent...','user:%s','trigger:desk:display','newTab','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','trigger:browser:url','https://xcally.desk.com/web/agent/case/%d','error','catch','outbound','recordingFormat','none','[OUTBOUND]','uniqueid','The\x20Ticket\x20ID\x20is:','%s/agent/tickets/%s','unmanaged','lastevent','toUpperCase','calleridname','lodash','md5','util','ioredis','./util','../../../../config/environment','redis','defaults','localhost','socket.io-emitter','emit','application/json','validateEmail','Getting\x20agent\x20with\x20email'];(function(_0x4b7373,_0x5de68c){var _0x467fcc=function(_0x11faa5){while(--_0x11faa5){_0x4b7373['push'](_0x4b7373['shift']());}};_0x467fcc(++_0x5de68c);}(_0x7217,0x19e));var _0x7721=function(_0x2f3848,_0x48564d){_0x2f3848=_0x2f3848-0x0;var _0x102668=_0x7217[_0x2f3848];return _0x102668;};'use strict';var _=require(_0x7721('0x0'));var rp=require('request-promise');var md5=require(_0x7721('0x1'));var util=require(_0x7721('0x2'));var Redis=require(_0x7721('0x3'));var intUtil=require(_0x7721('0x4'));var config=require(_0x7721('0x5'));var logger=require('../../../../config/logger')('desk');config[_0x7721('0x6')]=_[_0x7721('0x7')](config[_0x7721('0x6')],{'host':_0x7721('0x8'),'port':0x18eb});var io=require(_0x7721('0x9'))(new Redis(config[_0x7721('0x6')]));function emit(_0x18ab6b,_0x21f680,_0x225610){io['to'](_0x18ab6b)[_0x7721('0xa')](_0x21f680,_0x225610);}var headers={'Content-Type':_0x7721('0xb'),'Accept':_0x7721('0xb')};function getUser(_0xfa8835,_0x138740){if(intUtil[_0x7721('0xc')](_0x138740)===!![]){logger['info'](_0x7721('0xd'),_0x138740);return request({'uri':util[_0x7721('0xe')](_0x7721('0xf'),_0xfa8835[_0x7721('0x10')])})[_0x7721('0x11')](function(_0x409b37){if(_0x409b37[_0x7721('0x12')]){return _[_0x7721('0x13')](_0x409b37['_embedded'][_0x7721('0x14')],{'email':_0x138740});}})[_0x7721('0x11')](function(_0x57ff6d){if(_0x57ff6d){logger[_0x7721('0x15')](_0x7721('0x16'));return _0x57ff6d;}else{logger[_0x7721('0x15')](_0x7721('0x17'));return request({'uri':util['format'](_0x7721('0x18'),_0xfa8835[_0x7721('0x10')])});}});}else{logger['info']('Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!');return request({'uri':util['format'](_0x7721('0x18'),_0xfa8835[_0x7721('0x10')])});}}function request(_0x3cc909){logger[_0x7721('0x19')]('[HTTP]',JSON[_0x7721('0x1a')](_0x3cc909));return rp(_['defaults'](_0x3cc909,{'method':_0x7721('0x1b'),'headers':headers,'json':!![]}));}function getAuth(_0x5cb0e6){var _0xfec626;if(_0x5cb0e6[_0x7721('0x1c')]===_0x7721('0x1d')){_0xfec626=util[_0x7721('0xe')](_0x7721('0x1e'),_0x5cb0e6[_0x7721('0x1f')],_0x5cb0e6[_0x7721('0x20')]);}else if(_0x5cb0e6[_0x7721('0x1c')]===_0x7721('0x21')){_0xfec626=util[_0x7721('0xe')]('%s/token:%s',_0x5cb0e6[_0x7721('0x1f')],_0x5cb0e6[_0x7721('0x21')]);}return util[_0x7721('0xe')](_0x7721('0x22'),new Buffer(_0xfec626)['toString'](_0x7721('0x23')));}function getEndUser(_0x512f31,_0xb9e9dd,_0x288e3a){logger[_0x7721('0x15')](_0x7721('0x24'),_0x288e3a);return request({'uri':util[_0x7721('0xe')](_0x7721('0x25'),_0x512f31[_0x7721('0x10')]),'qs':{'phone':_0x288e3a}})['then'](function(_0x216f20){if(_0x216f20[_0x7721('0x12')]){logger[_0x7721('0x15')](_0x7721('0x26'));return _0x216f20[_0x7721('0x27')][_0x7721('0x14')][0x0];}else{logger[_0x7721('0x15')](_0x7721('0x28'));return request({'uri':util[_0x7721('0xe')]('%s/customers',_0x512f31[_0x7721('0x10')]),'method':'POST','body':{'first_name':_0xb9e9dd,'title':_0xb9e9dd,'phone_numbers':[{'type':'work','value':_0x288e3a}]}});}});}function getTags(_0x315202,_0x343c19){var _0x53c904=[];if(_0x315202&&_0x315202[_0x7721('0x29')]>0x0){_0x53c904=_[_0x7721('0x2a')](_0x315202,_0x343c19);}return _0x53c904;}function getCustomFields(_0x37b9f0,_0xd7d703){var _0x1da2d8=[];var _0x5c54f0={'custom_fields':{}};if(_0x37b9f0[_0x7721('0x29')]>0x0){_[_0x7721('0x2b')](_0x37b9f0,function(_0x497f9f){if(_['includes']([_0x7721('0x2c'),_0x7721('0x2d')],_0x497f9f['type'])&&_0x497f9f[_0x7721('0x2e')]&&!_0x497f9f[_0x7721('0x2f')]){_0x5c54f0[_0x497f9f[_0x7721('0x2e')]['toLowerCase']()]=_0x497f9f[_0x7721('0x30')][_0x7721('0x31')]();}else if(_[_0x7721('0x32')]([_0x7721('0x2c'),_0x7721('0x2d')],_0x497f9f['type'])&&_0x497f9f[_0x7721('0x33')]&&_0x497f9f[_0x7721('0x2f')]){_0x5c54f0[_0x7721('0x34')][_0x497f9f['idField']]=_0x497f9f[_0x7721('0x30')][_0x7721('0x31')]();}else if(_0x497f9f['type']===_0x7721('0x35')&&_0x497f9f['variableName']&&_0x497f9f[_0x7721('0x33')]&&_0x497f9f[_0x7721('0x2f')]){_0xd7d703[_0x497f9f[_0x7721('0x36')]]&&(_0x5c54f0[_0x7721('0x34')][_0x497f9f[_0x7721('0x33')]]=_0xd7d703[_0x497f9f[_0x7721('0x36')]][_0x7721('0x31')]());}else if(_0x497f9f[_0x7721('0x37')]===_0x7721('0x38')&&_0x497f9f[_0x7721('0x39')]&&_0x497f9f[_0x7721('0x39')]['name']&&_0x497f9f[_0x7721('0x33')]&&_0x497f9f['customField']){_0xd7d703[_0x497f9f[_0x7721('0x39')][_0x7721('0x3a')][_0x7721('0x3b')]()]&&(_0x5c54f0[_0x7721('0x34')][_0x497f9f[_0x7721('0x33')]]=_0xd7d703[_0x497f9f[_0x7721('0x39')]['name']['toLowerCase']()]['toString']());}});}if(_0x5c54f0['priority']){_0x5c54f0[_0x7721('0x3c')]=Number(_0x5c54f0[_0x7721('0x3c')]);}return _0x5c54f0;}function getTicket(_0x1acc72,_0x22ef35,_0x4a90ce,_0xa389fa,_0x4cf659){logger[_0x7721('0x15')](_0x7721('0x3d'));var _0x5a278e=_[_0x7721('0x3e')]({'subject':intUtil[_0x7721('0x3f')](_0xa389fa['Subjects'],_0x4cf659,'\x20'),'type':'phone','status':_0x7721('0x40'),'labels':[_0x7721('0x41'),_0x7721('0x42'),_0x7721('0x43')]['concat'](getTags(_0xa389fa[_0x7721('0x44')],_0x7721('0x3a'))),'description':intUtil[_0x7721('0x3f')](_0xa389fa[_0x7721('0x45')],_0x4cf659,'\x0a'),'_links':{'assigned_user':{'href':util[_0x7721('0xe')]('/api/v2/users/%d',_0x22ef35['id']),'class':_0x7721('0x46')}},'message':{'direction':'in','body':intUtil['getString'](_0xa389fa[_0x7721('0x45')],_0x4cf659,'\x0a')}},getCustomFields(_0xa389fa['Fields'],_0x4cf659));return request({'uri':util[_0x7721('0xe')](_0x7721('0x47'),_0x1acc72[_0x7721('0x10')],_0x4a90ce['id']),'method':'POST','body':_0x5a278e});}exports[_0x7721('0x48')]=function(_0x11d853,_0x1ad315,_0x481fa8,_0x9f7b1d,_0x754071,_0xdb3033){var _0x2d5f35,_0x135dbc;_0xdb3033[_0x7721('0x10')]=intUtil[_0x7721('0x49')](_0xdb3033['remoteUri']);_0xdb3033['serverUrl']=intUtil[_0x7721('0x49')](_0xdb3033[_0x7721('0x4a')]);if(_0x754071&&_0x754071[_0x7721('0x4b')]){logger[_0x7721('0x15')](_0x7721('0x4c'),_0x7721('0x4d'));_0x1ad315[_0x7721('0x4e')]=util[_0x7721('0xe')](_0x7721('0x4f'),_0xdb3033[_0x7721('0x4a')],_0x1ad315['uniqueid'],md5(_0x1ad315['uniqueid']));}else{_0x1ad315[_0x7721('0x4e')]='';}headers[_0x7721('0x50')]=getAuth(_0xdb3033);return getUser(_0xdb3033,_0x9f7b1d[_0x7721('0x51')])[_0x7721('0x11')](function(_0x589e95){_0x2d5f35=_0x589e95;logger[_0x7721('0x15')](_0x7721('0x52'),_0x2d5f35['id']);return getEndUser(_0xdb3033,_0x1ad315['calleridname'],_0x1ad315[_0x7721('0x53')]);})['then'](function(_0x2682b1){_0x135dbc=_0x2682b1;logger['info'](_0x7721('0x54'),_0x135dbc['id']);return getTicket(_0xdb3033,_0x2d5f35,_0x135dbc,_0x481fa8,_0x1ad315);})[_0x7721('0x11')](function(_0xf17c40){if(_0xf17c40){logger['info'](_0x7721('0x55'));logger[_0x7721('0x15')]('The\x20Ticket\x20ID\x20is:',_0xf17c40['id']);switch(_0xdb3033[_0x7721('0x37')]){case _0x7721('0x56'):logger[_0x7721('0x15')]('[QUEUE]',_0x7721('0x57'));emit(util['format'](_0x7721('0x58'),_0x9f7b1d[_0x7721('0x3a')]),_0x7721('0x59'),{'recordId':_0xf17c40['id']});break;case _0x7721('0x5a'):logger[_0x7721('0x15')](_0x7721('0x4c'),_0x7721('0x5b'));emit(util[_0x7721('0xe')](_0x7721('0x58'),_0x9f7b1d[_0x7721('0x3a')]),_0x7721('0x5c'),{'uri':util[_0x7721('0xe')](_0x7721('0x5d'),_0xf17c40['id'])});break;default:logger[_0x7721('0x5e')](_0x7721('0x4c'),'Desk\x20account\x20type\x20not\x20recognized');}}})[_0x7721('0x5f')](function(_0x2f6f30){console[_0x7721('0x5e')](_0x2f6f30);logger[_0x7721('0x5e')](_0x7721('0x4c'),JSON[_0x7721('0x1a')](_0x2f6f30));});};exports[_0x7721('0x60')]=function(_0x57484c,_0x234bee,_0x17036e,_0x134908,_0x3b7382,_0x1f1e84,_0x9c0d4){var _0x7fbd6c,_0x33287d;_0x1f1e84[_0x7721('0x10')]=intUtil[_0x7721('0x49')](_0x1f1e84[_0x7721('0x10')]);_0x1f1e84['serverUrl']=intUtil[_0x7721('0x49')](_0x1f1e84[_0x7721('0x4a')]);if(_0x9c0d4&&_0x9c0d4[_0x7721('0x61')]&&_0x9c0d4[_0x7721('0x61')]!==_0x7721('0x62')){logger[_0x7721('0x15')](_0x7721('0x63'),_0x7721('0x4d'));_0x234bee[_0x7721('0x4e')]=util[_0x7721('0xe')](_0x7721('0x4f'),_0x1f1e84[_0x7721('0x4a')],_0x234bee[_0x7721('0x64')],md5(_0x234bee[_0x7721('0x64')]));}headers[_0x7721('0x50')]=getAuth(_0x1f1e84);return getUser(_0x1f1e84,_0x134908['email'])['then'](function(_0x4e112e){_0x7fbd6c=_0x4e112e;logger[_0x7721('0x15')]('The\x20User\x20ID\x20is:',_0x7fbd6c['id']);return getEndUser(_0x1f1e84,_0x234bee['destcalleridname'],_0x234bee['destcalleridnum']);})['then'](function(_0x47925a){_0x33287d=_0x47925a;logger[_0x7721('0x15')](_0x7721('0x54'),_0x33287d['id']);return getTicket(_0x1f1e84,_0x7fbd6c,_0x33287d,_0x17036e,_0x234bee);})['then'](function(_0x5181d7){if(_0x5181d7){logger['info']('Ticket\x20created!');logger['info'](_0x7721('0x65'),_0x5181d7['id']);switch(_0x1f1e84['type']){case'integrationTab':logger['info'](_0x7721('0x4c'),_0x7721('0x57'));emit(util[_0x7721('0xe')]('user:%s',_0x134908[_0x7721('0x3a')]),_0x7721('0x59'),{'recordId':_0x5181d7['id']});break;case _0x7721('0x5a'):logger[_0x7721('0x15')](_0x7721('0x4c'),_0x7721('0x5b'));emit(util[_0x7721('0xe')](_0x7721('0x58'),_0x134908[_0x7721('0x3a')]),_0x7721('0x5c'),{'uri':util[_0x7721('0xe')](_0x7721('0x66'),_0x1f1e84[_0x7721('0x10')],_0x5181d7['id'])});break;default:logger[_0x7721('0x5e')](_0x7721('0x63'),'Desk\x20account\x20type\x20not\x20recognized');}}})[_0x7721('0x5f')](function(_0x2c93b0){logger[_0x7721('0x5e')](_0x7721('0x63'),JSON['stringify'](_0x2c93b0));});};exports[_0x7721('0x67')]=function(_0x104f05,_0x4c8284,_0x3e7df3,_0x5d37ad,_0x1f508d,_0x4bfb48){var _0x36a3a6,_0x3f9eaa;_0x4bfb48[_0x7721('0x10')]=intUtil[_0x7721('0x49')](_0x4bfb48[_0x7721('0x10')]);_0x4bfb48[_0x7721('0x4a')]=intUtil[_0x7721('0x49')](_0x4bfb48['serverUrl']);if(_0x1f508d&&_0x1f508d[_0x7721('0x4b')]){logger[_0x7721('0x15')]('['+_0x4c8284[_0x7721('0x68')][_0x7721('0x69')]()+']',_0x7721('0x4d'));_0x4c8284[_0x7721('0x4e')]=util[_0x7721('0xe')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x4bfb48[_0x7721('0x4a')],_0x4c8284[_0x7721('0x64')],md5(_0x4c8284['uniqueid']));}else{_0x4c8284[_0x7721('0x4e')]='';}headers['Authorization']=getAuth(_0x4bfb48);return getUser(_0x4bfb48)[_0x7721('0x11')](function(_0x382800){_0x36a3a6=_0x382800;logger[_0x7721('0x15')](_0x7721('0x52'),_0x36a3a6['id']);return getEndUser(_0x4bfb48,_0x4c8284[_0x7721('0x6a')],_0x4c8284[_0x7721('0x53')]);})[_0x7721('0x11')](function(_0x5dca04){_0x3f9eaa=_0x5dca04;logger[_0x7721('0x15')](_0x7721('0x54'),_0x3f9eaa['id']);return getTicket(_0x4bfb48,_0x36a3a6,_0x3f9eaa,_0x3e7df3,_0x4c8284);})[_0x7721('0x11')](function(_0x5f08cc){if(_0x5f08cc){logger['info']('Ticket\x20created!');logger['info']('The\x20Ticket\x20ID\x20is:',_0x5f08cc['id']);}})[_0x7721('0x5f')](function(_0x2645dd){logger['error']('['+_0x4c8284[_0x7721('0x68')][_0x7721('0x69')]()+']',JSON[_0x7721('0x1a')](_0x2645dd));});};
\ No newline at end of file