a1e794e96794cca2328ccc3a9ceb8636718d0223
[motion2.git] / server / api / rpc / rpc.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x6aba=['voiceQueuesChannel','VoiceQueuesChannel','voiceQueuesChannelHangup','VoiceQueuesChannelHangup','voiceQueuesChannelRedirect','outbound','Outbound','outboundChannels','OutboundChannels','agents','Agents','agentCapacity','body','interaction','user','hasOwnProperty','MemberReport','format','YYYY-MM-DD\x20HH:mm:ss','INTERACTION','interface','agent','internal','capacity','telephones','Trunks','campaigns','Campaigns','chatQueues','ChatQueues','showChatQueues','mailQueues','MailQueues','showMailQueues','mailAccounts','MailAccounts','OpenchannelQueues','showSmsQueues','SmsQueues','faxQueues','FaxQueues','showFaxQueues','faxAccounts','FaxAccounts','chatQueuesWaitingInteractions','ChatQueuesWaitingInteractions','mailQueuesWaitingInteractions','MailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','OpenchannelQueuesWaitingInteractions','faxQueuesWaitingInteractions','FaxQueuesWaitingInteractions','queueNotify','capitalize','chat','Website','Account','Message','findOne','Interaction','\x20Message\x20not\x20found','queue','InteractionId','QueueId','TransferReport','create','Start','queueTransferTimeout','*,*,*,*','channel','User','Agent\x20not\x20found','messageId','update','From','agentTransferTimeout','bluebird','moment','lodash','../../config/logger','api','client','http','request','then','error','code','message','result','catch','status','json','stack','name','isNil','rows','find','VoiceChannels','query','voiceChannelMixMonitor','VoiceChannelMixMonitor','voiceChannelStopMixMonitor','VoiceChannelStopMixMonitor','merge','voiceQueues','VoiceQueues','params','voiceQueuesPreview','VoiceQueuesPreview'];(function(_0x107b88,_0x14cfa5){var _0x2f53b0=function(_0x58b896){while(--_0x58b896){_0x107b88['push'](_0x107b88['shift']());}};_0x2f53b0(++_0x14cfa5);}(_0x6aba,0x193));var _0xa6ab=function(_0x4a66bb,_0x3e6a2d){_0x4a66bb=_0x4a66bb-0x0;var _0x39548e=_0x6aba[_0x4a66bb];return _0x39548e;};'use strict';var BPromise=require(_0xa6ab('0x0'));var moment=require(_0xa6ab('0x1'));var _=require(_0xa6ab('0x2'));var util=require('util');var db=require('../../mysqldb')['db'];var logger=require(_0xa6ab('0x3'))(_0xa6ab('0x4'));var jayson=require('jayson/promise');var amiClient=jayson[_0xa6ab('0x5')][_0xa6ab('0x6')]({'port':0x232a});var mailClient=jayson[_0xa6ab('0x5')][_0xa6ab('0x6')]({'port':0x232b});var routingClient=jayson[_0xa6ab('0x5')][_0xa6ab('0x6')]({'port':0x232c});function respondWithRpcPromise(_0x5a0b0a,_0x28b728,_0xb0db57){return new BPromise(function(_0x35417c,_0x412753){var _0x3e93c5=_0xb0db57?_0xb0db57:amiClient;return _0x3e93c5[_0xa6ab('0x7')](_0x5a0b0a,_0x28b728)[_0xa6ab('0x8')](function(_0x50763c){if(_0x50763c[_0xa6ab('0x9')]){if(_0x50763c['error'][_0xa6ab('0xa')]===0x1f4){return _0x412753(_0x50763c['error']['message']);}return _0x35417c(_0x50763c['error'][_0xa6ab('0xb')]);}else{_0x35417c(_0x50763c[_0xa6ab('0xc')]);}})[_0xa6ab('0xd')](function(_0x101481){_0x412753(_0x101481);});});}function respondWithResult(_0x2b3c96,_0x3734d1){_0x3734d1=_0x3734d1||0xc8;return function(_0x5087f3){if(_0x5087f3){return _0x2b3c96[_0xa6ab('0xe')](_0x3734d1)[_0xa6ab('0xf')](_0x5087f3);}return _0x2b3c96['sendStatus'](0x194);};}function handleError(_0x4cc285,_0xafea44){_0xafea44=_0xafea44||0x1f4;return function(_0x249a5b){logger[_0xa6ab('0x9')](_0x249a5b[_0xa6ab('0x10')]);if(_0x249a5b[_0xa6ab('0x11')]){delete _0x249a5b[_0xa6ab('0x11')];}_0x4cc285[_0xa6ab('0xe')](_0xafea44)['send'](_0x249a5b);};}function findById(_0x54d1c1){return function(_0x269ec4){if(!_[_0xa6ab('0x12')](_0x54d1c1)&&!_['isNil'](_0x269ec4)&&!_[_0xa6ab('0x12')](_0x269ec4[_0xa6ab('0x13')])){return _[_0xa6ab('0x14')](_0x269ec4[_0xa6ab('0x13')],function(_0x32ddd8){return _0x32ddd8['id']==_0x54d1c1;});}return null;};}exports['voiceChannels']=function(_0x2b7831,_0x4d4e1c){return respondWithRpcPromise(_0xa6ab('0x15'),_0x2b7831[_0xa6ab('0x16')])[_0xa6ab('0x8')](respondWithResult(_0x4d4e1c,null))[_0xa6ab('0xd')](handleError(_0x4d4e1c,null));};exports[_0xa6ab('0x17')]=function(_0x389ff1,_0x10e2bd){return respondWithRpcPromise(_0xa6ab('0x18'),_['merge'](_0x389ff1[_0xa6ab('0x16')],_0x389ff1['params']))[_0xa6ab('0x8')](respondWithResult(_0x10e2bd,null))[_0xa6ab('0xd')](handleError(_0x10e2bd,null));};exports[_0xa6ab('0x19')]=function(_0x3c3f67,_0x1b432b){return respondWithRpcPromise(_0xa6ab('0x1a'),_[_0xa6ab('0x1b')](_0x3c3f67[_0xa6ab('0x16')],_0x3c3f67['params']))[_0xa6ab('0x8')](respondWithResult(_0x1b432b,null))[_0xa6ab('0xd')](handleError(_0x1b432b,null));};exports[_0xa6ab('0x1c')]=function(_0x2cfed5,_0x2c21ee){return respondWithRpcPromise(_0xa6ab('0x1d'),_0x2cfed5[_0xa6ab('0x16')])[_0xa6ab('0x8')](respondWithResult(_0x2c21ee,null))[_0xa6ab('0xd')](handleError(_0x2c21ee,null));};exports['showVoiceQueues']=function(_0x194a86,_0x5cf165){return respondWithRpcPromise(_0xa6ab('0x1d'),_0x194a86[_0xa6ab('0x16')])[_0xa6ab('0x8')](findById(_0x194a86[_0xa6ab('0x1e')]['id']))['then'](respondWithResult(_0x5cf165,null))[_0xa6ab('0xd')](handleError(_0x5cf165,null));};exports[_0xa6ab('0x1f')]=function(_0x5e94ca,_0x3cf1ee){return respondWithRpcPromise(_0xa6ab('0x20'),_[_0xa6ab('0x1b')](_0x5e94ca[_0xa6ab('0x16')],_0x5e94ca[_0xa6ab('0x1e')]))['then'](respondWithResult(_0x3cf1ee,null))[_0xa6ab('0xd')](handleError(_0x3cf1ee,null));};exports['voiceQueuesChannels']=function(_0xfd092c,_0xb81ab1){return respondWithRpcPromise('VoiceQueuesChannels',_0xfd092c[_0xa6ab('0x16')])[_0xa6ab('0x8')](respondWithResult(_0xb81ab1,null))[_0xa6ab('0xd')](handleError(_0xb81ab1,null));};exports[_0xa6ab('0x21')]=function(_0x5224fc,_0x144559){return respondWithRpcPromise(_0xa6ab('0x22'),_[_0xa6ab('0x1b')](_0x5224fc[_0xa6ab('0x16')],_0x5224fc['params']))[_0xa6ab('0x8')](respondWithResult(_0x144559,null))[_0xa6ab('0xd')](handleError(_0x144559,null));};exports[_0xa6ab('0x23')]=function(_0x2f885a,_0x608d34){return respondWithRpcPromise(_0xa6ab('0x24'),_[_0xa6ab('0x1b')](_0x2f885a['query'],_0x2f885a['params']))['then'](respondWithResult(_0x608d34,null))[_0xa6ab('0xd')](handleError(_0x608d34,null));};exports[_0xa6ab('0x25')]=function(_0x409df3,_0x8d054b){return respondWithRpcPromise('VoiceQueuesChannelRedirect',_[_0xa6ab('0x1b')](_0x409df3[_0xa6ab('0x16')],_0x409df3[_0xa6ab('0x1e')]))[_0xa6ab('0x8')](respondWithResult(_0x8d054b,null))[_0xa6ab('0xd')](handleError(_0x8d054b,null));};exports[_0xa6ab('0x26')]=function(_0x325fc6,_0x281ae9){return respondWithRpcPromise(_0xa6ab('0x27'),_0x325fc6['query'])['then'](respondWithResult(_0x281ae9,null))[_0xa6ab('0xd')](handleError(_0x281ae9,null));};exports[_0xa6ab('0x28')]=function(_0x596797,_0x555081){return respondWithRpcPromise(_0xa6ab('0x29'),_0x596797['query'])[_0xa6ab('0x8')](respondWithResult(_0x555081,null))['catch'](handleError(_0x555081,null));};exports[_0xa6ab('0x2a')]=function(_0xd0e0bd,_0x2edabd){var _0x297e5e;return respondWithRpcPromise(_0xa6ab('0x2b'),_0xd0e0bd[_0xa6ab('0x16')])[_0xa6ab('0x8')](function(_0x56007b){_0x297e5e=_0x56007b;return respondWithRpcPromise(_0xa6ab('0x2b'),_0xd0e0bd[_0xa6ab('0x16')],routingClient);})['then'](function(_0x4c6063){return _['merge']({},_0x4c6063,_0x297e5e);})[_0xa6ab('0x8')](respondWithResult(_0x2edabd,null))[_0xa6ab('0xd')](handleError(_0x2edabd,null));};exports[_0xa6ab('0x2c')]=function(_0x37a6ef,_0x322e4c){if(_0x37a6ef[_0xa6ab('0x2d')]&&_0x37a6ef[_0xa6ab('0x2d')][_0xa6ab('0x2e')]&&_0x37a6ef[_0xa6ab('0x2f')]&&_0x37a6ef[_0xa6ab('0x2f')][_0xa6ab('0x11')]){for(var _0xe73e39 in _0x37a6ef[_0xa6ab('0x2d')][_0xa6ab('0x2e')]){if(_0x37a6ef['body'][_0xa6ab('0x2e')][_0xa6ab('0x30')](_0xe73e39)){db[_0xa6ab('0x31')]['findAll']({'where':{'channel':_0xe73e39,'membername':_0x37a6ef[_0xa6ab('0x2f')][_0xa6ab('0x11')],'type':'INTERACTION','exitAt':null,'uniqueid':_0x37a6ef['body'][_0xa6ab('0x2e')][_0xe73e39]&&_0x37a6ef[_0xa6ab('0x2d')]['interaction'][_0xe73e39]['length']?{'$notIn':_0x37a6ef[_0xa6ab('0x2d')][_0xa6ab('0x2e')][_0xe73e39]}:{'$ne':null}}})[_0xa6ab('0x8')](function(_0x3d10aa){var _0x3f4bad=moment()[_0xa6ab('0x32')](_0xa6ab('0x33'));for(var _0x3bd51a=0x0,_0x1303fe=_0x3d10aa['length'];_0x3bd51a<_0x1303fe;_0x3bd51a+=0x1){_0x3d10aa[_0x3bd51a]['updateAttributes']({'exitAt':_0x3f4bad});}});for(var _0x27f341=0x0;_0x27f341<_0x37a6ef[_0xa6ab('0x2d')]['interaction'][_0xe73e39]['length'];_0x27f341+=0x1){db['MemberReport']['findOrCreate']({'where':{'channel':_0xe73e39,'membername':_0x37a6ef['user']['name'],'type':_0xa6ab('0x34'),'uniqueid':_0x37a6ef[_0xa6ab('0x2d')][_0xa6ab('0x2e')][_0xe73e39][_0x27f341],'exitAt':null},'defaults':{'channel':_0xe73e39,'membername':_0x37a6ef[_0xa6ab('0x2f')]['name'],'interface':_[_0xa6ab('0x12')](_0x37a6ef[_0xa6ab('0x2f')][_0xa6ab('0x35')])?util[_0xa6ab('0x32')]('SIP/%s',_0x37a6ef[_0xa6ab('0x2f')]['name']):_0x37a6ef[_0xa6ab('0x2f')][_0xa6ab('0x35')],'type':_0xa6ab('0x34'),'enterAt':moment()['format'](_0xa6ab('0x33')),'role':_0xa6ab('0x36'),'internal':_0x37a6ef['user'][_0xa6ab('0x37')],'uniqueid':_0x37a6ef['body'][_0xa6ab('0x2e')][_0xe73e39][_0x27f341]}});}}}}return respondWithRpcPromise('AgentCapacity',{'id':_0x37a6ef['params']['id'],'capacity':_0x37a6ef[_0xa6ab('0x2d')][_0xa6ab('0x38')]},routingClient)[_0xa6ab('0x8')](respondWithResult(_0x322e4c,null))[_0xa6ab('0xd')](handleError(_0x322e4c,null));};exports[_0xa6ab('0x39')]=function(_0x4635b8,_0x29bbbd){return respondWithRpcPromise('Telephones',_0x4635b8[_0xa6ab('0x16')])[_0xa6ab('0x8')](respondWithResult(_0x29bbbd,null))[_0xa6ab('0xd')](handleError(_0x29bbbd,null));};exports['trunks']=function(_0x11937d,_0x56d6c6){return respondWithRpcPromise(_0xa6ab('0x3a'),_0x11937d[_0xa6ab('0x16')])[_0xa6ab('0x8')](respondWithResult(_0x56d6c6,null))[_0xa6ab('0xd')](handleError(_0x56d6c6,null));};exports[_0xa6ab('0x3b')]=function(_0x31a00a,_0x54f9a3){return respondWithRpcPromise(_0xa6ab('0x3c'),_0x31a00a[_0xa6ab('0x16')])[_0xa6ab('0x8')](respondWithResult(_0x54f9a3,null))[_0xa6ab('0xd')](handleError(_0x54f9a3,null));};exports[_0xa6ab('0x3d')]=function(_0x57c3ea,_0x5d1329){return respondWithRpcPromise(_0xa6ab('0x3e'),_0x57c3ea[_0xa6ab('0x16')],routingClient)[_0xa6ab('0x8')](respondWithResult(_0x5d1329,null))[_0xa6ab('0xd')](handleError(_0x5d1329,null));};exports[_0xa6ab('0x3f')]=function(_0x3f2116,_0x16a606){return respondWithRpcPromise(_0xa6ab('0x3e'),_0x3f2116[_0xa6ab('0x16')],routingClient)[_0xa6ab('0x8')](findById(_0x3f2116['params']['id']))[_0xa6ab('0x8')](respondWithResult(_0x16a606,null))[_0xa6ab('0xd')](handleError(_0x16a606,null));};exports[_0xa6ab('0x40')]=function(_0x21ce5a,_0x36f7fb){return respondWithRpcPromise(_0xa6ab('0x41'),_0x21ce5a['query'],routingClient)[_0xa6ab('0x8')](respondWithResult(_0x36f7fb,null))['catch'](handleError(_0x36f7fb,null));};exports[_0xa6ab('0x42')]=function(_0x410eb0,_0x2d940b){return respondWithRpcPromise(_0xa6ab('0x41'),_0x410eb0[_0xa6ab('0x16')],routingClient)[_0xa6ab('0x8')](findById(_0x410eb0[_0xa6ab('0x1e')]['id']))[_0xa6ab('0x8')](respondWithResult(_0x2d940b,null))[_0xa6ab('0xd')](handleError(_0x2d940b,null));};exports[_0xa6ab('0x43')]=function(_0x1af989,_0xf92865){return respondWithRpcPromise(_0xa6ab('0x44'),_0x1af989[_0xa6ab('0x16')],mailClient)[_0xa6ab('0x8')](respondWithResult(_0xf92865,null))[_0xa6ab('0xd')](handleError(_0xf92865,null));};exports['openchannelQueues']=function(_0x1b03fe,_0x43ecc5){return respondWithRpcPromise(_0xa6ab('0x45'),_0x1b03fe[_0xa6ab('0x16')],routingClient)[_0xa6ab('0x8')](respondWithResult(_0x43ecc5,null))[_0xa6ab('0xd')](handleError(_0x43ecc5,null));};exports['showOpenchannelQueues']=function(_0xfc2229,_0x3509c8){return respondWithRpcPromise('OpenchannelQueues',_0xfc2229[_0xa6ab('0x16')],routingClient)['then'](findById(_0xfc2229['params']['id']))['then'](respondWithResult(_0x3509c8,null))[_0xa6ab('0xd')](handleError(_0x3509c8,null));};exports['smsQueues']=function(_0x3418c5,_0x4ebc28){return respondWithRpcPromise('SmsQueues',_0x3418c5[_0xa6ab('0x16')],routingClient)[_0xa6ab('0x8')](respondWithResult(_0x4ebc28,null))[_0xa6ab('0xd')](handleError(_0x4ebc28,null));};exports[_0xa6ab('0x46')]=function(_0xedfb7e,_0x41f32d){return respondWithRpcPromise(_0xa6ab('0x47'),_0xedfb7e[_0xa6ab('0x16')],routingClient)[_0xa6ab('0x8')](findById(_0xedfb7e['params']['id']))['then'](respondWithResult(_0x41f32d,null))['catch'](handleError(_0x41f32d,null));};exports[_0xa6ab('0x48')]=function(_0xd78363,_0x477937){return respondWithRpcPromise(_0xa6ab('0x49'),_0xd78363['query'],routingClient)['then'](respondWithResult(_0x477937,null))['catch'](handleError(_0x477937,null));};exports[_0xa6ab('0x4a')]=function(_0x52a3b5,_0x111a26){return respondWithRpcPromise(_0xa6ab('0x49'),_0x52a3b5[_0xa6ab('0x16')],routingClient)[_0xa6ab('0x8')](findById(_0x52a3b5[_0xa6ab('0x1e')]['id']))[_0xa6ab('0x8')](respondWithResult(_0x111a26,null))[_0xa6ab('0xd')](handleError(_0x111a26,null));};exports[_0xa6ab('0x4b')]=function(_0x524c0e,_0x5c5661){return respondWithRpcPromise(_0xa6ab('0x4c'),_0x524c0e['query'])[_0xa6ab('0x8')](respondWithResult(_0x5c5661,null))['catch'](handleError(_0x5c5661,null));};exports[_0xa6ab('0x4d')]=function(_0x5efe59,_0x57b430){return respondWithRpcPromise(_0xa6ab('0x4e'),_0x5efe59['query'],routingClient)['then'](respondWithResult(_0x57b430,null))['catch'](handleError(_0x57b430,null));};exports[_0xa6ab('0x4f')]=function(_0x505776,_0x4802df){return respondWithRpcPromise(_0xa6ab('0x50'),_0x505776[_0xa6ab('0x16')],routingClient)[_0xa6ab('0x8')](respondWithResult(_0x4802df,null))[_0xa6ab('0xd')](handleError(_0x4802df,null));};exports[_0xa6ab('0x51')]=function(_0x281ebd,_0x3f6d99){return respondWithRpcPromise(_0xa6ab('0x52'),_0x281ebd[_0xa6ab('0x16')],routingClient)[_0xa6ab('0x8')](respondWithResult(_0x3f6d99,null))[_0xa6ab('0xd')](handleError(_0x3f6d99,null));};exports['smsQueuesWaitingInteractions']=function(_0x4defc0,_0x601ccf){return respondWithRpcPromise('SmsQueuesWaitingInteractions',_0x4defc0['query'],routingClient)[_0xa6ab('0x8')](respondWithResult(_0x601ccf,null))[_0xa6ab('0xd')](handleError(_0x601ccf,null));};exports[_0xa6ab('0x53')]=function(_0x453096,_0x158fdf){return respondWithRpcPromise(_0xa6ab('0x54'),_0x453096['query'],routingClient)[_0xa6ab('0x8')](respondWithResult(_0x158fdf,null))[_0xa6ab('0xd')](handleError(_0x158fdf,null));};exports[_0xa6ab('0x55')]=function(_0x1b8498){return function(_0x2dea01,_0x1d7da2){var _0x472b1a,_0x222b8e;var _0x28a61a=_[_0xa6ab('0x56')](_0x1b8498);var _0x1861fc=_0x1b8498===_0xa6ab('0x57')?_0xa6ab('0x58'):_0xa6ab('0x59');return db[_0x28a61a+'Queue']['findOne']({'raw':!![],'where':{'id':_0x2dea01[_0xa6ab('0x1e')]['id']}})[_0xa6ab('0x8')](function(_0x4b213d){if(_[_0xa6ab('0x12')](_0x4b213d)){throw new Error(_0x28a61a+'\x20Queue\x20not\x20found');}_0x472b1a=_0x4b213d;return db[_0x28a61a+_0xa6ab('0x5a')][_0xa6ab('0x5b')]({'where':{'id':_0x2dea01['body']['messageId']},'include':[{'model':db[_0x28a61a+_0xa6ab('0x5c')],'as':_0xa6ab('0x5c')},{'model':db[_0x28a61a+_0x1861fc],'as':'Account'}]});})[_0xa6ab('0x8')](function(_0x2ab251){if(_['isNil'](_0x2ab251)){throw new Error(_0x28a61a+_0xa6ab('0x5d'));}_0x222b8e=_0x2ab251;return _0x2ab251['update']({'read':0x0,'readAt':null,'UserId':null});})[_0xa6ab('0x8')](function(){var _0x3548ee={'uniqueid':_0x1b8498+'.'+_0x222b8e['id']+'.'+_0x222b8e[_0xa6ab('0x5c')]['id'],'FromUserId':_0x2dea01[_0xa6ab('0x2f')]['id'],'type':_0xa6ab('0x5e')};_0x3548ee[_0x28a61a+'MessageId']=_0x222b8e['id'];_0x3548ee[_0x28a61a+_0xa6ab('0x5f')]=_0x222b8e['Interaction']['id'];_0x3548ee['From'+_0x28a61a+_0x1861fc+'Id']=_0x222b8e['Account']['id'];_0x3548ee['To'+_0x28a61a+_0xa6ab('0x60')]=_0x472b1a['id'];return db[_0x28a61a+_0xa6ab('0x61')][_0xa6ab('0x62')](_0x3548ee);})[_0xa6ab('0x8')](function(){return respondWithRpcPromise(_0xa6ab('0x63'),{'channel':_0x1b8498,'interaction':_0x222b8e['Interaction'],'message':_0x222b8e,'account':_0x222b8e['Account'],'applications':[{'id':0x0,'priority':0x1,'app':_0xa6ab('0x5e'),'appdata':_0x472b1a[_0xa6ab('0x11')]+','+(_0x222b8e['Account'][_0xa6ab('0x64')]||0x12c),'interval':_0xa6ab('0x65')}]},routingClient);})[_0xa6ab('0x8')](respondWithResult(_0x1d7da2,null))[_0xa6ab('0xd')](handleError(_0x1d7da2,null));};};exports['agentNotify']=function(_0x19d51c,_0x4dad76){var _0x5070b3,_0x36965f;if(_['isNil'](_0x19d51c['body'][_0xa6ab('0x66')])){throw new Error('Channel\x20field\x20is\x20mandatory');}var _0x59e07e=_0x19d51c[_0xa6ab('0x2d')][_0xa6ab('0x66')];var _0x5c20e6=_[_0xa6ab('0x56')](_0x59e07e);var _0x3b6417=_0x59e07e===_0xa6ab('0x57')?_0xa6ab('0x58'):_0xa6ab('0x59');return db[_0xa6ab('0x67')][_0xa6ab('0x5b')]({'raw':!![],'where':{'id':_0x19d51c[_0xa6ab('0x1e')]['id'],'role':_0xa6ab('0x36')}})[_0xa6ab('0x8')](function(_0x196abd){if(_['isNil'](_0x196abd)){throw new Error(_0xa6ab('0x68'));}_0x5070b3=_0x196abd;return db[_0x5c20e6+_0xa6ab('0x5a')][_0xa6ab('0x5b')]({'where':{'id':_0x19d51c[_0xa6ab('0x2d')][_0xa6ab('0x69')]},'include':[{'model':db[_0x5c20e6+_0xa6ab('0x5c')],'as':_0xa6ab('0x5c')},{'model':db[_0x5c20e6+_0x3b6417],'as':_0xa6ab('0x59')}]});})[_0xa6ab('0x8')](function(_0x5ac88e){if(_[_0xa6ab('0x12')](_0x5ac88e)){throw new Error(_0x5c20e6+'\x20Message\x20not\x20found');}_0x36965f=_0x5ac88e;return _0x5ac88e[_0xa6ab('0x6a')]({'read':0x0,'readAt':null,'UserId':null});})[_0xa6ab('0x8')](function(){var _0x5e48a0={'uniqueid':_0x59e07e+'.'+_0x36965f['id']+'.'+_0x36965f[_0xa6ab('0x5c')]['id'],'FromUserId':_0x19d51c['user']['id'],'type':_0xa6ab('0x5e'),'ToUserId':_0x5070b3['id']};_0x5e48a0[_0x5c20e6+'MessageId']=_0x36965f['id'];_0x5e48a0[_0x5c20e6+_0xa6ab('0x5f')]=_0x36965f[_0xa6ab('0x5c')]['id'];_0x5e48a0[_0xa6ab('0x6b')+_0x5c20e6+_0x3b6417+'Id']=_0x36965f[_0xa6ab('0x59')]['id'];return db[_0x5c20e6+_0xa6ab('0x61')]['create'](_0x5e48a0);})[_0xa6ab('0x8')](function(){return respondWithRpcPromise(_0xa6ab('0x63'),{'channel':_0x59e07e,'interaction':_0x36965f[_0xa6ab('0x5c')],'message':_0x36965f,'account':_0x36965f['Account'],'applications':[{'id':0x0,'priority':0x1,'app':_0xa6ab('0x36'),'appdata':_0x5070b3[_0xa6ab('0x11')]+','+(_0x36965f[_0xa6ab('0x59')][_0xa6ab('0x6c')]||0x12c),'interval':'*,*,*,*'}]},routingClient);})[_0xa6ab('0x8')](respondWithResult(_0x4dad76,null))[_0xa6ab('0xd')](handleError(_0x4dad76,null));};