4864521f83a6b066a0f0479561e8fa14d6ec45ae
[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 _0x9256=['OpenchannelQueues','showOpenchannelQueues','smsQueues','showSmsQueues','SmsQueues','whatsappQueues','WhatsappQueues','faxQueues','showFaxQueues','FaxQueues','faxAccounts','FaxAccounts','chatQueuesWaitingInteractions','mailQueuesWaitingInteractions','MailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','OpenchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','SmsQueuesWaitingInteractions','whatsappQueuesWaitingInteractions','WhatsappQueuesWaitingInteractions','faxQueuesWaitingInteractions','FaxQueuesWaitingInteractions','queueNotify','capitalize','chat','Website','Account','Queue','\x20Queue\x20not\x20found','Message','findOne','Interaction','\x20Message\x20not\x20found','update','queue','From','TransferReport','create','Start','queueTransferTimeout','*,*,*,*','agentNotify','channel','Channel\x20field\x20is\x20mandatory','messageId','MessageId','InteractionId','agentTransferTimeout','bluebird','../../mysqldb','jayson/promise','client','http','request','then','error','code','message','json','sendStatus','stack','name','status','send','isNil','rows','voiceChannels','VoiceChannels','catch','VoiceChannelMixMonitor','merge','query','voiceChannelStopMixMonitor','VoiceChannelStopMixMonitor','params','showVoiceQueues','VoiceQueues','voiceQueuesChannels','voiceQueuesChannel','VoiceQueuesChannelHangup','voiceQueuesChannelRedirect','VoiceQueuesChannelRedirect','outbound','Outbound','outboundChannels','OutboundChannels','body','interaction','user','hasOwnProperty','MemberReport','findAll','length','format','updateAttributes','findOrCreate','INTERACTION','interface','SIP/%s','YYYY-MM-DD\x20HH:mm:ss','agent','internal','AgentCapacity','capacity','telephones','Telephones','trunks','campaigns','Campaigns','chatQueues','ChatQueues','showChatQueues','mailQueues','MailQueues','showMailQueues','mailAccounts','MailAccounts','openchannelQueues'];(function(_0x1abd5e,_0x607b87){var _0x39194a=function(_0x4cfff4){while(--_0x4cfff4){_0x1abd5e['push'](_0x1abd5e['shift']());}};_0x39194a(++_0x607b87);}(_0x9256,0xa8));var _0x6925=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x9256[_0x321bb2];return _0x9c12ed;};'use strict';var BPromise=require(_0x6925('0x0'));var moment=require('moment');var _=require('lodash');var util=require('util');var db=require(_0x6925('0x1'))['db'];var logger=require('../../config/logger')('api');var jayson=require(_0x6925('0x2'));var amiClient=jayson[_0x6925('0x3')]['http']({'port':0x232a});var mailClient=jayson[_0x6925('0x3')]['http']({'port':0x232b});var routingClient=jayson[_0x6925('0x3')][_0x6925('0x4')]({'port':0x232c});function respondWithRpcPromise(_0x5b82da,_0x508677,_0x1be7f5){return new BPromise(function(_0x592f35,_0x473bd6){var _0x40c127=_0x1be7f5?_0x1be7f5:amiClient;return _0x40c127[_0x6925('0x5')](_0x5b82da,_0x508677)[_0x6925('0x6')](function(_0x261172){if(_0x261172[_0x6925('0x7')]){if(_0x261172[_0x6925('0x7')][_0x6925('0x8')]===0x1f4){return _0x473bd6(_0x261172['error'][_0x6925('0x9')]);}return _0x592f35(_0x261172[_0x6925('0x7')][_0x6925('0x9')]);}else{_0x592f35(_0x261172['result']);}})['catch'](function(_0xd6fc25){_0x473bd6(_0xd6fc25);});});}function respondWithResult(_0x4ff240,_0x34d638){_0x34d638=_0x34d638||0xc8;return function(_0xc2279){if(_0xc2279){return _0x4ff240['status'](_0x34d638)[_0x6925('0xa')](_0xc2279);}return _0x4ff240[_0x6925('0xb')](0x194);};}function handleError(_0x55783d,_0x51963a){_0x51963a=_0x51963a||0x1f4;return function(_0x20382e){logger[_0x6925('0x7')](_0x20382e[_0x6925('0xc')]);if(_0x20382e[_0x6925('0xd')]){delete _0x20382e['name'];}_0x55783d[_0x6925('0xe')](_0x51963a)[_0x6925('0xf')](_0x20382e);};}function findById(_0x24c33e){return function(_0x23a535){if(!_[_0x6925('0x10')](_0x24c33e)&&!_[_0x6925('0x10')](_0x23a535)&&!_['isNil'](_0x23a535[_0x6925('0x11')])){return _['find'](_0x23a535['rows'],function(_0x2f5a6f){return _0x2f5a6f['id']==_0x24c33e;});}return null;};}exports[_0x6925('0x12')]=function(_0x3dcab7,_0x1ba39b){return respondWithRpcPromise(_0x6925('0x13'),_0x3dcab7['query'])[_0x6925('0x6')](respondWithResult(_0x1ba39b,null))[_0x6925('0x14')](handleError(_0x1ba39b,null));};exports['voiceChannelMixMonitor']=function(_0x37ee53,_0x2c0480){return respondWithRpcPromise(_0x6925('0x15'),_[_0x6925('0x16')](_0x37ee53[_0x6925('0x17')],_0x37ee53['params']))[_0x6925('0x6')](respondWithResult(_0x2c0480,null))[_0x6925('0x14')](handleError(_0x2c0480,null));};exports[_0x6925('0x18')]=function(_0x2fc475,_0x432f52){return respondWithRpcPromise(_0x6925('0x19'),_[_0x6925('0x16')](_0x2fc475[_0x6925('0x17')],_0x2fc475[_0x6925('0x1a')]))[_0x6925('0x6')](respondWithResult(_0x432f52,null))[_0x6925('0x14')](handleError(_0x432f52,null));};exports['voiceQueues']=function(_0x190f36,_0x528a2b){return respondWithRpcPromise('VoiceQueues',_0x190f36[_0x6925('0x17')])['then'](respondWithResult(_0x528a2b,null))[_0x6925('0x14')](handleError(_0x528a2b,null));};exports[_0x6925('0x1b')]=function(_0x53fcf1,_0x5a8b08){return respondWithRpcPromise(_0x6925('0x1c'),_0x53fcf1[_0x6925('0x17')])['then'](findById(_0x53fcf1[_0x6925('0x1a')]['id']))[_0x6925('0x6')](respondWithResult(_0x5a8b08,null))[_0x6925('0x14')](handleError(_0x5a8b08,null));};exports['voiceQueuesPreview']=function(_0x41524b,_0x40cfc5){return respondWithRpcPromise('VoiceQueuesPreview',_[_0x6925('0x16')](_0x41524b[_0x6925('0x17')],_0x41524b[_0x6925('0x1a')]))['then'](respondWithResult(_0x40cfc5,null))[_0x6925('0x14')](handleError(_0x40cfc5,null));};exports[_0x6925('0x1d')]=function(_0x4e8414,_0xb17526){return respondWithRpcPromise('VoiceQueuesChannels',_0x4e8414[_0x6925('0x17')])[_0x6925('0x6')](respondWithResult(_0xb17526,null))[_0x6925('0x14')](handleError(_0xb17526,null));};exports[_0x6925('0x1e')]=function(_0x115f1e,_0xb21117){return respondWithRpcPromise('VoiceQueuesChannel',_[_0x6925('0x16')](_0x115f1e[_0x6925('0x17')],_0x115f1e['params']))[_0x6925('0x6')](respondWithResult(_0xb21117,null))[_0x6925('0x14')](handleError(_0xb21117,null));};exports['voiceQueuesChannelHangup']=function(_0x4b370a,_0x1356be){return respondWithRpcPromise(_0x6925('0x1f'),_[_0x6925('0x16')](_0x4b370a[_0x6925('0x17')],_0x4b370a[_0x6925('0x1a')]))[_0x6925('0x6')](respondWithResult(_0x1356be,null))['catch'](handleError(_0x1356be,null));};exports[_0x6925('0x20')]=function(_0x33340c,_0x145fe2){return respondWithRpcPromise(_0x6925('0x21'),_[_0x6925('0x16')](_0x33340c[_0x6925('0x17')],_0x33340c['params']))[_0x6925('0x6')](respondWithResult(_0x145fe2,null))[_0x6925('0x14')](handleError(_0x145fe2,null));};exports[_0x6925('0x22')]=function(_0xb7d486,_0x1fefc2){return respondWithRpcPromise(_0x6925('0x23'),_0xb7d486[_0x6925('0x17')])['then'](respondWithResult(_0x1fefc2,null))[_0x6925('0x14')](handleError(_0x1fefc2,null));};exports[_0x6925('0x24')]=function(_0x2b8e20,_0x8b8d0c){return respondWithRpcPromise(_0x6925('0x25'),_0x2b8e20[_0x6925('0x17')])[_0x6925('0x6')](respondWithResult(_0x8b8d0c,null))[_0x6925('0x14')](handleError(_0x8b8d0c,null));};exports['agents']=function(_0x15f585,_0xea72c6){var _0x618a99;return respondWithRpcPromise('Agents',_0x15f585[_0x6925('0x17')])[_0x6925('0x6')](function(_0x10c483){_0x618a99=_0x10c483;return respondWithRpcPromise('Agents',_0x15f585['query'],routingClient);})[_0x6925('0x6')](function(_0xc327cc){return _[_0x6925('0x16')]({},_0xc327cc,_0x618a99);})[_0x6925('0x6')](respondWithResult(_0xea72c6,null))[_0x6925('0x14')](handleError(_0xea72c6,null));};exports['agentCapacity']=function(_0x52d7de,_0x1e7096){if(_0x52d7de[_0x6925('0x26')]&&_0x52d7de[_0x6925('0x26')][_0x6925('0x27')]&&_0x52d7de[_0x6925('0x28')]&&_0x52d7de[_0x6925('0x28')][_0x6925('0xd')]){for(var _0x1d8d4a in _0x52d7de['body'][_0x6925('0x27')]){if(_0x52d7de[_0x6925('0x26')][_0x6925('0x27')][_0x6925('0x29')](_0x1d8d4a)){db[_0x6925('0x2a')][_0x6925('0x2b')]({'where':{'channel':_0x1d8d4a,'membername':_0x52d7de['user']['name'],'type':'INTERACTION','exitAt':null,'uniqueid':_0x52d7de[_0x6925('0x26')]['interaction'][_0x1d8d4a]&&_0x52d7de['body']['interaction'][_0x1d8d4a][_0x6925('0x2c')]?{'$notIn':_0x52d7de[_0x6925('0x26')][_0x6925('0x27')][_0x1d8d4a]}:{'$ne':null}}})[_0x6925('0x6')](function(_0x4f55dd){var _0x5be7f3=moment()[_0x6925('0x2d')]('YYYY-MM-DD\x20HH:mm:ss');for(var _0x1d7ada=0x0,_0x3ef597=_0x4f55dd[_0x6925('0x2c')];_0x1d7ada<_0x3ef597;_0x1d7ada+=0x1){_0x4f55dd[_0x1d7ada][_0x6925('0x2e')]({'exitAt':_0x5be7f3});}});for(var _0x313830=0x0;_0x313830<_0x52d7de[_0x6925('0x26')][_0x6925('0x27')][_0x1d8d4a]['length'];_0x313830+=0x1){db[_0x6925('0x2a')][_0x6925('0x2f')]({'where':{'channel':_0x1d8d4a,'membername':_0x52d7de['user']['name'],'type':_0x6925('0x30'),'uniqueid':_0x52d7de[_0x6925('0x26')][_0x6925('0x27')][_0x1d8d4a][_0x313830],'exitAt':null},'defaults':{'channel':_0x1d8d4a,'membername':_0x52d7de[_0x6925('0x28')]['name'],'interface':_[_0x6925('0x10')](_0x52d7de[_0x6925('0x28')][_0x6925('0x31')])?util[_0x6925('0x2d')](_0x6925('0x32'),_0x52d7de['user'][_0x6925('0xd')]):_0x52d7de[_0x6925('0x28')][_0x6925('0x31')],'type':_0x6925('0x30'),'enterAt':moment()[_0x6925('0x2d')](_0x6925('0x33')),'role':_0x6925('0x34'),'internal':_0x52d7de[_0x6925('0x28')][_0x6925('0x35')],'uniqueid':_0x52d7de[_0x6925('0x26')]['interaction'][_0x1d8d4a][_0x313830]}});}}}}return respondWithRpcPromise(_0x6925('0x36'),{'id':_0x52d7de['params']['id'],'capacity':_0x52d7de[_0x6925('0x26')][_0x6925('0x37')]},routingClient)['then'](respondWithResult(_0x1e7096,null))[_0x6925('0x14')](handleError(_0x1e7096,null));};exports[_0x6925('0x38')]=function(_0x2c1389,_0x56a58e){return respondWithRpcPromise(_0x6925('0x39'),_0x2c1389['query'])[_0x6925('0x6')](respondWithResult(_0x56a58e,null))['catch'](handleError(_0x56a58e,null));};exports[_0x6925('0x3a')]=function(_0x6be525,_0x2c027a){return respondWithRpcPromise('Trunks',_0x6be525[_0x6925('0x17')])[_0x6925('0x6')](respondWithResult(_0x2c027a,null))[_0x6925('0x14')](handleError(_0x2c027a,null));};exports[_0x6925('0x3b')]=function(_0x5616ee,_0x14690b){return respondWithRpcPromise(_0x6925('0x3c'),_0x5616ee[_0x6925('0x17')])[_0x6925('0x6')](respondWithResult(_0x14690b,null))[_0x6925('0x14')](handleError(_0x14690b,null));};exports[_0x6925('0x3d')]=function(_0x1b6c9a,_0x1a11ef){return respondWithRpcPromise(_0x6925('0x3e'),_0x1b6c9a['query'],routingClient)[_0x6925('0x6')](respondWithResult(_0x1a11ef,null))[_0x6925('0x14')](handleError(_0x1a11ef,null));};exports[_0x6925('0x3f')]=function(_0x597147,_0x1612ff){return respondWithRpcPromise(_0x6925('0x3e'),_0x597147[_0x6925('0x17')],routingClient)[_0x6925('0x6')](findById(_0x597147[_0x6925('0x1a')]['id']))[_0x6925('0x6')](respondWithResult(_0x1612ff,null))['catch'](handleError(_0x1612ff,null));};exports[_0x6925('0x40')]=function(_0x2310cc,_0x59f6ee){return respondWithRpcPromise(_0x6925('0x41'),_0x2310cc['query'],routingClient)[_0x6925('0x6')](respondWithResult(_0x59f6ee,null))[_0x6925('0x14')](handleError(_0x59f6ee,null));};exports[_0x6925('0x42')]=function(_0x40e43a,_0x32572e){return respondWithRpcPromise(_0x6925('0x41'),_0x40e43a['query'],routingClient)[_0x6925('0x6')](findById(_0x40e43a[_0x6925('0x1a')]['id']))[_0x6925('0x6')](respondWithResult(_0x32572e,null))['catch'](handleError(_0x32572e,null));};exports[_0x6925('0x43')]=function(_0x4a98af,_0x1b4869){return respondWithRpcPromise(_0x6925('0x44'),_0x4a98af[_0x6925('0x17')],mailClient)['then'](respondWithResult(_0x1b4869,null))['catch'](handleError(_0x1b4869,null));};exports[_0x6925('0x45')]=function(_0x2608d8,_0x49229e){return respondWithRpcPromise(_0x6925('0x46'),_0x2608d8[_0x6925('0x17')],routingClient)[_0x6925('0x6')](respondWithResult(_0x49229e,null))[_0x6925('0x14')](handleError(_0x49229e,null));};exports[_0x6925('0x47')]=function(_0x537f4e,_0x2e0806){return respondWithRpcPromise(_0x6925('0x46'),_0x537f4e['query'],routingClient)[_0x6925('0x6')](findById(_0x537f4e[_0x6925('0x1a')]['id']))[_0x6925('0x6')](respondWithResult(_0x2e0806,null))['catch'](handleError(_0x2e0806,null));};exports[_0x6925('0x48')]=function(_0x30a8fa,_0x3ea102){return respondWithRpcPromise('SmsQueues',_0x30a8fa['query'],routingClient)['then'](respondWithResult(_0x3ea102,null))[_0x6925('0x14')](handleError(_0x3ea102,null));};exports[_0x6925('0x49')]=function(_0x58f6c6,_0x17b86d){return respondWithRpcPromise(_0x6925('0x4a'),_0x58f6c6[_0x6925('0x17')],routingClient)[_0x6925('0x6')](findById(_0x58f6c6[_0x6925('0x1a')]['id']))[_0x6925('0x6')](respondWithResult(_0x17b86d,null))['catch'](handleError(_0x17b86d,null));};exports[_0x6925('0x4b')]=function(_0x224513,_0x393fcf){return respondWithRpcPromise(_0x6925('0x4c'),_0x224513[_0x6925('0x17')],routingClient)[_0x6925('0x6')](respondWithResult(_0x393fcf,null))[_0x6925('0x14')](handleError(_0x393fcf,null));};exports['showWhatsappQueues']=function(_0x3d300f,_0x435135){return respondWithRpcPromise(_0x6925('0x4c'),_0x3d300f[_0x6925('0x17')],routingClient)[_0x6925('0x6')](findById(_0x3d300f['params']['id']))[_0x6925('0x6')](respondWithResult(_0x435135,null))[_0x6925('0x14')](handleError(_0x435135,null));};exports[_0x6925('0x4d')]=function(_0x5c0cd1,_0x570da9){return respondWithRpcPromise('FaxQueues',_0x5c0cd1[_0x6925('0x17')],routingClient)[_0x6925('0x6')](respondWithResult(_0x570da9,null))[_0x6925('0x14')](handleError(_0x570da9,null));};exports[_0x6925('0x4e')]=function(_0x20c31f,_0x160f7e){return respondWithRpcPromise(_0x6925('0x4f'),_0x20c31f[_0x6925('0x17')],routingClient)['then'](findById(_0x20c31f[_0x6925('0x1a')]['id']))['then'](respondWithResult(_0x160f7e,null))[_0x6925('0x14')](handleError(_0x160f7e,null));};exports[_0x6925('0x50')]=function(_0x13c4a7,_0x5c5da8){return respondWithRpcPromise(_0x6925('0x51'),_0x13c4a7[_0x6925('0x17')])[_0x6925('0x6')](respondWithResult(_0x5c5da8,null))[_0x6925('0x14')](handleError(_0x5c5da8,null));};exports[_0x6925('0x52')]=function(_0x4de220,_0x1a7ce7){return respondWithRpcPromise('ChatQueuesWaitingInteractions',_0x4de220[_0x6925('0x17')],routingClient)[_0x6925('0x6')](respondWithResult(_0x1a7ce7,null))['catch'](handleError(_0x1a7ce7,null));};exports[_0x6925('0x53')]=function(_0x172fe1,_0x5489ce){return respondWithRpcPromise(_0x6925('0x54'),_0x172fe1[_0x6925('0x17')],routingClient)[_0x6925('0x6')](respondWithResult(_0x5489ce,null))[_0x6925('0x14')](handleError(_0x5489ce,null));};exports[_0x6925('0x55')]=function(_0x2456f3,_0x537c72){return respondWithRpcPromise(_0x6925('0x56'),_0x2456f3[_0x6925('0x17')],routingClient)[_0x6925('0x6')](respondWithResult(_0x537c72,null))['catch'](handleError(_0x537c72,null));};exports[_0x6925('0x57')]=function(_0x22e2c4,_0x2b451e){return respondWithRpcPromise(_0x6925('0x58'),_0x22e2c4[_0x6925('0x17')],routingClient)['then'](respondWithResult(_0x2b451e,null))[_0x6925('0x14')](handleError(_0x2b451e,null));};exports[_0x6925('0x59')]=function(_0x4d8b28,_0x317025){return respondWithRpcPromise(_0x6925('0x5a'),_0x4d8b28[_0x6925('0x17')],routingClient)[_0x6925('0x6')](respondWithResult(_0x317025,null))['catch'](handleError(_0x317025,null));};exports[_0x6925('0x5b')]=function(_0x5a4f74,_0x76f4c){return respondWithRpcPromise(_0x6925('0x5c'),_0x5a4f74[_0x6925('0x17')],routingClient)[_0x6925('0x6')](respondWithResult(_0x76f4c,null))['catch'](handleError(_0x76f4c,null));};exports[_0x6925('0x5d')]=function(_0x47eb37){return function(_0x1c0f76,_0x553a2a){var _0x19bdc6,_0x569dd6;var _0x2c1fd8=_[_0x6925('0x5e')](_0x47eb37);var _0x8e3660=_0x47eb37===_0x6925('0x5f')?_0x6925('0x60'):_0x6925('0x61');return db[_0x2c1fd8+_0x6925('0x62')]['findOne']({'raw':!![],'where':{'id':_0x1c0f76['params']['id']}})[_0x6925('0x6')](function(_0x5c51ca){if(_[_0x6925('0x10')](_0x5c51ca)){throw new Error(_0x2c1fd8+_0x6925('0x63'));}_0x19bdc6=_0x5c51ca;return db[_0x2c1fd8+_0x6925('0x64')][_0x6925('0x65')]({'where':{'id':_0x1c0f76[_0x6925('0x26')]['messageId']},'include':[{'model':db[_0x2c1fd8+_0x6925('0x66')],'as':_0x6925('0x66')},{'model':db[_0x2c1fd8+_0x8e3660],'as':_0x6925('0x61')}]});})[_0x6925('0x6')](function(_0x2b5279){if(_[_0x6925('0x10')](_0x2b5279)){throw new Error(_0x2c1fd8+_0x6925('0x67'));}_0x569dd6=_0x2b5279;return _0x2b5279[_0x6925('0x68')]({'read':0x0,'readAt':null,'UserId':null});})['then'](function(){var _0x55d38a={'uniqueid':_0x47eb37+'.'+_0x569dd6['id']+'.'+_0x569dd6[_0x6925('0x66')]['id'],'FromUserId':_0x1c0f76['user']['id'],'type':_0x6925('0x69')};_0x55d38a[_0x2c1fd8+'MessageId']=_0x569dd6['id'];_0x55d38a[_0x2c1fd8+'InteractionId']=_0x569dd6[_0x6925('0x66')]['id'];_0x55d38a[_0x6925('0x6a')+_0x2c1fd8+_0x8e3660+'Id']=_0x569dd6['Account']['id'];_0x55d38a['To'+_0x2c1fd8+'QueueId']=_0x19bdc6['id'];return db[_0x2c1fd8+_0x6925('0x6b')][_0x6925('0x6c')](_0x55d38a);})['then'](function(){return respondWithRpcPromise(_0x6925('0x6d'),{'channel':_0x47eb37,'interaction':_0x569dd6[_0x6925('0x66')],'message':_0x569dd6,'account':_0x569dd6['Account'],'applications':[{'id':0x0,'priority':0x1,'app':_0x6925('0x69'),'appdata':_0x19bdc6[_0x6925('0xd')]+','+(_0x569dd6[_0x6925('0x61')][_0x6925('0x6e')]||0x12c),'interval':_0x6925('0x6f')}]},routingClient);})[_0x6925('0x6')](respondWithResult(_0x553a2a,null))[_0x6925('0x14')](handleError(_0x553a2a,null));};};exports[_0x6925('0x70')]=function(_0x61697a,_0x3580e3){var _0x46a635,_0x5ee645;if(_[_0x6925('0x10')](_0x61697a[_0x6925('0x26')][_0x6925('0x71')])){throw new Error(_0x6925('0x72'));}var _0xb8fc80=_0x61697a['body'][_0x6925('0x71')];var _0x2a198a=_[_0x6925('0x5e')](_0xb8fc80);var _0x3192e2=_0xb8fc80===_0x6925('0x5f')?_0x6925('0x60'):_0x6925('0x61');return db['User'][_0x6925('0x65')]({'raw':!![],'where':{'id':_0x61697a['params']['id'],'role':_0x6925('0x34')}})[_0x6925('0x6')](function(_0x4a7a20){if(_[_0x6925('0x10')](_0x4a7a20)){throw new Error('Agent\x20not\x20found');}_0x46a635=_0x4a7a20;return db[_0x2a198a+_0x6925('0x64')][_0x6925('0x65')]({'where':{'id':_0x61697a[_0x6925('0x26')][_0x6925('0x73')]},'include':[{'model':db[_0x2a198a+_0x6925('0x66')],'as':_0x6925('0x66')},{'model':db[_0x2a198a+_0x3192e2],'as':_0x6925('0x61')}]});})['then'](function(_0x24020e){if(_['isNil'](_0x24020e)){throw new Error(_0x2a198a+_0x6925('0x67'));}_0x5ee645=_0x24020e;return _0x24020e[_0x6925('0x68')]({'read':0x0,'readAt':null,'UserId':null});})[_0x6925('0x6')](function(){var _0x84c567={'uniqueid':_0xb8fc80+'.'+_0x5ee645['id']+'.'+_0x5ee645[_0x6925('0x66')]['id'],'FromUserId':_0x61697a[_0x6925('0x28')]['id'],'type':_0x6925('0x69'),'ToUserId':_0x46a635['id']};_0x84c567[_0x2a198a+_0x6925('0x74')]=_0x5ee645['id'];_0x84c567[_0x2a198a+_0x6925('0x75')]=_0x5ee645[_0x6925('0x66')]['id'];_0x84c567[_0x6925('0x6a')+_0x2a198a+_0x3192e2+'Id']=_0x5ee645[_0x6925('0x61')]['id'];return db[_0x2a198a+_0x6925('0x6b')][_0x6925('0x6c')](_0x84c567);})[_0x6925('0x6')](function(){return respondWithRpcPromise(_0x6925('0x6d'),{'channel':_0xb8fc80,'interaction':_0x5ee645['Interaction'],'message':_0x5ee645,'account':_0x5ee645[_0x6925('0x61')],'applications':[{'id':0x0,'priority':0x1,'app':_0x6925('0x34'),'appdata':_0x46a635[_0x6925('0xd')]+','+(_0x5ee645['Account'][_0x6925('0x76')]||0x12c),'interval':_0x6925('0x6f')}]},routingClient);})[_0x6925('0x6')](respondWithResult(_0x3580e3,null))[_0x6925('0x14')](handleError(_0x3580e3,null));};