Built motion from commit (unavailable).|2.4.4
[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 _0x2bad=['hasOwnProperty','MemberReport','findAll','INTERACTION','format','YYYY-MM-DD\x20HH:mm:ss','length','findOrCreate','isNil','interface','SIP/%s','agent','AgentCapacity','telephones','Telephones','campaigns','Campaigns','chatQueues','ChatQueues','showMailQueues','MailQueues','mailAccounts','MailAccounts','openchannelQueues','OpenchannelQueues','showOpenchannelQueues','smsQueues','SmsQueues','showSmsQueues','FaxQueues','showFaxQueues','faxAccounts','FaxAccounts','chatQueuesWaitingInteractions','ChatQueuesWaitingInteractions','mailQueuesWaitingInteractions','MailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','OpenchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','SmsQueuesWaitingInteractions','FaxQueuesWaitingInteractions','queueNotify','capitalize','chat','Website','Account','Queue','findOne','messageId','Interaction','\x20Message\x20not\x20found','update','InteractionId','From','QueueId','TransferReport','create','Start','queue','queueTransferTimeout','*,*,*,*','agentNotify','channel','Channel\x20field\x20is\x20mandatory','User','Message','agentTransferTimeout','bluebird','lodash','../../mysqldb','../../config/logger','jayson/promise','client','http','request','error','message','result','catch','stack','name','status','find','rows','voiceChannels','query','then','VoiceChannelMixMonitor','merge','params','voiceChannelStopMixMonitor','VoiceChannelStopMixMonitor','voiceQueues','showVoiceQueues','VoiceQueuesPreview','VoiceQueuesChannels','voiceQueuesChannel','VoiceQueuesChannel','voiceQueuesChannelRedirect','VoiceQueuesChannelRedirect','outbound','outboundChannels','OutboundChannels','Agents','agentCapacity','body','user','interaction'];(function(_0x39d544,_0x35c14f){var _0x5a5ff2=function(_0x2271fb){while(--_0x2271fb){_0x39d544['push'](_0x39d544['shift']());}};_0x5a5ff2(++_0x35c14f);}(_0x2bad,0x11e));var _0xd2ba=function(_0x290181,_0x46db3e){_0x290181=_0x290181-0x0;var _0x2dc9dc=_0x2bad[_0x290181];return _0x2dc9dc;};'use strict';var BPromise=require(_0xd2ba('0x0'));var moment=require('moment');var _=require(_0xd2ba('0x1'));var util=require('util');var db=require(_0xd2ba('0x2'))['db'];var logger=require(_0xd2ba('0x3'))('api');var jayson=require(_0xd2ba('0x4'));var amiClient=jayson[_0xd2ba('0x5')][_0xd2ba('0x6')]({'port':0x232a});var mailClient=jayson[_0xd2ba('0x5')][_0xd2ba('0x6')]({'port':0x232b});var routingClient=jayson[_0xd2ba('0x5')][_0xd2ba('0x6')]({'port':0x232c});function respondWithRpcPromise(_0x296b70,_0x506157,_0x15fb7b){return new BPromise(function(_0x553ecc,_0x4cb891){var _0x1da9fd=_0x15fb7b?_0x15fb7b:amiClient;return _0x1da9fd[_0xd2ba('0x7')](_0x296b70,_0x506157)['then'](function(_0x58d6d0){if(_0x58d6d0[_0xd2ba('0x8')]){if(_0x58d6d0['error']['code']===0x1f4){return _0x4cb891(_0x58d6d0['error'][_0xd2ba('0x9')]);}return _0x553ecc(_0x58d6d0[_0xd2ba('0x8')]['message']);}else{_0x553ecc(_0x58d6d0[_0xd2ba('0xa')]);}})[_0xd2ba('0xb')](function(_0x543e3f){_0x4cb891(_0x543e3f);});});}function respondWithResult(_0x5871a0,_0x4ba2cc){_0x4ba2cc=_0x4ba2cc||0xc8;return function(_0x58477c){if(_0x58477c){return _0x5871a0['status'](_0x4ba2cc)['json'](_0x58477c);}return _0x5871a0['sendStatus'](0x194);};}function handleError(_0x321f4d,_0x440b92){_0x440b92=_0x440b92||0x1f4;return function(_0x578cb){logger['error'](_0x578cb[_0xd2ba('0xc')]);if(_0x578cb[_0xd2ba('0xd')]){delete _0x578cb[_0xd2ba('0xd')];}_0x321f4d[_0xd2ba('0xe')](_0x440b92)['send'](_0x578cb);};}function findById(_0x51d639){return function(_0x74b1eb){if(!_['isNil'](_0x51d639)&&!_['isNil'](_0x74b1eb)&&!_['isNil'](_0x74b1eb['rows'])){return _[_0xd2ba('0xf')](_0x74b1eb[_0xd2ba('0x10')],function(_0x3aaded){return _0x3aaded['id']==_0x51d639;});}return null;};}exports[_0xd2ba('0x11')]=function(_0x1fe5cc,_0x12db17){return respondWithRpcPromise('VoiceChannels',_0x1fe5cc[_0xd2ba('0x12')])[_0xd2ba('0x13')](respondWithResult(_0x12db17,null))[_0xd2ba('0xb')](handleError(_0x12db17,null));};exports['voiceChannelMixMonitor']=function(_0x3336f6,_0x171313){return respondWithRpcPromise(_0xd2ba('0x14'),_[_0xd2ba('0x15')](_0x3336f6[_0xd2ba('0x12')],_0x3336f6[_0xd2ba('0x16')]))[_0xd2ba('0x13')](respondWithResult(_0x171313,null))[_0xd2ba('0xb')](handleError(_0x171313,null));};exports[_0xd2ba('0x17')]=function(_0x478377,_0xb3a608){return respondWithRpcPromise(_0xd2ba('0x18'),_[_0xd2ba('0x15')](_0x478377[_0xd2ba('0x12')],_0x478377[_0xd2ba('0x16')]))[_0xd2ba('0x13')](respondWithResult(_0xb3a608,null))['catch'](handleError(_0xb3a608,null));};exports[_0xd2ba('0x19')]=function(_0x5ec9c1,_0xa4c762){return respondWithRpcPromise('VoiceQueues',_0x5ec9c1[_0xd2ba('0x12')])['then'](respondWithResult(_0xa4c762,null))[_0xd2ba('0xb')](handleError(_0xa4c762,null));};exports[_0xd2ba('0x1a')]=function(_0x2b8725,_0x18e6d8){return respondWithRpcPromise('VoiceQueues',_0x2b8725['query'])[_0xd2ba('0x13')](findById(_0x2b8725[_0xd2ba('0x16')]['id']))[_0xd2ba('0x13')](respondWithResult(_0x18e6d8,null))[_0xd2ba('0xb')](handleError(_0x18e6d8,null));};exports['voiceQueuesPreview']=function(_0x2353f4,_0x3ebaad){return respondWithRpcPromise(_0xd2ba('0x1b'),_[_0xd2ba('0x15')](_0x2353f4[_0xd2ba('0x12')],_0x2353f4['params']))['then'](respondWithResult(_0x3ebaad,null))[_0xd2ba('0xb')](handleError(_0x3ebaad,null));};exports['voiceQueuesChannels']=function(_0x47e32a,_0x208670){return respondWithRpcPromise(_0xd2ba('0x1c'),_0x47e32a[_0xd2ba('0x12')])[_0xd2ba('0x13')](respondWithResult(_0x208670,null))[_0xd2ba('0xb')](handleError(_0x208670,null));};exports[_0xd2ba('0x1d')]=function(_0x230502,_0x2fda36){return respondWithRpcPromise(_0xd2ba('0x1e'),_['merge'](_0x230502[_0xd2ba('0x12')],_0x230502[_0xd2ba('0x16')]))[_0xd2ba('0x13')](respondWithResult(_0x2fda36,null))[_0xd2ba('0xb')](handleError(_0x2fda36,null));};exports['voiceQueuesChannelHangup']=function(_0x1611b2,_0x9433e8){return respondWithRpcPromise('VoiceQueuesChannelHangup',_[_0xd2ba('0x15')](_0x1611b2['query'],_0x1611b2['params']))[_0xd2ba('0x13')](respondWithResult(_0x9433e8,null))[_0xd2ba('0xb')](handleError(_0x9433e8,null));};exports[_0xd2ba('0x1f')]=function(_0x3e957c,_0x1b8414){return respondWithRpcPromise(_0xd2ba('0x20'),_['merge'](_0x3e957c[_0xd2ba('0x12')],_0x3e957c[_0xd2ba('0x16')]))[_0xd2ba('0x13')](respondWithResult(_0x1b8414,null))[_0xd2ba('0xb')](handleError(_0x1b8414,null));};exports[_0xd2ba('0x21')]=function(_0x2ddb7f,_0x53b807){return respondWithRpcPromise('Outbound',_0x2ddb7f['query'])['then'](respondWithResult(_0x53b807,null))['catch'](handleError(_0x53b807,null));};exports[_0xd2ba('0x22')]=function(_0x52ce2e,_0x15a421){return respondWithRpcPromise(_0xd2ba('0x23'),_0x52ce2e[_0xd2ba('0x12')])['then'](respondWithResult(_0x15a421,null))[_0xd2ba('0xb')](handleError(_0x15a421,null));};exports['agents']=function(_0x1745c2,_0x219de9){var _0x411b10;return respondWithRpcPromise(_0xd2ba('0x24'),_0x1745c2['query'])[_0xd2ba('0x13')](function(_0x5efb8f){_0x411b10=_0x5efb8f;return respondWithRpcPromise('Agents',_0x1745c2[_0xd2ba('0x12')],routingClient);})[_0xd2ba('0x13')](function(_0x25e031){return _[_0xd2ba('0x15')]({},_0x25e031,_0x411b10);})[_0xd2ba('0x13')](respondWithResult(_0x219de9,null))[_0xd2ba('0xb')](handleError(_0x219de9,null));};exports[_0xd2ba('0x25')]=function(_0x1ed6f8,_0x198e48){if(_0x1ed6f8[_0xd2ba('0x26')]&&_0x1ed6f8[_0xd2ba('0x26')]['interaction']&&_0x1ed6f8['user']&&_0x1ed6f8[_0xd2ba('0x27')][_0xd2ba('0xd')]){for(var _0x298125 in _0x1ed6f8[_0xd2ba('0x26')][_0xd2ba('0x28')]){if(_0x1ed6f8[_0xd2ba('0x26')][_0xd2ba('0x28')][_0xd2ba('0x29')](_0x298125)){db[_0xd2ba('0x2a')][_0xd2ba('0x2b')]({'where':{'channel':_0x298125,'membername':_0x1ed6f8['user'][_0xd2ba('0xd')],'type':_0xd2ba('0x2c'),'exitAt':null,'uniqueid':_0x1ed6f8[_0xd2ba('0x26')][_0xd2ba('0x28')][_0x298125]&&_0x1ed6f8[_0xd2ba('0x26')][_0xd2ba('0x28')][_0x298125]['length']?{'$notIn':_0x1ed6f8[_0xd2ba('0x26')][_0xd2ba('0x28')][_0x298125]}:{'$ne':null}}})[_0xd2ba('0x13')](function(_0x33cc42){var _0x1b11a4=moment()[_0xd2ba('0x2d')](_0xd2ba('0x2e'));for(var _0x16bb43=0x0,_0x21ca57=_0x33cc42[_0xd2ba('0x2f')];_0x16bb43<_0x21ca57;_0x16bb43+=0x1){_0x33cc42[_0x16bb43]['updateAttributes']({'exitAt':_0x1b11a4});}});for(var _0x82a335=0x0;_0x82a335<_0x1ed6f8[_0xd2ba('0x26')][_0xd2ba('0x28')][_0x298125]['length'];_0x82a335+=0x1){db[_0xd2ba('0x2a')][_0xd2ba('0x30')]({'where':{'channel':_0x298125,'membername':_0x1ed6f8['user'][_0xd2ba('0xd')],'type':_0xd2ba('0x2c'),'uniqueid':_0x1ed6f8['body'][_0xd2ba('0x28')][_0x298125][_0x82a335],'exitAt':null},'defaults':{'channel':_0x298125,'membername':_0x1ed6f8['user']['name'],'interface':_[_0xd2ba('0x31')](_0x1ed6f8[_0xd2ba('0x27')][_0xd2ba('0x32')])?util[_0xd2ba('0x2d')](_0xd2ba('0x33'),_0x1ed6f8[_0xd2ba('0x27')][_0xd2ba('0xd')]):_0x1ed6f8[_0xd2ba('0x27')]['interface'],'type':_0xd2ba('0x2c'),'enterAt':moment()[_0xd2ba('0x2d')](_0xd2ba('0x2e')),'role':_0xd2ba('0x34'),'internal':_0x1ed6f8[_0xd2ba('0x27')]['internal'],'uniqueid':_0x1ed6f8['body'][_0xd2ba('0x28')][_0x298125][_0x82a335]}});}}}}return respondWithRpcPromise(_0xd2ba('0x35'),{'id':_0x1ed6f8[_0xd2ba('0x16')]['id'],'capacity':_0x1ed6f8[_0xd2ba('0x26')]['capacity']},routingClient)['then'](respondWithResult(_0x198e48,null))[_0xd2ba('0xb')](handleError(_0x198e48,null));};exports[_0xd2ba('0x36')]=function(_0x3ff53c,_0x2a831b){return respondWithRpcPromise(_0xd2ba('0x37'),_0x3ff53c[_0xd2ba('0x12')])[_0xd2ba('0x13')](respondWithResult(_0x2a831b,null))['catch'](handleError(_0x2a831b,null));};exports['trunks']=function(_0x2a8812,_0x87b80d){return respondWithRpcPromise('Trunks',_0x2a8812[_0xd2ba('0x12')])[_0xd2ba('0x13')](respondWithResult(_0x87b80d,null))['catch'](handleError(_0x87b80d,null));};exports[_0xd2ba('0x38')]=function(_0x25e343,_0x382303){return respondWithRpcPromise(_0xd2ba('0x39'),_0x25e343[_0xd2ba('0x12')])['then'](respondWithResult(_0x382303,null))[_0xd2ba('0xb')](handleError(_0x382303,null));};exports[_0xd2ba('0x3a')]=function(_0x1b7af1,_0x4e6446){return respondWithRpcPromise(_0xd2ba('0x3b'),_0x1b7af1[_0xd2ba('0x12')],routingClient)['then'](respondWithResult(_0x4e6446,null))['catch'](handleError(_0x4e6446,null));};exports['showChatQueues']=function(_0x5b1e16,_0x5a646c){return respondWithRpcPromise(_0xd2ba('0x3b'),_0x5b1e16[_0xd2ba('0x12')],routingClient)[_0xd2ba('0x13')](findById(_0x5b1e16[_0xd2ba('0x16')]['id']))[_0xd2ba('0x13')](respondWithResult(_0x5a646c,null))['catch'](handleError(_0x5a646c,null));};exports['mailQueues']=function(_0x4ae02f,_0x27dcfa){return respondWithRpcPromise('MailQueues',_0x4ae02f['query'],routingClient)[_0xd2ba('0x13')](respondWithResult(_0x27dcfa,null))['catch'](handleError(_0x27dcfa,null));};exports[_0xd2ba('0x3c')]=function(_0x200a0e,_0x2d93d9){return respondWithRpcPromise(_0xd2ba('0x3d'),_0x200a0e['query'],routingClient)[_0xd2ba('0x13')](findById(_0x200a0e[_0xd2ba('0x16')]['id']))[_0xd2ba('0x13')](respondWithResult(_0x2d93d9,null))[_0xd2ba('0xb')](handleError(_0x2d93d9,null));};exports[_0xd2ba('0x3e')]=function(_0x812143,_0x55c69c){return respondWithRpcPromise(_0xd2ba('0x3f'),_0x812143[_0xd2ba('0x12')],mailClient)[_0xd2ba('0x13')](respondWithResult(_0x55c69c,null))[_0xd2ba('0xb')](handleError(_0x55c69c,null));};exports[_0xd2ba('0x40')]=function(_0x362f55,_0x3256af){return respondWithRpcPromise(_0xd2ba('0x41'),_0x362f55[_0xd2ba('0x12')],routingClient)['then'](respondWithResult(_0x3256af,null))[_0xd2ba('0xb')](handleError(_0x3256af,null));};exports[_0xd2ba('0x42')]=function(_0x57c231,_0xa9830d){return respondWithRpcPromise('OpenchannelQueues',_0x57c231['query'],routingClient)[_0xd2ba('0x13')](findById(_0x57c231[_0xd2ba('0x16')]['id']))[_0xd2ba('0x13')](respondWithResult(_0xa9830d,null))[_0xd2ba('0xb')](handleError(_0xa9830d,null));};exports[_0xd2ba('0x43')]=function(_0x26c958,_0x33e323){return respondWithRpcPromise(_0xd2ba('0x44'),_0x26c958[_0xd2ba('0x12')],routingClient)[_0xd2ba('0x13')](respondWithResult(_0x33e323,null))[_0xd2ba('0xb')](handleError(_0x33e323,null));};exports[_0xd2ba('0x45')]=function(_0x67ab52,_0x373564){return respondWithRpcPromise(_0xd2ba('0x44'),_0x67ab52[_0xd2ba('0x12')],routingClient)[_0xd2ba('0x13')](findById(_0x67ab52['params']['id']))[_0xd2ba('0x13')](respondWithResult(_0x373564,null))[_0xd2ba('0xb')](handleError(_0x373564,null));};exports['faxQueues']=function(_0x15ff8b,_0x54a56b){return respondWithRpcPromise(_0xd2ba('0x46'),_0x15ff8b[_0xd2ba('0x12')],routingClient)[_0xd2ba('0x13')](respondWithResult(_0x54a56b,null))[_0xd2ba('0xb')](handleError(_0x54a56b,null));};exports[_0xd2ba('0x47')]=function(_0x165ed1,_0x560808){return respondWithRpcPromise(_0xd2ba('0x46'),_0x165ed1[_0xd2ba('0x12')],routingClient)[_0xd2ba('0x13')](findById(_0x165ed1[_0xd2ba('0x16')]['id']))[_0xd2ba('0x13')](respondWithResult(_0x560808,null))[_0xd2ba('0xb')](handleError(_0x560808,null));};exports[_0xd2ba('0x48')]=function(_0x3818ca,_0x1be22b){return respondWithRpcPromise(_0xd2ba('0x49'),_0x3818ca[_0xd2ba('0x12')])[_0xd2ba('0x13')](respondWithResult(_0x1be22b,null))['catch'](handleError(_0x1be22b,null));};exports[_0xd2ba('0x4a')]=function(_0x4cdded,_0x3a9753){return respondWithRpcPromise(_0xd2ba('0x4b'),_0x4cdded[_0xd2ba('0x12')],routingClient)[_0xd2ba('0x13')](respondWithResult(_0x3a9753,null))[_0xd2ba('0xb')](handleError(_0x3a9753,null));};exports[_0xd2ba('0x4c')]=function(_0x2d2544,_0x1aee36){return respondWithRpcPromise(_0xd2ba('0x4d'),_0x2d2544[_0xd2ba('0x12')],routingClient)[_0xd2ba('0x13')](respondWithResult(_0x1aee36,null))[_0xd2ba('0xb')](handleError(_0x1aee36,null));};exports[_0xd2ba('0x4e')]=function(_0x186e8c,_0x51d689){return respondWithRpcPromise(_0xd2ba('0x4f'),_0x186e8c['query'],routingClient)[_0xd2ba('0x13')](respondWithResult(_0x51d689,null))[_0xd2ba('0xb')](handleError(_0x51d689,null));};exports[_0xd2ba('0x50')]=function(_0x42a1ab,_0x3c7a7c){return respondWithRpcPromise(_0xd2ba('0x51'),_0x42a1ab[_0xd2ba('0x12')],routingClient)[_0xd2ba('0x13')](respondWithResult(_0x3c7a7c,null))[_0xd2ba('0xb')](handleError(_0x3c7a7c,null));};exports['faxQueuesWaitingInteractions']=function(_0x26b14f,_0x406004){return respondWithRpcPromise(_0xd2ba('0x52'),_0x26b14f['query'],routingClient)['then'](respondWithResult(_0x406004,null))['catch'](handleError(_0x406004,null));};exports[_0xd2ba('0x53')]=function(_0x1b3795){return function(_0x4bf666,_0x4cf14c){var _0x33520e,_0xf61652;var _0x1fcd88=_[_0xd2ba('0x54')](_0x1b3795);var _0x222e75=_0x1b3795===_0xd2ba('0x55')?_0xd2ba('0x56'):_0xd2ba('0x57');return db[_0x1fcd88+_0xd2ba('0x58')]['findOne']({'raw':!![],'where':{'id':_0x4bf666[_0xd2ba('0x16')]['id']}})[_0xd2ba('0x13')](function(_0x5f2c82){if(_[_0xd2ba('0x31')](_0x5f2c82)){throw new Error(_0x1fcd88+'\x20Queue\x20not\x20found');}_0x33520e=_0x5f2c82;return db[_0x1fcd88+'Message'][_0xd2ba('0x59')]({'where':{'id':_0x4bf666[_0xd2ba('0x26')][_0xd2ba('0x5a')]},'include':[{'model':db[_0x1fcd88+_0xd2ba('0x5b')],'as':_0xd2ba('0x5b')},{'model':db[_0x1fcd88+_0x222e75],'as':_0xd2ba('0x57')}]});})['then'](function(_0x163a1f){if(_[_0xd2ba('0x31')](_0x163a1f)){throw new Error(_0x1fcd88+_0xd2ba('0x5c'));}_0xf61652=_0x163a1f;return _0x163a1f[_0xd2ba('0x5d')]({'read':0x0,'readAt':null,'UserId':null});})[_0xd2ba('0x13')](function(){var _0x370b98={'uniqueid':_0x1b3795+'.'+_0xf61652['id']+'.'+_0xf61652[_0xd2ba('0x5b')]['id'],'FromUserId':_0x4bf666['user']['id'],'type':'queue'};_0x370b98[_0x1fcd88+'MessageId']=_0xf61652['id'];_0x370b98[_0x1fcd88+_0xd2ba('0x5e')]=_0xf61652[_0xd2ba('0x5b')]['id'];_0x370b98[_0xd2ba('0x5f')+_0x1fcd88+_0x222e75+'Id']=_0xf61652[_0xd2ba('0x57')]['id'];_0x370b98['To'+_0x1fcd88+_0xd2ba('0x60')]=_0x33520e['id'];return db[_0x1fcd88+_0xd2ba('0x61')][_0xd2ba('0x62')](_0x370b98);})[_0xd2ba('0x13')](function(){return respondWithRpcPromise(_0xd2ba('0x63'),{'channel':_0x1b3795,'interaction':_0xf61652[_0xd2ba('0x5b')],'message':_0xf61652,'account':_0xf61652[_0xd2ba('0x57')],'applications':[{'id':0x0,'priority':0x1,'app':_0xd2ba('0x64'),'appdata':_0x33520e[_0xd2ba('0xd')]+','+(_0xf61652[_0xd2ba('0x57')][_0xd2ba('0x65')]||0x12c),'interval':_0xd2ba('0x66')}]},routingClient);})[_0xd2ba('0x13')](respondWithResult(_0x4cf14c,null))[_0xd2ba('0xb')](handleError(_0x4cf14c,null));};};exports[_0xd2ba('0x67')]=function(_0x33ddc3,_0x1b122c){var _0xdfc8f0,_0x49d5da;if(_[_0xd2ba('0x31')](_0x33ddc3['body'][_0xd2ba('0x68')])){throw new Error(_0xd2ba('0x69'));}var _0x28177a=_0x33ddc3[_0xd2ba('0x26')][_0xd2ba('0x68')];var _0x22ff40=_['capitalize'](_0x28177a);var _0x52c49c=_0x28177a===_0xd2ba('0x55')?_0xd2ba('0x56'):_0xd2ba('0x57');return db[_0xd2ba('0x6a')][_0xd2ba('0x59')]({'raw':!![],'where':{'id':_0x33ddc3['params']['id'],'role':_0xd2ba('0x34')}})[_0xd2ba('0x13')](function(_0x3da566){if(_[_0xd2ba('0x31')](_0x3da566)){throw new Error('Agent\x20not\x20found');}_0xdfc8f0=_0x3da566;return db[_0x22ff40+_0xd2ba('0x6b')][_0xd2ba('0x59')]({'where':{'id':_0x33ddc3[_0xd2ba('0x26')][_0xd2ba('0x5a')]},'include':[{'model':db[_0x22ff40+'Interaction'],'as':_0xd2ba('0x5b')},{'model':db[_0x22ff40+_0x52c49c],'as':_0xd2ba('0x57')}]});})['then'](function(_0x539478){if(_[_0xd2ba('0x31')](_0x539478)){throw new Error(_0x22ff40+_0xd2ba('0x5c'));}_0x49d5da=_0x539478;return _0x539478['update']({'read':0x0,'readAt':null,'UserId':null});})[_0xd2ba('0x13')](function(){var _0x12ff8={'uniqueid':_0x28177a+'.'+_0x49d5da['id']+'.'+_0x49d5da[_0xd2ba('0x5b')]['id'],'FromUserId':_0x33ddc3[_0xd2ba('0x27')]['id'],'type':_0xd2ba('0x64'),'ToUserId':_0xdfc8f0['id']};_0x12ff8[_0x22ff40+'MessageId']=_0x49d5da['id'];_0x12ff8[_0x22ff40+_0xd2ba('0x5e')]=_0x49d5da[_0xd2ba('0x5b')]['id'];_0x12ff8[_0xd2ba('0x5f')+_0x22ff40+_0x52c49c+'Id']=_0x49d5da[_0xd2ba('0x57')]['id'];return db[_0x22ff40+_0xd2ba('0x61')][_0xd2ba('0x62')](_0x12ff8);})[_0xd2ba('0x13')](function(){return respondWithRpcPromise(_0xd2ba('0x63'),{'channel':_0x28177a,'interaction':_0x49d5da[_0xd2ba('0x5b')],'message':_0x49d5da,'account':_0x49d5da[_0xd2ba('0x57')],'applications':[{'id':0x0,'priority':0x1,'app':_0xd2ba('0x34'),'appdata':_0xdfc8f0['name']+','+(_0x49d5da[_0xd2ba('0x57')][_0xd2ba('0x6c')]||0x12c),'interval':_0xd2ba('0x66')}]},routingClient);})[_0xd2ba('0x13')](respondWithResult(_0x1b122c,null))['catch'](handleError(_0x1b122c,null));};