Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / services / ami / trigger / integration / desk.js
index c08f5fd..cfb75a5 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4eec=['_embedded','entries','then','Agent\x20found!','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me','debug','[HTTP]','stringify','authType','basic','%s:%s','username','password','%s/token:%s','token','Basic\x20%s','toString','base64','Searching\x20enduser\x20with\x20phone','Enduser\x20found!','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','POST','work','length','forEach','includes','string','picklist','type','nameField','customField','toLowerCase','content','idField','variable','variableName','Variable','name','custom_fields','priority','Creating\x20new\x20ticket...','merge','getString','Subjects','new','xCALLY','CTI','Descriptions','/api/v2/users/%d','user','Fields','%s/customers/%d/cases','queue','serverUrl','stripTrailingSlash','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','uniqueid','Authorization','email','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','integrationTab','Displaying\x20ticket\x20to\x20agent...','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','https://xcally.desk.com/web/agent/case/%d','outbound','none','[OUTBOUND]','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','newTab','%s/agent/tickets/%s','error','Desk\x20account\x20type\x20not\x20recognized','catch','unmanaged','lastevent','toUpperCase','md5','ioredis','../../../../config/environment','../../../../config/logger','desk','defaults','localhost','socket.io-emitter','redis','emit','application/json','validateEmail','info','Getting\x20agent\x20with\x20email','format','%s/users','remoteUri','total_entries','find'];(function(_0x521bf6,_0x22adcd){var _0x1ffd15=function(_0x33f2dc){while(--_0x33f2dc){_0x521bf6['push'](_0x521bf6['shift']());}};_0x1ffd15(++_0x22adcd);}(_0x4eec,0x12b));var _0xc4ee=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x4eec[_0x3dd15e];return _0x231fd0;};'use strict';var _=require('lodash');var rp=require('request-promise');var md5=require(_0xc4ee('0x0'));var util=require('util');var Redis=require(_0xc4ee('0x1'));var intUtil=require('./util');var config=require(_0xc4ee('0x2'));var logger=require(_0xc4ee('0x3'))(_0xc4ee('0x4'));config['redis']=_[_0xc4ee('0x5')](config['redis'],{'host':_0xc4ee('0x6'),'port':0x18eb});var io=require(_0xc4ee('0x7'))(new Redis(config[_0xc4ee('0x8')]));function emit(_0x596002,_0x1126fb,_0x315f32){io['to'](_0x596002)[_0xc4ee('0x9')](_0x1126fb,_0x315f32);}var headers={'Content-Type':_0xc4ee('0xa'),'Accept':_0xc4ee('0xa')};function getUser(_0x5c6b90,_0x416ac9){if(intUtil[_0xc4ee('0xb')](_0x416ac9)===!![]){logger[_0xc4ee('0xc')](_0xc4ee('0xd'),_0x416ac9);return request({'uri':util[_0xc4ee('0xe')](_0xc4ee('0xf'),_0x5c6b90[_0xc4ee('0x10')])})['then'](function(_0x16386e){if(_0x16386e[_0xc4ee('0x11')]){return _[_0xc4ee('0x12')](_0x16386e[_0xc4ee('0x13')][_0xc4ee('0x14')],{'email':_0x416ac9});}})[_0xc4ee('0x15')](function(_0x3b6524){if(_0x3b6524){logger[_0xc4ee('0xc')](_0xc4ee('0x16'));return _0x3b6524;}else{logger[_0xc4ee('0xc')](_0xc4ee('0x17'));return request({'uri':util[_0xc4ee('0xe')]('%s/users/me',_0x5c6b90['remoteUri'])});}});}else{logger['info']('Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!');return request({'uri':util[_0xc4ee('0xe')](_0xc4ee('0x18'),_0x5c6b90[_0xc4ee('0x10')])});}}function request(_0xb5bc8d){logger[_0xc4ee('0x19')](_0xc4ee('0x1a'),JSON[_0xc4ee('0x1b')](_0xb5bc8d));return rp(_[_0xc4ee('0x5')](_0xb5bc8d,{'method':'GET','headers':headers,'json':!![]}));}function getAuth(_0x223bdb){var _0x40c793;if(_0x223bdb[_0xc4ee('0x1c')]===_0xc4ee('0x1d')){_0x40c793=util[_0xc4ee('0xe')](_0xc4ee('0x1e'),_0x223bdb[_0xc4ee('0x1f')],_0x223bdb[_0xc4ee('0x20')]);}else if(_0x223bdb['authType']==='token'){_0x40c793=util[_0xc4ee('0xe')](_0xc4ee('0x21'),_0x223bdb['username'],_0x223bdb[_0xc4ee('0x22')]);}return util['format'](_0xc4ee('0x23'),new Buffer(_0x40c793)[_0xc4ee('0x24')](_0xc4ee('0x25')));}function getEndUser(_0x11e174,_0xef5ba2,_0x2ab12e){logger[_0xc4ee('0xc')](_0xc4ee('0x26'),_0x2ab12e);return request({'uri':util[_0xc4ee('0xe')]('%s/customers/search',_0x11e174[_0xc4ee('0x10')]),'qs':{'phone':_0x2ab12e}})['then'](function(_0x3d28b3){if(_0x3d28b3[_0xc4ee('0x11')]){logger[_0xc4ee('0xc')](_0xc4ee('0x27'));return _0x3d28b3[_0xc4ee('0x13')][_0xc4ee('0x14')][0x0];}else{logger['info'](_0xc4ee('0x28'));return request({'uri':util[_0xc4ee('0xe')]('%s/customers',_0x11e174[_0xc4ee('0x10')]),'method':_0xc4ee('0x29'),'body':{'first_name':_0xef5ba2,'title':_0xef5ba2,'phone_numbers':[{'type':_0xc4ee('0x2a'),'value':_0x2ab12e}]}});}});}function getTags(_0x11baa3,_0x3c0d9b){var _0x1a732c=[];if(_0x11baa3&&_0x11baa3[_0xc4ee('0x2b')]>0x0){_0x1a732c=_['map'](_0x11baa3,_0x3c0d9b);}return _0x1a732c;}function getCustomFields(_0xe8ea01,_0x3b42f0){var _0x3d9ee7=[];var _0x4bee06={'custom_fields':{}};if(_0xe8ea01[_0xc4ee('0x2b')]>0x0){_[_0xc4ee('0x2c')](_0xe8ea01,function(_0xd307e5){if(_[_0xc4ee('0x2d')]([_0xc4ee('0x2e'),_0xc4ee('0x2f')],_0xd307e5[_0xc4ee('0x30')])&&_0xd307e5[_0xc4ee('0x31')]&&!_0xd307e5[_0xc4ee('0x32')]){_0x4bee06[_0xd307e5[_0xc4ee('0x31')][_0xc4ee('0x33')]()]=_0xd307e5[_0xc4ee('0x34')]['toString']();}else if(_[_0xc4ee('0x2d')]([_0xc4ee('0x2e'),_0xc4ee('0x2f')],_0xd307e5['type'])&&_0xd307e5[_0xc4ee('0x35')]&&_0xd307e5['customField']){_0x4bee06['custom_fields'][_0xd307e5[_0xc4ee('0x35')]]=_0xd307e5['content'][_0xc4ee('0x24')]();}else if(_0xd307e5[_0xc4ee('0x30')]===_0xc4ee('0x36')&&_0xd307e5[_0xc4ee('0x37')]&&_0xd307e5[_0xc4ee('0x35')]&&_0xd307e5[_0xc4ee('0x32')]){_0x3b42f0[_0xd307e5[_0xc4ee('0x37')]]&&(_0x4bee06['custom_fields'][_0xd307e5[_0xc4ee('0x35')]]=_0x3b42f0[_0xd307e5['variableName']][_0xc4ee('0x24')]());}else if(_0xd307e5[_0xc4ee('0x30')]==='customVariable'&&_0xd307e5['Variable']&&_0xd307e5[_0xc4ee('0x38')]['name']&&_0xd307e5['idField']&&_0xd307e5[_0xc4ee('0x32')]){_0x3b42f0[_0xd307e5[_0xc4ee('0x38')][_0xc4ee('0x39')][_0xc4ee('0x33')]()]&&(_0x4bee06[_0xc4ee('0x3a')][_0xd307e5[_0xc4ee('0x35')]]=_0x3b42f0[_0xd307e5[_0xc4ee('0x38')][_0xc4ee('0x39')][_0xc4ee('0x33')]()]['toString']());}});}if(_0x4bee06[_0xc4ee('0x3b')]){_0x4bee06[_0xc4ee('0x3b')]=Number(_0x4bee06['priority']);}return _0x4bee06;}function getTicket(_0x53bb54,_0x17e111,_0x2d9fa0,_0x2ffd21,_0xd89697){logger[_0xc4ee('0xc')](_0xc4ee('0x3c'));var _0x28bf30=_[_0xc4ee('0x3d')]({'subject':intUtil[_0xc4ee('0x3e')](_0x2ffd21[_0xc4ee('0x3f')],_0xd89697,'\x20'),'type':'phone','status':_0xc4ee('0x40'),'labels':[_0xc4ee('0x41'),'Motion',_0xc4ee('0x42')]['concat'](getTags(_0x2ffd21['Tags'],_0xc4ee('0x39'))),'description':intUtil[_0xc4ee('0x3e')](_0x2ffd21[_0xc4ee('0x43')],_0xd89697,'\x0a'),'_links':{'assigned_user':{'href':util[_0xc4ee('0xe')](_0xc4ee('0x44'),_0x17e111['id']),'class':_0xc4ee('0x45')}},'message':{'direction':'in','body':intUtil[_0xc4ee('0x3e')](_0x2ffd21['Descriptions'],_0xd89697,'\x0a')}},getCustomFields(_0x2ffd21[_0xc4ee('0x46')],_0xd89697));return request({'uri':util[_0xc4ee('0xe')](_0xc4ee('0x47'),_0x53bb54[_0xc4ee('0x10')],_0x2d9fa0['id']),'method':_0xc4ee('0x29'),'body':_0x28bf30});}exports[_0xc4ee('0x48')]=function(_0x327168,_0x4c7c10,_0x10fd96,_0x748b72,_0x339f87,_0x23dd94){var _0x22deed,_0x3bb4e1;_0x23dd94[_0xc4ee('0x10')]=intUtil['stripTrailingSlash'](_0x23dd94[_0xc4ee('0x10')]);_0x23dd94[_0xc4ee('0x49')]=intUtil[_0xc4ee('0x4a')](_0x23dd94[_0xc4ee('0x49')]);if(_0x339f87&&_0x339f87[_0xc4ee('0x4b')]){logger[_0xc4ee('0xc')](_0xc4ee('0x4c'),_0xc4ee('0x4d'));_0x4c7c10[_0xc4ee('0x4e')]=util[_0xc4ee('0xe')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x23dd94[_0xc4ee('0x49')],_0x4c7c10[_0xc4ee('0x4f')],md5(_0x4c7c10[_0xc4ee('0x4f')]));}else{_0x4c7c10[_0xc4ee('0x4e')]='';}headers[_0xc4ee('0x50')]=getAuth(_0x23dd94);return getUser(_0x23dd94,_0x748b72[_0xc4ee('0x51')])[_0xc4ee('0x15')](function(_0x5ee337){_0x22deed=_0x5ee337;logger[_0xc4ee('0xc')]('The\x20User\x20ID\x20is:',_0x22deed['id']);return getEndUser(_0x23dd94,_0x4c7c10[_0xc4ee('0x52')],_0x4c7c10[_0xc4ee('0x53')]);})[_0xc4ee('0x15')](function(_0xb06027){_0x3bb4e1=_0xb06027;logger['info'](_0xc4ee('0x54'),_0x3bb4e1['id']);return getTicket(_0x23dd94,_0x22deed,_0x3bb4e1,_0x10fd96,_0x4c7c10);})[_0xc4ee('0x15')](function(_0x5cb8f0){if(_0x5cb8f0){logger[_0xc4ee('0xc')]('Ticket\x20created!');logger[_0xc4ee('0xc')](_0xc4ee('0x55'),_0x5cb8f0['id']);switch(_0x23dd94[_0xc4ee('0x30')]){case _0xc4ee('0x56'):logger[_0xc4ee('0xc')](_0xc4ee('0x4c'),_0xc4ee('0x57'));emit(util[_0xc4ee('0xe')]('user:%s',_0x748b72[_0xc4ee('0x39')]),'trigger:desk:display',{'recordId':_0x5cb8f0['id']});break;case'newTab':logger[_0xc4ee('0xc')](_0xc4ee('0x4c'),_0xc4ee('0x58'));emit(util[_0xc4ee('0xe')](_0xc4ee('0x59'),_0x748b72[_0xc4ee('0x39')]),'trigger:browser:url',{'uri':util[_0xc4ee('0xe')](_0xc4ee('0x5a'),_0x5cb8f0['id'])});break;default:logger['error'](_0xc4ee('0x4c'),'Desk\x20account\x20type\x20not\x20recognized');}}})['catch'](function(_0x226d92){console['error'](_0x226d92);logger['error']('[QUEUE]',JSON['stringify'](_0x226d92));});};exports[_0xc4ee('0x5b')]=function(_0x25bf7c,_0x30c944,_0x48c3b9,_0x20a2d9,_0x1bd128,_0x449069,_0x8598fc){var _0xcb021c,_0x2ace65;_0x449069[_0xc4ee('0x10')]=intUtil[_0xc4ee('0x4a')](_0x449069[_0xc4ee('0x10')]);_0x449069['serverUrl']=intUtil[_0xc4ee('0x4a')](_0x449069[_0xc4ee('0x49')]);if(_0x8598fc&&_0x8598fc['recordingFormat']&&_0x8598fc['recordingFormat']!==_0xc4ee('0x5c')){logger[_0xc4ee('0xc')](_0xc4ee('0x5d'),'Recording\x20is\x20enabled!');_0x30c944['recordingURL']=util[_0xc4ee('0xe')](_0xc4ee('0x5e'),_0x449069[_0xc4ee('0x49')],_0x30c944['uniqueid'],md5(_0x30c944['uniqueid']));}headers['Authorization']=getAuth(_0x449069);return getUser(_0x449069,_0x20a2d9[_0xc4ee('0x51')])[_0xc4ee('0x15')](function(_0x55a7fd){_0xcb021c=_0x55a7fd;logger[_0xc4ee('0xc')](_0xc4ee('0x5f'),_0xcb021c['id']);return getEndUser(_0x449069,_0x30c944[_0xc4ee('0x60')],_0x30c944[_0xc4ee('0x61')]);})[_0xc4ee('0x15')](function(_0x4746a3){_0x2ace65=_0x4746a3;logger[_0xc4ee('0xc')](_0xc4ee('0x54'),_0x2ace65['id']);return getTicket(_0x449069,_0xcb021c,_0x2ace65,_0x48c3b9,_0x30c944);})[_0xc4ee('0x15')](function(_0x4e8d26){if(_0x4e8d26){logger['info']('Ticket\x20created!');logger['info'](_0xc4ee('0x55'),_0x4e8d26['id']);switch(_0x449069[_0xc4ee('0x30')]){case _0xc4ee('0x56'):logger['info']('[QUEUE]','Displaying\x20ticket\x20to\x20agent...');emit(util[_0xc4ee('0xe')](_0xc4ee('0x59'),_0x20a2d9[_0xc4ee('0x39')]),'trigger:desk:display',{'recordId':_0x4e8d26['id']});break;case _0xc4ee('0x62'):logger[_0xc4ee('0xc')]('[QUEUE]','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0xc4ee('0xe')](_0xc4ee('0x59'),_0x20a2d9[_0xc4ee('0x39')]),'trigger:browser:url',{'uri':util['format'](_0xc4ee('0x63'),_0x449069[_0xc4ee('0x10')],_0x4e8d26['id'])});break;default:logger[_0xc4ee('0x64')](_0xc4ee('0x5d'),_0xc4ee('0x65'));}}})[_0xc4ee('0x66')](function(_0x38fa0c){logger[_0xc4ee('0x64')](_0xc4ee('0x5d'),JSON[_0xc4ee('0x1b')](_0x38fa0c));});};exports[_0xc4ee('0x67')]=function(_0x27f4a1,_0x35e293,_0x5d1851,_0x36702f,_0x366398,_0x4bdfeb){var _0x336601,_0x4963c7;_0x4bdfeb[_0xc4ee('0x10')]=intUtil[_0xc4ee('0x4a')](_0x4bdfeb[_0xc4ee('0x10')]);_0x4bdfeb[_0xc4ee('0x49')]=intUtil[_0xc4ee('0x4a')](_0x4bdfeb[_0xc4ee('0x49')]);if(_0x366398&&_0x366398['monitor_format']){logger[_0xc4ee('0xc')]('['+_0x35e293[_0xc4ee('0x68')][_0xc4ee('0x69')]()+']',_0xc4ee('0x4d'));_0x35e293['recordingURL']=util[_0xc4ee('0xe')](_0xc4ee('0x5e'),_0x4bdfeb[_0xc4ee('0x49')],_0x35e293[_0xc4ee('0x4f')],md5(_0x35e293[_0xc4ee('0x4f')]));}else{_0x35e293[_0xc4ee('0x4e')]='';}headers['Authorization']=getAuth(_0x4bdfeb);return getUser(_0x4bdfeb)['then'](function(_0x1f1a9e){_0x336601=_0x1f1a9e;logger[_0xc4ee('0xc')](_0xc4ee('0x5f'),_0x336601['id']);return getEndUser(_0x4bdfeb,_0x35e293[_0xc4ee('0x52')],_0x35e293['calleridnum']);})[_0xc4ee('0x15')](function(_0x19f5be){_0x4963c7=_0x19f5be;logger[_0xc4ee('0xc')]('The\x20Enduser\x20ID\x20is:',_0x4963c7['id']);return getTicket(_0x4bdfeb,_0x336601,_0x4963c7,_0x5d1851,_0x35e293);})[_0xc4ee('0x15')](function(_0x374ec4){if(_0x374ec4){logger['info']('Ticket\x20created!');logger['info']('The\x20Ticket\x20ID\x20is:',_0x374ec4['id']);}})[_0xc4ee('0x66')](function(_0x727782){logger[_0xc4ee('0x64')]('['+_0x35e293['lastevent']['toUpperCase']()+']',JSON[_0xc4ee('0x1b')](_0x727782));});};
\ 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(_0x255d5b,_0x4f6f35){var _0x3e141a=function(_0x249ee2){while(--_0x249ee2){_0x255d5b['push'](_0x255d5b['shift']());}};_0x3e141a(++_0x4f6f35);}(_0x5fc3,0xa8));var _0x35fc=function(_0x3ec122,_0x55150a){_0x3ec122=_0x3ec122-0x0;var _0x4ecf41=_0x5fc3[_0x3ec122];return _0x4ecf41;};'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