Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / services / ami / trigger / integration / desk.js
index addc6c4..4aa53a7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xe2cf=['calleridnum','request-promise','util','./util','../../../../config/environment','../../../../config/logger','desk','defaults','redis','emit','application/json','validateEmail','info','format','%s/users','remoteUri','then','total_entries','find','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me','[HTTP]','stringify','GET','basic','%s:%s','username','authType','%s/token:%s','Basic\x20%s','base64','Searching\x20enduser\x20with\x20phone','%s/customers/search','Enduser\x20found!','_embedded','%s/customers','work','length','map','forEach','type','string','nameField','toLowerCase','content','toString','idField','customField','custom_fields','variable','variableName','Variable','name','priority','Creating\x20new\x20ticket...','merge','getString','Subjects','phone','new','xCALLY','Motion','CTI','Tags','user','Descriptions','Fields','%s/customers/%d/cases','POST','queue','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','Authorization','The\x20User\x20ID\x20is:','The\x20Enduser\x20ID\x20is:','integrationTab','Displaying\x20ticket\x20to\x20agent...','user:%s','trigger:desk:display','trigger:browser:url','https://xcally.desk.com/web/agent/case/%d','error','Desk\x20account\x20type\x20not\x20recognized','catch','outbound','recordingFormat','none','email','destcalleridname','destcalleridnum','Ticket\x20created!','The\x20Ticket\x20ID\x20is:','newTab','%s/agent/tickets/%s','[OUTBOUND]','abandoned','[ABANDONED]','calleridname'];(function(_0x421027,_0x20273b){var _0x4938ed=function(_0x14d9dd){while(--_0x14d9dd){_0x421027['push'](_0x421027['shift']());}};_0x4938ed(++_0x20273b);}(_0xe2cf,0x1a1));var _0xfe2c=function(_0x46759d,_0x13e994){_0x46759d=_0x46759d-0x0;var _0x3e7fe0=_0xe2cf[_0x46759d];return _0x3e7fe0;};'use strict';var _=require('lodash');var rp=require(_0xfe2c('0x0'));var md5=require('md5');var util=require(_0xfe2c('0x1'));var Redis=require('ioredis');var intUtil=require(_0xfe2c('0x2'));var config=require(_0xfe2c('0x3'));var logger=require(_0xfe2c('0x4'))(_0xfe2c('0x5'));config['redis']=_[_0xfe2c('0x6')](config[_0xfe2c('0x7')],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xfe2c('0x7')]));function emit(_0x417bc4,_0x5e5b46,_0x485a24){io['to'](_0x417bc4)[_0xfe2c('0x8')](_0x5e5b46,_0x485a24);}var headers={'Content-Type':_0xfe2c('0x9'),'Accept':_0xfe2c('0x9')};function getUser(_0x562414,_0x5b616c){if(intUtil[_0xfe2c('0xa')](_0x5b616c)===!![]){logger[_0xfe2c('0xb')]('Getting\x20agent\x20with\x20email',_0x5b616c);return request({'uri':util[_0xfe2c('0xc')](_0xfe2c('0xd'),_0x562414[_0xfe2c('0xe')])})[_0xfe2c('0xf')](function(_0x325608){if(_0x325608[_0xfe2c('0x10')]){return _[_0xfe2c('0x11')](_0x325608['_embedded']['entries'],{'email':_0x5b616c});}})['then'](function(_0x48ddcc){if(_0x48ddcc){logger[_0xfe2c('0xb')]('Agent\x20found!');return _0x48ddcc;}else{logger['info'](_0xfe2c('0x12'));return request({'uri':util[_0xfe2c('0xc')](_0xfe2c('0x13'),_0x562414[_0xfe2c('0xe')])});}});}else{logger['info']('Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!');return request({'uri':util[_0xfe2c('0xc')](_0xfe2c('0x13'),_0x562414[_0xfe2c('0xe')])});}}function request(_0x56cebc){logger['debug'](_0xfe2c('0x14'),JSON[_0xfe2c('0x15')](_0x56cebc));return rp(_[_0xfe2c('0x6')](_0x56cebc,{'method':_0xfe2c('0x16'),'headers':headers,'json':!![]}));}function getAuth(_0x36aeec){var _0x13f233;if(_0x36aeec['authType']===_0xfe2c('0x17')){_0x13f233=util[_0xfe2c('0xc')](_0xfe2c('0x18'),_0x36aeec[_0xfe2c('0x19')],_0x36aeec['password']);}else if(_0x36aeec[_0xfe2c('0x1a')]==='token'){_0x13f233=util['format'](_0xfe2c('0x1b'),_0x36aeec[_0xfe2c('0x19')],_0x36aeec['token']);}return util[_0xfe2c('0xc')](_0xfe2c('0x1c'),new Buffer(_0x13f233)['toString'](_0xfe2c('0x1d')));}function getEndUser(_0x5dd54b,_0x4481ff,_0x466bcd){logger[_0xfe2c('0xb')](_0xfe2c('0x1e'),_0x466bcd);return request({'uri':util[_0xfe2c('0xc')](_0xfe2c('0x1f'),_0x5dd54b['remoteUri']),'qs':{'phone':_0x466bcd}})[_0xfe2c('0xf')](function(_0x45a722){if(_0x45a722[_0xfe2c('0x10')]){logger[_0xfe2c('0xb')](_0xfe2c('0x20'));return _0x45a722[_0xfe2c('0x21')]['entries'][0x0];}else{logger[_0xfe2c('0xb')]('Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!');return request({'uri':util[_0xfe2c('0xc')](_0xfe2c('0x22'),_0x5dd54b[_0xfe2c('0xe')]),'method':'POST','body':{'first_name':_0x4481ff,'title':_0x4481ff,'phone_numbers':[{'type':_0xfe2c('0x23'),'value':_0x466bcd}]}});}});}function getTags(_0x344ca0,_0x59094a){var _0x3d7e1f=[];if(_0x344ca0&&_0x344ca0[_0xfe2c('0x24')]>0x0){_0x3d7e1f=_[_0xfe2c('0x25')](_0x344ca0,_0x59094a);}return _0x3d7e1f;}function getCustomFields(_0x53a8c1,_0x170026){var _0x1b7c91=[];var _0x55aed7={'custom_fields':{}};if(_0x53a8c1['length']>0x0){_[_0xfe2c('0x26')](_0x53a8c1,function(_0x13e9a9){if(_0x13e9a9[_0xfe2c('0x27')]===_0xfe2c('0x28')&&_0x13e9a9[_0xfe2c('0x29')]&&!_0x13e9a9['customField']){_0x55aed7[_0x13e9a9[_0xfe2c('0x29')][_0xfe2c('0x2a')]()]=_0x13e9a9[_0xfe2c('0x2b')][_0xfe2c('0x2c')]();}else if(_0x13e9a9[_0xfe2c('0x27')]===_0xfe2c('0x28')&&_0x13e9a9[_0xfe2c('0x2d')]&&_0x13e9a9[_0xfe2c('0x2e')]){_0x55aed7[_0xfe2c('0x2f')][_0x13e9a9[_0xfe2c('0x2d')]]=_0x13e9a9[_0xfe2c('0x2b')][_0xfe2c('0x2c')]();}else if(_0x13e9a9['type']===_0xfe2c('0x30')&&_0x13e9a9[_0xfe2c('0x31')]&&_0x13e9a9[_0xfe2c('0x2d')]&&_0x13e9a9['customField']){_0x170026[_0x13e9a9[_0xfe2c('0x31')]]&&(_0x55aed7[_0xfe2c('0x2f')][_0x13e9a9['idField']]=_0x170026[_0x13e9a9[_0xfe2c('0x31')]][_0xfe2c('0x2c')]());}else if(_0x13e9a9[_0xfe2c('0x27')]==='customVariable'&&_0x13e9a9[_0xfe2c('0x32')]&&_0x13e9a9[_0xfe2c('0x32')][_0xfe2c('0x33')]&&_0x13e9a9[_0xfe2c('0x2d')]&&_0x13e9a9[_0xfe2c('0x2e')]){_0x170026[_0x13e9a9[_0xfe2c('0x32')][_0xfe2c('0x33')]['toLowerCase']()]&&(_0x55aed7['custom_fields'][_0x13e9a9[_0xfe2c('0x2d')]]=_0x170026[_0x13e9a9[_0xfe2c('0x32')][_0xfe2c('0x33')][_0xfe2c('0x2a')]()]['toString']());}});}if(_0x55aed7[_0xfe2c('0x34')]){_0x55aed7['priority']=Number(_0x55aed7[_0xfe2c('0x34')]);}return _0x55aed7;}function getTicket(_0x31ba48,_0x5c849c,_0x1d5877,_0x4a0ced,_0x5d726a){logger[_0xfe2c('0xb')](_0xfe2c('0x35'));var _0x2c1b43=_[_0xfe2c('0x36')]({'subject':intUtil[_0xfe2c('0x37')](_0x4a0ced[_0xfe2c('0x38')],_0x5d726a,'\x20'),'type':_0xfe2c('0x39'),'status':_0xfe2c('0x3a'),'labels':[_0xfe2c('0x3b'),_0xfe2c('0x3c'),_0xfe2c('0x3d')]['concat'](getTags(_0x4a0ced[_0xfe2c('0x3e')],_0xfe2c('0x33'))),'description':intUtil[_0xfe2c('0x37')](_0x4a0ced['Descriptions'],_0x5d726a,'\x0a'),'_links':{'assigned_user':{'href':util['format']('/api/v2/users/%d',_0x5c849c['id']),'class':_0xfe2c('0x3f')}},'message':{'direction':'in','body':intUtil[_0xfe2c('0x37')](_0x4a0ced[_0xfe2c('0x40')],_0x5d726a,'\x0a')}},getCustomFields(_0x4a0ced[_0xfe2c('0x41')],_0x5d726a));return request({'uri':util['format'](_0xfe2c('0x42'),_0x31ba48[_0xfe2c('0xe')],_0x1d5877['id']),'method':_0xfe2c('0x43'),'body':_0x2c1b43});}exports[_0xfe2c('0x44')]=function(_0xe8cc05,_0x48e361,_0x5a8d4e,_0xeb04b9,_0x6055dd,_0x789810){var _0x5a69c0,_0x5d87e9;_0x789810[_0xfe2c('0xe')]=intUtil[_0xfe2c('0x45')](_0x789810['remoteUri']);_0x789810[_0xfe2c('0x46')]=intUtil[_0xfe2c('0x45')](_0x789810[_0xfe2c('0x46')]);if(_0x6055dd&&_0x6055dd[_0xfe2c('0x47')]){logger['info'](_0xfe2c('0x48'),_0xfe2c('0x49'));_0x48e361[_0xfe2c('0x4a')]=util[_0xfe2c('0xc')](_0xfe2c('0x4b'),_0x789810[_0xfe2c('0x46')],_0x48e361[_0xfe2c('0x4c')],md5(_0x48e361[_0xfe2c('0x4c')]));}else{_0x48e361['recordingURL']='';}headers[_0xfe2c('0x4d')]=getAuth(_0x789810);return getUser(_0x789810,_0xeb04b9['email'])[_0xfe2c('0xf')](function(_0x362769){_0x5a69c0=_0x362769;logger[_0xfe2c('0xb')](_0xfe2c('0x4e'),_0x5a69c0['id']);return getEndUser(_0x789810,_0x48e361['calleridname'],_0x48e361['calleridnum']);})['then'](function(_0x56eaca){_0x5d87e9=_0x56eaca;logger['info'](_0xfe2c('0x4f'),_0x5d87e9['id']);return getTicket(_0x789810,_0x5a69c0,_0x5d87e9,_0x5a8d4e,_0x48e361);})['then'](function(_0x512a2b){if(_0x512a2b){logger[_0xfe2c('0xb')]('Ticket\x20created!');logger[_0xfe2c('0xb')]('The\x20Ticket\x20ID\x20is:',_0x512a2b['id']);switch(_0x789810[_0xfe2c('0x27')]){case _0xfe2c('0x50'):logger[_0xfe2c('0xb')](_0xfe2c('0x48'),_0xfe2c('0x51'));emit(util['format'](_0xfe2c('0x52'),_0xeb04b9[_0xfe2c('0x33')]),_0xfe2c('0x53'),{'recordId':_0x512a2b['id']});break;case'newTab':logger[_0xfe2c('0xb')](_0xfe2c('0x48'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util['format']('user:%s',_0xeb04b9[_0xfe2c('0x33')]),_0xfe2c('0x54'),{'uri':util[_0xfe2c('0xc')](_0xfe2c('0x55'),_0x512a2b['id'])});break;default:logger[_0xfe2c('0x56')]('[QUEUE]',_0xfe2c('0x57'));}}})[_0xfe2c('0x58')](function(_0x3f57f4){console['error'](_0x3f57f4);logger['error'](_0xfe2c('0x48'),JSON[_0xfe2c('0x15')](_0x3f57f4));});};exports[_0xfe2c('0x59')]=function(_0x154381,_0x384766,_0x45e013,_0x218d64,_0x37e3de,_0x39c745,_0x45b285){var _0x4f4811,_0x22d32a;_0x39c745[_0xfe2c('0xe')]=intUtil[_0xfe2c('0x45')](_0x39c745[_0xfe2c('0xe')]);_0x39c745[_0xfe2c('0x46')]=intUtil[_0xfe2c('0x45')](_0x39c745[_0xfe2c('0x46')]);if(_0x45b285&&_0x45b285[_0xfe2c('0x5a')]&&_0x45b285[_0xfe2c('0x5a')]!==_0xfe2c('0x5b')){logger[_0xfe2c('0xb')]('[OUTBOUND]',_0xfe2c('0x49'));_0x384766['recordingURL']=util[_0xfe2c('0xc')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x39c745['serverUrl'],_0x384766['uniqueid'],md5(_0x384766[_0xfe2c('0x4c')]));}headers['Authorization']=getAuth(_0x39c745);return getUser(_0x39c745,_0x218d64[_0xfe2c('0x5c')])['then'](function(_0x20c81b){_0x4f4811=_0x20c81b;logger[_0xfe2c('0xb')](_0xfe2c('0x4e'),_0x4f4811['id']);return getEndUser(_0x39c745,_0x384766[_0xfe2c('0x5d')],_0x384766[_0xfe2c('0x5e')]);})[_0xfe2c('0xf')](function(_0x8f807c){_0x22d32a=_0x8f807c;logger[_0xfe2c('0xb')](_0xfe2c('0x4f'),_0x22d32a['id']);return getTicket(_0x39c745,_0x4f4811,_0x22d32a,_0x45e013,_0x384766);})['then'](function(_0x9725e0){if(_0x9725e0){logger[_0xfe2c('0xb')](_0xfe2c('0x5f'));logger[_0xfe2c('0xb')](_0xfe2c('0x60'),_0x9725e0['id']);switch(_0x39c745['type']){case _0xfe2c('0x50'):logger[_0xfe2c('0xb')]('[QUEUE]','Displaying\x20ticket\x20to\x20agent...');emit(util[_0xfe2c('0xc')](_0xfe2c('0x52'),_0x218d64[_0xfe2c('0x33')]),_0xfe2c('0x53'),{'recordId':_0x9725e0['id']});break;case _0xfe2c('0x61'):logger[_0xfe2c('0xb')](_0xfe2c('0x48'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0xfe2c('0xc')](_0xfe2c('0x52'),_0x218d64[_0xfe2c('0x33')]),_0xfe2c('0x54'),{'uri':util[_0xfe2c('0xc')](_0xfe2c('0x62'),_0x39c745[_0xfe2c('0xe')],_0x9725e0['id'])});break;default:logger['error'](_0xfe2c('0x63'),'Desk\x20account\x20type\x20not\x20recognized');}}})[_0xfe2c('0x58')](function(_0x349d72){logger['error'](_0xfe2c('0x63'),JSON['stringify'](_0x349d72));});};exports[_0xfe2c('0x64')]=function(_0x377064,_0x4b1e65,_0x476cf9,_0x5b4abf,_0x14c38d,_0x5231ae){var _0x23827b,_0x3c1f15;_0x5231ae['remoteUri']=intUtil[_0xfe2c('0x45')](_0x5231ae[_0xfe2c('0xe')]);_0x5231ae[_0xfe2c('0x46')]=intUtil[_0xfe2c('0x45')](_0x5231ae[_0xfe2c('0x46')]);if(_0x14c38d&&_0x14c38d['monitor_format']){logger[_0xfe2c('0xb')](_0xfe2c('0x65'),_0xfe2c('0x49'));_0x4b1e65[_0xfe2c('0x4a')]=util['format'](_0xfe2c('0x4b'),_0x5231ae['serverUrl'],_0x4b1e65[_0xfe2c('0x4c')],md5(_0x4b1e65['uniqueid']));}else{_0x4b1e65[_0xfe2c('0x4a')]='';}headers[_0xfe2c('0x4d')]=getAuth(_0x5231ae);return getUser(_0x5231ae)[_0xfe2c('0xf')](function(_0x281213){_0x23827b=_0x281213;logger[_0xfe2c('0xb')](_0xfe2c('0x4e'),_0x23827b['id']);return getEndUser(_0x5231ae,_0x4b1e65[_0xfe2c('0x66')],_0x4b1e65[_0xfe2c('0x67')]);})[_0xfe2c('0xf')](function(_0x21b07a){_0x3c1f15=_0x21b07a;logger[_0xfe2c('0xb')](_0xfe2c('0x4f'),_0x3c1f15['id']);return getTicket(_0x5231ae,_0x23827b,_0x3c1f15,_0x476cf9,_0x4b1e65);})[_0xfe2c('0xf')](function(_0x3ea492){if(_0x3ea492){logger[_0xfe2c('0xb')](_0xfe2c('0x5f'));logger['info'](_0xfe2c('0x60'),_0x3ea492['id']);}})['catch'](function(_0xdafb46){logger['error'](_0xfe2c('0x65'),JSON['stringify'](_0xdafb46));});};
\ No newline at end of file
+var _0x5fc3=['map','forEach','includes','string','picklist','nameField','customField','toLowerCase','content','type','custom_fields','variable','variableName','idField','Variable','name','priority','Creating\x20new\x20ticket...','merge','getString','phone','new','xCALLY','Motion','CTI','concat','Descriptions','/api/v2/users/%d','user','Fields','%s/customers/%d/cases','queue','stripTrailingSlash','serverUrl','monitor_format','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','Authorization','email','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','integrationTab','[QUEUE]','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','outbound','recordingFormat','none','recordingURL','The\x20User\x20ID\x20is:','destcalleridnum','Ticket\x20created!','[OUTBOUND]','unmanaged','lastevent','Recording\x20is\x20enabled!','lodash','request-promise','util','ioredis','./util','../../../../config/environment','../../../../config/logger','redis','defaults','emit','application/json','info','Getting\x20agent\x20with\x20email','%s/users','remoteUri','total_entries','entries','Agent\x20found!','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!','format','%s/users/me','debug','stringify','authType','%s:%s','username','token','%s/token:%s','Basic\x20%s','toString','base64','Searching\x20enduser\x20with\x20phone','then','Enduser\x20found!','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','POST','length'];(function(_0xdea41a,_0x552987){var _0x15d0d8=function(_0x1e0d0b){while(--_0x1e0d0b){_0xdea41a['push'](_0xdea41a['shift']());}};_0x15d0d8(++_0x552987);}(_0x5fc3,0xa8));var _0x35fc=function(_0x3a4318,_0x13c6eb){_0x3a4318=_0x3a4318-0x0;var _0x36d746=_0x5fc3[_0x3a4318];return _0x36d746;};'use strict';var _=require(_0x35fc('0x0'));var rp=require(_0x35fc('0x1'));var md5=require('md5');var util=require(_0x35fc('0x2'));var Redis=require(_0x35fc('0x3'));var intUtil=require(_0x35fc('0x4'));var config=require(_0x35fc('0x5'));var logger=require(_0x35fc('0x6'))('desk');config[_0x35fc('0x7')]=_[_0x35fc('0x8')](config[_0x35fc('0x7')],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x35fc('0x7')]));function emit(_0x508b32,_0x16e153,_0x27524f){io['to'](_0x508b32)[_0x35fc('0x9')](_0x16e153,_0x27524f);}var headers={'Content-Type':_0x35fc('0xa'),'Accept':_0x35fc('0xa')};function getUser(_0xf9d3a6,_0x2051ab){if(intUtil['validateEmail'](_0x2051ab)===!![]){logger[_0x35fc('0xb')](_0x35fc('0xc'),_0x2051ab);return request({'uri':util['format'](_0x35fc('0xd'),_0xf9d3a6[_0x35fc('0xe')])})['then'](function(_0xda83fb){if(_0xda83fb[_0x35fc('0xf')]){return _['find'](_0xda83fb['_embedded'][_0x35fc('0x10')],{'email':_0x2051ab});}})['then'](function(_0x397738){if(_0x397738){logger[_0x35fc('0xb')](_0x35fc('0x11'));return _0x397738;}else{logger[_0x35fc('0xb')](_0x35fc('0x12'));return request({'uri':util['format']('%s/users/me',_0xf9d3a6['remoteUri'])});}});}else{logger['info'](_0x35fc('0x13'));return request({'uri':util[_0x35fc('0x14')](_0x35fc('0x15'),_0xf9d3a6[_0x35fc('0xe')])});}}function request(_0x227a49){logger[_0x35fc('0x16')]('[HTTP]',JSON[_0x35fc('0x17')](_0x227a49));return rp(_[_0x35fc('0x8')](_0x227a49,{'method':'GET','headers':headers,'json':!![]}));}function getAuth(_0x41e165){var _0x363e47;if(_0x41e165[_0x35fc('0x18')]==='basic'){_0x363e47=util[_0x35fc('0x14')](_0x35fc('0x19'),_0x41e165[_0x35fc('0x1a')],_0x41e165['password']);}else if(_0x41e165[_0x35fc('0x18')]===_0x35fc('0x1b')){_0x363e47=util[_0x35fc('0x14')](_0x35fc('0x1c'),_0x41e165[_0x35fc('0x1a')],_0x41e165[_0x35fc('0x1b')]);}return util[_0x35fc('0x14')](_0x35fc('0x1d'),new Buffer(_0x363e47)[_0x35fc('0x1e')](_0x35fc('0x1f')));}function getEndUser(_0x5bd2b8,_0x323aee,_0xd5399f){logger[_0x35fc('0xb')](_0x35fc('0x20'),_0xd5399f);return request({'uri':util[_0x35fc('0x14')]('%s/customers/search',_0x5bd2b8[_0x35fc('0xe')]),'qs':{'phone':_0xd5399f}})[_0x35fc('0x21')](function(_0x561bf8){if(_0x561bf8[_0x35fc('0xf')]){logger[_0x35fc('0xb')](_0x35fc('0x22'));return _0x561bf8['_embedded'][_0x35fc('0x10')][0x0];}else{logger['info'](_0x35fc('0x23'));return request({'uri':util[_0x35fc('0x14')]('%s/customers',_0x5bd2b8['remoteUri']),'method':_0x35fc('0x24'),'body':{'first_name':_0x323aee,'title':_0x323aee,'phone_numbers':[{'type':'work','value':_0xd5399f}]}});}});}function getTags(_0x274208,_0x1a5d92){var _0x57001c=[];if(_0x274208&&_0x274208[_0x35fc('0x25')]>0x0){_0x57001c=_[_0x35fc('0x26')](_0x274208,_0x1a5d92);}return _0x57001c;}function getCustomFields(_0x383837,_0x9f3c8a){var _0x3735da=[];var _0x134dfa={'custom_fields':{}};if(_0x383837[_0x35fc('0x25')]>0x0){_[_0x35fc('0x27')](_0x383837,function(_0x54aedc){if(_[_0x35fc('0x28')]([_0x35fc('0x29'),_0x35fc('0x2a')],_0x54aedc['type'])&&_0x54aedc[_0x35fc('0x2b')]&&!_0x54aedc[_0x35fc('0x2c')]){_0x134dfa[_0x54aedc[_0x35fc('0x2b')][_0x35fc('0x2d')]()]=_0x54aedc[_0x35fc('0x2e')][_0x35fc('0x1e')]();}else if(_[_0x35fc('0x28')]([_0x35fc('0x29'),_0x35fc('0x2a')],_0x54aedc[_0x35fc('0x2f')])&&_0x54aedc['idField']&&_0x54aedc['customField']){_0x134dfa[_0x35fc('0x30')][_0x54aedc['idField']]=_0x54aedc[_0x35fc('0x2e')][_0x35fc('0x1e')]();}else if(_0x54aedc[_0x35fc('0x2f')]===_0x35fc('0x31')&&_0x54aedc[_0x35fc('0x32')]&&_0x54aedc[_0x35fc('0x33')]&&_0x54aedc['customField']){_0x9f3c8a[_0x54aedc[_0x35fc('0x32')]]&&(_0x134dfa[_0x35fc('0x30')][_0x54aedc[_0x35fc('0x33')]]=_0x9f3c8a[_0x54aedc[_0x35fc('0x32')]][_0x35fc('0x1e')]());}else if(_0x54aedc[_0x35fc('0x2f')]==='customVariable'&&_0x54aedc[_0x35fc('0x34')]&&_0x54aedc[_0x35fc('0x34')][_0x35fc('0x35')]&&_0x54aedc['idField']&&_0x54aedc[_0x35fc('0x2c')]){_0x9f3c8a[_0x54aedc['Variable'][_0x35fc('0x35')][_0x35fc('0x2d')]()]&&(_0x134dfa[_0x35fc('0x30')][_0x54aedc[_0x35fc('0x33')]]=_0x9f3c8a[_0x54aedc['Variable']['name']['toLowerCase']()][_0x35fc('0x1e')]());}});}if(_0x134dfa['priority']){_0x134dfa[_0x35fc('0x36')]=Number(_0x134dfa['priority']);}return _0x134dfa;}function getTicket(_0x9c6b65,_0x1f2d66,_0x2ca9ac,_0x22b724,_0x1c10e0){logger[_0x35fc('0xb')](_0x35fc('0x37'));var _0x4ec0dc=_[_0x35fc('0x38')]({'subject':intUtil[_0x35fc('0x39')](_0x22b724['Subjects'],_0x1c10e0,'\x20'),'type':_0x35fc('0x3a'),'status':_0x35fc('0x3b'),'labels':[_0x35fc('0x3c'),_0x35fc('0x3d'),_0x35fc('0x3e')][_0x35fc('0x3f')](getTags(_0x22b724['Tags'],_0x35fc('0x35'))),'description':intUtil[_0x35fc('0x39')](_0x22b724[_0x35fc('0x40')],_0x1c10e0,'\x0a'),'_links':{'assigned_user':{'href':util['format'](_0x35fc('0x41'),_0x1f2d66['id']),'class':_0x35fc('0x42')}},'message':{'direction':'in','body':intUtil['getString'](_0x22b724[_0x35fc('0x40')],_0x1c10e0,'\x0a')}},getCustomFields(_0x22b724[_0x35fc('0x43')],_0x1c10e0));return request({'uri':util[_0x35fc('0x14')](_0x35fc('0x44'),_0x9c6b65[_0x35fc('0xe')],_0x2ca9ac['id']),'method':_0x35fc('0x24'),'body':_0x4ec0dc});}exports[_0x35fc('0x45')]=function(_0x3ec51f,_0x5a7e9e,_0x596e83,_0x210d5d,_0x36fcf9,_0x4fdc6d){var _0x5c2e5c,_0x4ff202;_0x4fdc6d[_0x35fc('0xe')]=intUtil[_0x35fc('0x46')](_0x4fdc6d['remoteUri']);_0x4fdc6d[_0x35fc('0x47')]=intUtil[_0x35fc('0x46')](_0x4fdc6d[_0x35fc('0x47')]);if(_0x36fcf9&&_0x36fcf9[_0x35fc('0x48')]){logger['info']('[QUEUE]','Recording\x20is\x20enabled!');_0x5a7e9e['recordingURL']=util['format'](_0x35fc('0x49'),_0x4fdc6d[_0x35fc('0x47')],_0x5a7e9e['uniqueid'],md5(_0x5a7e9e[_0x35fc('0x4a')]));}else{_0x5a7e9e['recordingURL']='';}headers[_0x35fc('0x4b')]=getAuth(_0x4fdc6d);return getUser(_0x4fdc6d,_0x210d5d[_0x35fc('0x4c')])[_0x35fc('0x21')](function(_0x2de5d1){_0x5c2e5c=_0x2de5d1;logger[_0x35fc('0xb')]('The\x20User\x20ID\x20is:',_0x5c2e5c['id']);return getEndUser(_0x4fdc6d,_0x5a7e9e[_0x35fc('0x4d')],_0x5a7e9e[_0x35fc('0x4e')]);})['then'](function(_0x18181b){_0x4ff202=_0x18181b;logger[_0x35fc('0xb')](_0x35fc('0x4f'),_0x4ff202['id']);return getTicket(_0x4fdc6d,_0x5c2e5c,_0x4ff202,_0x596e83,_0x5a7e9e);})[_0x35fc('0x21')](function(_0x5bc8c3){if(_0x5bc8c3){logger[_0x35fc('0xb')]('Ticket\x20created!');logger['info'](_0x35fc('0x50'),_0x5bc8c3['id']);switch(_0x4fdc6d[_0x35fc('0x2f')]){case _0x35fc('0x51'):logger[_0x35fc('0xb')](_0x35fc('0x52'),_0x35fc('0x53'));emit(util[_0x35fc('0x14')](_0x35fc('0x54'),_0x210d5d['name']),_0x35fc('0x55'),{'recordId':_0x5bc8c3['id']});break;case _0x35fc('0x56'):logger[_0x35fc('0xb')](_0x35fc('0x52'),_0x35fc('0x57'));emit(util[_0x35fc('0x14')](_0x35fc('0x54'),_0x210d5d[_0x35fc('0x35')]),_0x35fc('0x58'),{'uri':util[_0x35fc('0x14')](_0x35fc('0x59'),_0x5bc8c3['id'])});break;default:logger[_0x35fc('0x5a')](_0x35fc('0x52'),_0x35fc('0x5b'));}}})['catch'](function(_0x553ed6){console[_0x35fc('0x5a')](_0x553ed6);logger[_0x35fc('0x5a')](_0x35fc('0x52'),JSON[_0x35fc('0x17')](_0x553ed6));});};exports[_0x35fc('0x5c')]=function(_0x3e6494,_0x4a4798,_0x4f024c,_0x388521,_0x19b2ce,_0x395d63,_0x38bc78){var _0x5b2595,_0x467980;_0x395d63[_0x35fc('0xe')]=intUtil['stripTrailingSlash'](_0x395d63[_0x35fc('0xe')]);_0x395d63[_0x35fc('0x47')]=intUtil['stripTrailingSlash'](_0x395d63[_0x35fc('0x47')]);if(_0x38bc78&&_0x38bc78[_0x35fc('0x5d')]&&_0x38bc78[_0x35fc('0x5d')]!==_0x35fc('0x5e')){logger['info']('[OUTBOUND]','Recording\x20is\x20enabled!');_0x4a4798[_0x35fc('0x5f')]=util[_0x35fc('0x14')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x395d63[_0x35fc('0x47')],_0x4a4798[_0x35fc('0x4a')],md5(_0x4a4798[_0x35fc('0x4a')]));}headers[_0x35fc('0x4b')]=getAuth(_0x395d63);return getUser(_0x395d63,_0x388521[_0x35fc('0x4c')])['then'](function(_0x2d9d45){_0x5b2595=_0x2d9d45;logger[_0x35fc('0xb')](_0x35fc('0x60'),_0x5b2595['id']);return getEndUser(_0x395d63,_0x4a4798['destcalleridname'],_0x4a4798[_0x35fc('0x61')]);})[_0x35fc('0x21')](function(_0x47fb1a){_0x467980=_0x47fb1a;logger[_0x35fc('0xb')](_0x35fc('0x4f'),_0x467980['id']);return getTicket(_0x395d63,_0x5b2595,_0x467980,_0x4f024c,_0x4a4798);})[_0x35fc('0x21')](function(_0x1c4c33){if(_0x1c4c33){logger[_0x35fc('0xb')](_0x35fc('0x62'));logger[_0x35fc('0xb')](_0x35fc('0x50'),_0x1c4c33['id']);switch(_0x395d63['type']){case _0x35fc('0x51'):logger[_0x35fc('0xb')](_0x35fc('0x52'),'Displaying\x20ticket\x20to\x20agent...');emit(util[_0x35fc('0x14')]('user:%s',_0x388521['name']),'trigger:desk:display',{'recordId':_0x1c4c33['id']});break;case _0x35fc('0x56'):logger[_0x35fc('0xb')](_0x35fc('0x52'),_0x35fc('0x57'));emit(util[_0x35fc('0x14')]('user:%s',_0x388521['name']),'trigger:browser:url',{'uri':util['format']('%s/agent/tickets/%s',_0x395d63[_0x35fc('0xe')],_0x1c4c33['id'])});break;default:logger[_0x35fc('0x5a')](_0x35fc('0x63'),_0x35fc('0x5b'));}}})['catch'](function(_0x458eb8){logger[_0x35fc('0x5a')](_0x35fc('0x63'),JSON[_0x35fc('0x17')](_0x458eb8));});};exports[_0x35fc('0x64')]=function(_0x1d0e53,_0x27071b,_0x2127e0,_0x462ceb,_0x4c3ace,_0x35d7c8){var _0x47c75f,_0xfbd737;_0x35d7c8[_0x35fc('0xe')]=intUtil[_0x35fc('0x46')](_0x35d7c8[_0x35fc('0xe')]);_0x35d7c8['serverUrl']=intUtil[_0x35fc('0x46')](_0x35d7c8['serverUrl']);if(_0x4c3ace&&_0x4c3ace['monitor_format']){logger['info']('['+_0x27071b[_0x35fc('0x65')]['toUpperCase']()+']',_0x35fc('0x66'));_0x27071b['recordingURL']=util[_0x35fc('0x14')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x35d7c8[_0x35fc('0x47')],_0x27071b[_0x35fc('0x4a')],md5(_0x27071b[_0x35fc('0x4a')]));}else{_0x27071b[_0x35fc('0x5f')]='';}headers['Authorization']=getAuth(_0x35d7c8);return getUser(_0x35d7c8)[_0x35fc('0x21')](function(_0x1e2214){_0x47c75f=_0x1e2214;logger[_0x35fc('0xb')]('The\x20User\x20ID\x20is:',_0x47c75f['id']);return getEndUser(_0x35d7c8,_0x27071b[_0x35fc('0x4d')],_0x27071b[_0x35fc('0x4e')]);})[_0x35fc('0x21')](function(_0x3c1b56){_0xfbd737=_0x3c1b56;logger[_0x35fc('0xb')](_0x35fc('0x4f'),_0xfbd737['id']);return getTicket(_0x35d7c8,_0x47c75f,_0xfbd737,_0x2127e0,_0x27071b);})[_0x35fc('0x21')](function(_0x4464d5){if(_0x4464d5){logger['info'](_0x35fc('0x62'));logger[_0x35fc('0xb')](_0x35fc('0x50'),_0x4464d5['id']);}})['catch'](function(_0x1c88d8){logger[_0x35fc('0x5a')]('['+_0x27071b['lastevent']['toUpperCase']()+']',JSON[_0x35fc('0x17')](_0x1c88d8));});};
\ No newline at end of file