Built motion from commit (unavailable).|2.6.0
[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 _0xd2d9=['queue_id','uniq','value','indexOf','smsQueuesWaitingInteractions','SmsQueuesWaitingInteractions','WhatsappQueuesWaitingInteractions','faxQueuesWaitingInteractions','chat','Account','Queue','\x20Queue\x20not\x20found','findOne','messageId','Interaction','\x20Message\x20not\x20found','update','MessageId','InteractionId','From','QueueId','create','Start','queue','queueTransferTimeout','channel','Channel\x20field\x20is\x20mandatory','capitalize','Website','agent','Agent\x20not\x20found','Message','TransferReport','agentTransferTimeout','bluebird','moment','lodash','util','../../mysqldb','../../config/logger','api','client','http','request','then','error','message','catch','status','json','sendStatus','stack','name','isNil','rows','find','voiceChannels','VoiceChannels','query','voiceChannelMixMonitor','merge','params','voiceChannelStopMixMonitor','voiceQueues','VoiceQueues','updateVoiceQueue','VoiceQueuesPreview','voiceQueuesChannels','VoiceQueuesChannels','voiceQueuesChannel','VoiceQueuesChannel','voiceQueuesChannelHangup','VoiceQueuesChannelHangup','VoiceQueuesChannelRedirect','outbound','outboundChannels','OutboundChannels','Agents','agentCapacity','body','interaction','user','hasOwnProperty','MemberReport','findAll','length','updateAttributes','findOrCreate','INTERACTION','interface','SIP/%s','internal','capacity','telephones','Telephones','trunks','Trunks','chatQueues','ChatQueues','showChatQueues','mailQueues','MailQueues','showMailQueues','mailAccounts','MailAccounts','openchannelQueues','OpenchannelQueues','showOpenchannelQueues','smsQueues','showSmsQueues','SmsQueues','whatsappQueues','WhatsappQueues','showWhatsappQueues','faxQueues','FaxQueues','showFaxQueues','faxAccounts','FaxAccounts','chatQueuesWaitingInteractions','mailQueuesWaitingInteractions','MailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','OpenchannelQueuesWaitingInteractions','type','filter'];(function(_0x2b10c6,_0x185590){var _0x3789d2=function(_0x272987){while(--_0x272987){_0x2b10c6['push'](_0x2b10c6['shift']());}};_0x3789d2(++_0x185590);}(_0xd2d9,0x19c));var _0x9d2d=function(_0x43f489,_0x2b4fea){_0x43f489=_0x43f489-0x0;var _0x4134b4=_0xd2d9[_0x43f489];return _0x4134b4;};'use strict';var BPromise=require(_0x9d2d('0x0'));var moment=require(_0x9d2d('0x1'));var _=require(_0x9d2d('0x2'));var util=require(_0x9d2d('0x3'));var db=require(_0x9d2d('0x4'))['db'];var logger=require(_0x9d2d('0x5'))(_0x9d2d('0x6'));var jayson=require('jayson/promise');var amiClient=jayson[_0x9d2d('0x7')][_0x9d2d('0x8')]({'port':0x232a});var mailClient=jayson[_0x9d2d('0x7')][_0x9d2d('0x8')]({'port':0x232b});var routingClient=jayson[_0x9d2d('0x7')][_0x9d2d('0x8')]({'port':0x232c});function respondWithRpcPromise(_0x25ebb8,_0x27713d,_0x79c250){return new BPromise(function(_0x5cb734,_0x4ab6d7){var _0x3cfc5a=_0x79c250?_0x79c250:amiClient;return _0x3cfc5a[_0x9d2d('0x9')](_0x25ebb8,_0x27713d)[_0x9d2d('0xa')](function(_0x2302ff){if(_0x2302ff[_0x9d2d('0xb')]){if(_0x2302ff['error']['code']===0x1f4){return _0x4ab6d7(_0x2302ff[_0x9d2d('0xb')]['message']);}return _0x5cb734(_0x2302ff[_0x9d2d('0xb')][_0x9d2d('0xc')]);}else{_0x5cb734(_0x2302ff['result']);}})[_0x9d2d('0xd')](function(_0x396c46){_0x4ab6d7(_0x396c46);});});}function respondWithResult(_0x2681f8,_0x4db83c){_0x4db83c=_0x4db83c||0xc8;return function(_0x535340){if(_0x535340){return _0x2681f8[_0x9d2d('0xe')](_0x4db83c)[_0x9d2d('0xf')](_0x535340);}return _0x2681f8[_0x9d2d('0x10')](0x194);};}function handleError(_0x2c0b22,_0x59f6ea){_0x59f6ea=_0x59f6ea||0x1f4;return function(_0x2c529a){logger[_0x9d2d('0xb')](_0x2c529a[_0x9d2d('0x11')]);if(_0x2c529a['name']){delete _0x2c529a[_0x9d2d('0x12')];}_0x2c0b22[_0x9d2d('0xe')](_0x59f6ea)['send'](_0x2c529a);};}function findById(_0x227ab4){return function(_0xcda890){if(!_[_0x9d2d('0x13')](_0x227ab4)&&!_[_0x9d2d('0x13')](_0xcda890)&&!_[_0x9d2d('0x13')](_0xcda890[_0x9d2d('0x14')])){return _[_0x9d2d('0x15')](_0xcda890[_0x9d2d('0x14')],function(_0x2553ff){return _0x2553ff['id']==_0x227ab4;});}return null;};}exports[_0x9d2d('0x16')]=function(_0x4b0626,_0x45568d){return respondWithRpcPromise(_0x9d2d('0x17'),_0x4b0626[_0x9d2d('0x18')])['then'](respondWithResult(_0x45568d,null))['catch'](handleError(_0x45568d,null));};exports[_0x9d2d('0x19')]=function(_0x41fcad,_0x3313f5){return respondWithRpcPromise('VoiceChannelMixMonitor',_[_0x9d2d('0x1a')](_0x41fcad[_0x9d2d('0x18')],_0x41fcad[_0x9d2d('0x1b')]))[_0x9d2d('0xa')](respondWithResult(_0x3313f5,null))[_0x9d2d('0xd')](handleError(_0x3313f5,null));};exports[_0x9d2d('0x1c')]=function(_0x16c664,_0x232e3f){return respondWithRpcPromise('VoiceChannelStopMixMonitor',_['merge'](_0x16c664[_0x9d2d('0x18')],_0x16c664[_0x9d2d('0x1b')]))[_0x9d2d('0xa')](respondWithResult(_0x232e3f,null))[_0x9d2d('0xd')](handleError(_0x232e3f,null));};exports[_0x9d2d('0x1d')]=function(_0x31ffcf,_0x3eb465){return respondWithRpcPromise(_0x9d2d('0x1e'),_0x31ffcf['query'])[_0x9d2d('0xa')](respondWithResult(_0x3eb465,null))[_0x9d2d('0xd')](handleError(_0x3eb465,null));};exports['showVoiceQueues']=function(_0x3a84ae,_0x7d2146){return respondWithRpcPromise(_0x9d2d('0x1e'),_0x3a84ae[_0x9d2d('0x18')])[_0x9d2d('0xa')](findById(_0x3a84ae[_0x9d2d('0x1b')]['id']))[_0x9d2d('0xa')](respondWithResult(_0x7d2146,null))['catch'](handleError(_0x7d2146,null));};exports[_0x9d2d('0x1f')]=function(_0x23bbdc,_0x558a86){return respondWithRpcPromise('UpdateVoiceQueue',_[_0x9d2d('0x1a')](_0x23bbdc['body'],_0x23bbdc[_0x9d2d('0x1b')]))['then'](respondWithResult(_0x558a86,null))[_0x9d2d('0xd')](handleError(_0x558a86,null));};exports['voiceQueuesPreview']=function(_0x3158fb,_0x5d7555){return respondWithRpcPromise(_0x9d2d('0x20'),_[_0x9d2d('0x1a')](_0x3158fb['query'],_0x3158fb[_0x9d2d('0x1b')]))['then'](respondWithResult(_0x5d7555,null))['catch'](handleError(_0x5d7555,null));};exports[_0x9d2d('0x21')]=function(_0x164f9f,_0x421800){return respondWithRpcPromise(_0x9d2d('0x22'),_0x164f9f['query'])[_0x9d2d('0xa')](respondWithResult(_0x421800,null))[_0x9d2d('0xd')](handleError(_0x421800,null));};exports[_0x9d2d('0x23')]=function(_0x2b4f5c,_0x3b5d7a){return respondWithRpcPromise(_0x9d2d('0x24'),_[_0x9d2d('0x1a')](_0x2b4f5c['query'],_0x2b4f5c[_0x9d2d('0x1b')]))['then'](respondWithResult(_0x3b5d7a,null))[_0x9d2d('0xd')](handleError(_0x3b5d7a,null));};exports[_0x9d2d('0x25')]=function(_0x306c79,_0x178bfc){return respondWithRpcPromise(_0x9d2d('0x26'),_[_0x9d2d('0x1a')](_0x306c79['query'],_0x306c79['params']))[_0x9d2d('0xa')](respondWithResult(_0x178bfc,null))[_0x9d2d('0xd')](handleError(_0x178bfc,null));};exports['voiceQueuesChannelRedirect']=function(_0x42d955,_0x1808ed){return respondWithRpcPromise(_0x9d2d('0x27'),_[_0x9d2d('0x1a')](_0x42d955[_0x9d2d('0x18')],_0x42d955[_0x9d2d('0x1b')]))[_0x9d2d('0xa')](respondWithResult(_0x1808ed,null))[_0x9d2d('0xd')](handleError(_0x1808ed,null));};exports[_0x9d2d('0x28')]=function(_0x5b2723,_0xc7371b){return respondWithRpcPromise('Outbound',_0x5b2723[_0x9d2d('0x18')])[_0x9d2d('0xa')](respondWithResult(_0xc7371b,null))[_0x9d2d('0xd')](handleError(_0xc7371b,null));};exports[_0x9d2d('0x29')]=function(_0x352052,_0x940723){return respondWithRpcPromise(_0x9d2d('0x2a'),_0x352052[_0x9d2d('0x18')])['then'](respondWithResult(_0x940723,null))['catch'](handleError(_0x940723,null));};exports['agents']=function(_0xcc5015,_0x5de085){var _0x4360ef;return respondWithRpcPromise(_0x9d2d('0x2b'),_0xcc5015[_0x9d2d('0x18')])[_0x9d2d('0xa')](function(_0x1f7ddd){_0x4360ef=_0x1f7ddd;return respondWithRpcPromise(_0x9d2d('0x2b'),_0xcc5015[_0x9d2d('0x18')],routingClient);})['then'](function(_0x2d0b30){return _[_0x9d2d('0x1a')]({},_0x2d0b30,_0x4360ef);})[_0x9d2d('0xa')](respondWithResult(_0x5de085,null))[_0x9d2d('0xd')](handleError(_0x5de085,null));};exports[_0x9d2d('0x2c')]=function(_0x463cdc,_0xb510e7){if(_0x463cdc['body']&&_0x463cdc[_0x9d2d('0x2d')][_0x9d2d('0x2e')]&&_0x463cdc[_0x9d2d('0x2f')]&&_0x463cdc[_0x9d2d('0x2f')][_0x9d2d('0x12')]){for(var _0x3390ad in _0x463cdc['body'][_0x9d2d('0x2e')]){if(_0x463cdc[_0x9d2d('0x2d')][_0x9d2d('0x2e')][_0x9d2d('0x30')](_0x3390ad)){db[_0x9d2d('0x31')][_0x9d2d('0x32')]({'where':{'channel':_0x3390ad,'membername':_0x463cdc[_0x9d2d('0x2f')]['name'],'type':'INTERACTION','exitAt':null,'uniqueid':_0x463cdc[_0x9d2d('0x2d')][_0x9d2d('0x2e')][_0x3390ad]&&_0x463cdc['body'][_0x9d2d('0x2e')][_0x3390ad]['length']?{'$notIn':_0x463cdc['body'][_0x9d2d('0x2e')][_0x3390ad]}:{'$ne':null}}})[_0x9d2d('0xa')](function(_0x2a7fa5){var _0x4f9fde=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');for(var _0xb897c4=0x0,_0x534c6a=_0x2a7fa5[_0x9d2d('0x33')];_0xb897c4<_0x534c6a;_0xb897c4+=0x1){_0x2a7fa5[_0xb897c4][_0x9d2d('0x34')]({'exitAt':_0x4f9fde});}});for(var _0x296b07=0x0;_0x296b07<_0x463cdc[_0x9d2d('0x2d')]['interaction'][_0x3390ad][_0x9d2d('0x33')];_0x296b07+=0x1){db[_0x9d2d('0x31')][_0x9d2d('0x35')]({'where':{'channel':_0x3390ad,'membername':_0x463cdc[_0x9d2d('0x2f')]['name'],'type':_0x9d2d('0x36'),'uniqueid':_0x463cdc[_0x9d2d('0x2d')][_0x9d2d('0x2e')][_0x3390ad][_0x296b07],'exitAt':null},'defaults':{'channel':_0x3390ad,'membername':_0x463cdc['user'][_0x9d2d('0x12')],'interface':_[_0x9d2d('0x13')](_0x463cdc[_0x9d2d('0x2f')][_0x9d2d('0x37')])?util['format'](_0x9d2d('0x38'),_0x463cdc[_0x9d2d('0x2f')][_0x9d2d('0x12')]):_0x463cdc[_0x9d2d('0x2f')][_0x9d2d('0x37')],'type':_0x9d2d('0x36'),'enterAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'role':'agent','internal':_0x463cdc[_0x9d2d('0x2f')][_0x9d2d('0x39')],'uniqueid':_0x463cdc[_0x9d2d('0x2d')]['interaction'][_0x3390ad][_0x296b07]}});}}}}return respondWithRpcPromise('AgentCapacity',{'id':_0x463cdc[_0x9d2d('0x1b')]['id'],'capacity':_0x463cdc[_0x9d2d('0x2d')][_0x9d2d('0x3a')]},routingClient)[_0x9d2d('0xa')](respondWithResult(_0xb510e7,null))[_0x9d2d('0xd')](handleError(_0xb510e7,null));};exports[_0x9d2d('0x3b')]=function(_0x3cb0c1,_0x2d9fb4){return respondWithRpcPromise(_0x9d2d('0x3c'),_0x3cb0c1[_0x9d2d('0x18')])['then'](respondWithResult(_0x2d9fb4,null))[_0x9d2d('0xd')](handleError(_0x2d9fb4,null));};exports[_0x9d2d('0x3d')]=function(_0x3491b8,_0x52143b){return respondWithRpcPromise(_0x9d2d('0x3e'),_0x3491b8[_0x9d2d('0x18')])[_0x9d2d('0xa')](respondWithResult(_0x52143b,null))[_0x9d2d('0xd')](handleError(_0x52143b,null));};exports['campaigns']=function(_0xee5a4,_0x242c27){return respondWithRpcPromise('Campaigns',_0xee5a4['query'])[_0x9d2d('0xa')](respondWithResult(_0x242c27,null))[_0x9d2d('0xd')](handleError(_0x242c27,null));};exports[_0x9d2d('0x3f')]=function(_0x48cba5,_0x324467){return respondWithRpcPromise(_0x9d2d('0x40'),_0x48cba5[_0x9d2d('0x18')],routingClient)['then'](respondWithResult(_0x324467,null))[_0x9d2d('0xd')](handleError(_0x324467,null));};exports[_0x9d2d('0x41')]=function(_0x108290,_0x18cf4f){return respondWithRpcPromise('ChatQueues',_0x108290[_0x9d2d('0x18')],routingClient)[_0x9d2d('0xa')](findById(_0x108290['params']['id']))[_0x9d2d('0xa')](respondWithResult(_0x18cf4f,null))[_0x9d2d('0xd')](handleError(_0x18cf4f,null));};exports[_0x9d2d('0x42')]=function(_0x2bce02,_0x1896e6){return respondWithRpcPromise(_0x9d2d('0x43'),_0x2bce02['query'],routingClient)[_0x9d2d('0xa')](respondWithResult(_0x1896e6,null))[_0x9d2d('0xd')](handleError(_0x1896e6,null));};exports[_0x9d2d('0x44')]=function(_0xc21bcd,_0x5c666b){return respondWithRpcPromise(_0x9d2d('0x43'),_0xc21bcd[_0x9d2d('0x18')],routingClient)['then'](findById(_0xc21bcd[_0x9d2d('0x1b')]['id']))[_0x9d2d('0xa')](respondWithResult(_0x5c666b,null))['catch'](handleError(_0x5c666b,null));};exports[_0x9d2d('0x45')]=function(_0x44d15a,_0x5d3a9e){return respondWithRpcPromise(_0x9d2d('0x46'),_0x44d15a['query'],mailClient)[_0x9d2d('0xa')](respondWithResult(_0x5d3a9e,null))[_0x9d2d('0xd')](handleError(_0x5d3a9e,null));};exports[_0x9d2d('0x47')]=function(_0x274992,_0x2b1a4f){return respondWithRpcPromise(_0x9d2d('0x48'),_0x274992[_0x9d2d('0x18')],routingClient)[_0x9d2d('0xa')](respondWithResult(_0x2b1a4f,null))['catch'](handleError(_0x2b1a4f,null));};exports[_0x9d2d('0x49')]=function(_0x4ae6e2,_0x251e24){return respondWithRpcPromise('OpenchannelQueues',_0x4ae6e2['query'],routingClient)[_0x9d2d('0xa')](findById(_0x4ae6e2[_0x9d2d('0x1b')]['id']))[_0x9d2d('0xa')](respondWithResult(_0x251e24,null))[_0x9d2d('0xd')](handleError(_0x251e24,null));};exports[_0x9d2d('0x4a')]=function(_0x2bc93d,_0x116c07){return respondWithRpcPromise('SmsQueues',_0x2bc93d[_0x9d2d('0x18')],routingClient)['then'](respondWithResult(_0x116c07,null))[_0x9d2d('0xd')](handleError(_0x116c07,null));};exports[_0x9d2d('0x4b')]=function(_0x5e404e,_0x47bc46){return respondWithRpcPromise(_0x9d2d('0x4c'),_0x5e404e[_0x9d2d('0x18')],routingClient)[_0x9d2d('0xa')](findById(_0x5e404e['params']['id']))[_0x9d2d('0xa')](respondWithResult(_0x47bc46,null))[_0x9d2d('0xd')](handleError(_0x47bc46,null));};exports[_0x9d2d('0x4d')]=function(_0x146d32,_0x33edb5){return respondWithRpcPromise(_0x9d2d('0x4e'),_0x146d32[_0x9d2d('0x18')],routingClient)['then'](respondWithResult(_0x33edb5,null))[_0x9d2d('0xd')](handleError(_0x33edb5,null));};exports[_0x9d2d('0x4f')]=function(_0x28921d,_0x2a7d20){return respondWithRpcPromise(_0x9d2d('0x4e'),_0x28921d['query'],routingClient)[_0x9d2d('0xa')](findById(_0x28921d[_0x9d2d('0x1b')]['id']))['then'](respondWithResult(_0x2a7d20,null))[_0x9d2d('0xd')](handleError(_0x2a7d20,null));};exports[_0x9d2d('0x50')]=function(_0x35eb7f,_0x5d4dde){return respondWithRpcPromise(_0x9d2d('0x51'),_0x35eb7f[_0x9d2d('0x18')],routingClient)['then'](respondWithResult(_0x5d4dde,null))[_0x9d2d('0xd')](handleError(_0x5d4dde,null));};exports[_0x9d2d('0x52')]=function(_0x3805d7,_0x4145f4){return respondWithRpcPromise(_0x9d2d('0x51'),_0x3805d7['query'],routingClient)[_0x9d2d('0xa')](findById(_0x3805d7[_0x9d2d('0x1b')]['id']))[_0x9d2d('0xa')](respondWithResult(_0x4145f4,null))[_0x9d2d('0xd')](handleError(_0x4145f4,null));};exports[_0x9d2d('0x53')]=function(_0x1c9d82,_0x458f11){return respondWithRpcPromise(_0x9d2d('0x54'),_0x1c9d82[_0x9d2d('0x18')])[_0x9d2d('0xa')](respondWithResult(_0x458f11,null))[_0x9d2d('0xd')](handleError(_0x458f11,null));};exports[_0x9d2d('0x55')]=function(_0x2a9413,_0x2a73bb){return respondWithRpcPromise('ChatQueuesWaitingInteractions',_0x2a9413['query'],routingClient)[_0x9d2d('0xa')](respondWithResult(_0x2a73bb,null))[_0x9d2d('0xd')](handleError(_0x2a73bb,null));};exports[_0x9d2d('0x56')]=function(_0xe814f0,_0x9fdb5b){return respondWithRpcPromise(_0x9d2d('0x57'),_0xe814f0[_0x9d2d('0x18')],routingClient)[_0x9d2d('0xa')](respondWithResult(_0x9fdb5b,null))[_0x9d2d('0xd')](handleError(_0x9fdb5b,null));};exports[_0x9d2d('0x58')]=function(_0x2d4afd,_0x3b9b9){return respondWithRpcPromise(_0x9d2d('0x59'),_0x2d4afd['query'],routingClient)[_0x9d2d('0xa')](respondWithResult(_0x3b9b9,null))[_0x9d2d('0xd')](handleError(_0x3b9b9,null));};exports['openchannelQueuesIdWaitingInteractions']=function(_0x23cda9,_0x300dcb){return respondWithRpcPromise(_0x9d2d('0x59'),_0x23cda9['query'],routingClient)['then'](function(_0x122288){if(_0x23cda9[_0x9d2d('0x18')][_0x9d2d('0x5a')]!==undefined){var _0x3edbfb=_(_0x122288['rows'])[_0x9d2d('0x5b')]([_0x23cda9[_0x9d2d('0x18')][_0x9d2d('0x5a')],_0x23cda9['params']['id']])['map'](_0x9d2d('0x5c'))[_0x9d2d('0x5d')]()[_0x9d2d('0x5e')]();return _0x122288['rows']['filter'](function(_0x307c41){return _0x3edbfb[_0x9d2d('0x5f')](_0x307c41[_0x9d2d('0x5c')])>-0x1;});}else{return _0x122288[_0x9d2d('0x14')][_0x9d2d('0x5b')](function(_0x67b736){return _0x67b736[_0x9d2d('0x5c')]===parseInt(_0x23cda9[_0x9d2d('0x1b')]['id']);});}})[_0x9d2d('0xa')](respondWithResult(_0x300dcb,null))[_0x9d2d('0xd')](handleError(_0x300dcb,null));};exports[_0x9d2d('0x60')]=function(_0x4817f4,_0x219f35){return respondWithRpcPromise(_0x9d2d('0x61'),_0x4817f4[_0x9d2d('0x18')],routingClient)[_0x9d2d('0xa')](respondWithResult(_0x219f35,null))[_0x9d2d('0xd')](handleError(_0x219f35,null));};exports['whatsappQueuesWaitingInteractions']=function(_0x30cb48,_0x22e72d){return respondWithRpcPromise(_0x9d2d('0x62'),_0x30cb48[_0x9d2d('0x18')],routingClient)[_0x9d2d('0xa')](respondWithResult(_0x22e72d,null))[_0x9d2d('0xd')](handleError(_0x22e72d,null));};exports[_0x9d2d('0x63')]=function(_0x85317e,_0x174db8){return respondWithRpcPromise('FaxQueuesWaitingInteractions',_0x85317e[_0x9d2d('0x18')],routingClient)['then'](respondWithResult(_0x174db8,null))[_0x9d2d('0xd')](handleError(_0x174db8,null));};exports['queueNotify']=function(_0x4a7ec9){return function(_0x3c9aba,_0x43bb92){var _0x5a3efd,_0x2d2d04;var _0x4ebcb5=_['capitalize'](_0x4a7ec9);var _0x247cba=_0x4a7ec9===_0x9d2d('0x64')?'Website':_0x9d2d('0x65');return db[_0x4ebcb5+_0x9d2d('0x66')]['findOne']({'raw':!![],'where':{'id':_0x3c9aba[_0x9d2d('0x1b')]['id']}})[_0x9d2d('0xa')](function(_0x184576){if(_['isNil'](_0x184576)){throw new Error(_0x4ebcb5+_0x9d2d('0x67'));}_0x5a3efd=_0x184576;return db[_0x4ebcb5+'Message'][_0x9d2d('0x68')]({'where':{'id':_0x3c9aba[_0x9d2d('0x2d')][_0x9d2d('0x69')]},'include':[{'model':db[_0x4ebcb5+_0x9d2d('0x6a')],'as':_0x9d2d('0x6a')},{'model':db[_0x4ebcb5+_0x247cba],'as':_0x9d2d('0x65')}]});})[_0x9d2d('0xa')](function(_0x1c79ac){if(_['isNil'](_0x1c79ac)){throw new Error(_0x4ebcb5+_0x9d2d('0x6b'));}_0x2d2d04=_0x1c79ac;return _0x1c79ac[_0x9d2d('0x6c')]({'read':0x0,'readAt':null,'UserId':null});})[_0x9d2d('0xa')](function(){var _0x5c3434={'uniqueid':_0x4a7ec9+'.'+_0x2d2d04['id']+'.'+_0x2d2d04[_0x9d2d('0x6a')]['id'],'FromUserId':_0x3c9aba['user']['id'],'type':'queue'};_0x5c3434[_0x4ebcb5+_0x9d2d('0x6d')]=_0x2d2d04['id'];_0x5c3434[_0x4ebcb5+_0x9d2d('0x6e')]=_0x2d2d04[_0x9d2d('0x6a')]['id'];_0x5c3434[_0x9d2d('0x6f')+_0x4ebcb5+_0x247cba+'Id']=_0x2d2d04['Account']['id'];_0x5c3434['To'+_0x4ebcb5+_0x9d2d('0x70')]=_0x5a3efd['id'];return db[_0x4ebcb5+'TransferReport'][_0x9d2d('0x71')](_0x5c3434);})['then'](function(){return respondWithRpcPromise(_0x9d2d('0x72'),{'channel':_0x4a7ec9,'interaction':_0x2d2d04[_0x9d2d('0x6a')],'message':_0x2d2d04,'account':_0x2d2d04[_0x9d2d('0x65')],'applications':[{'id':0x0,'priority':0x1,'app':_0x9d2d('0x73'),'appdata':_0x5a3efd[_0x9d2d('0x12')]+','+(_0x2d2d04[_0x9d2d('0x65')][_0x9d2d('0x74')]||0x12c),'interval':'*,*,*,*'}]},routingClient);})[_0x9d2d('0xa')](respondWithResult(_0x43bb92,null))[_0x9d2d('0xd')](handleError(_0x43bb92,null));};};exports['agentNotify']=function(_0x5f5db3,_0x2b9072){var _0x59e079,_0x10d682;if(_['isNil'](_0x5f5db3[_0x9d2d('0x2d')][_0x9d2d('0x75')])){throw new Error(_0x9d2d('0x76'));}var _0x4a8730=_0x5f5db3[_0x9d2d('0x2d')][_0x9d2d('0x75')];var _0x1e610c=_[_0x9d2d('0x77')](_0x4a8730);var _0x4765a1=_0x4a8730==='chat'?_0x9d2d('0x78'):'Account';return db['User']['findOne']({'raw':!![],'where':{'id':_0x5f5db3[_0x9d2d('0x1b')]['id'],'role':_0x9d2d('0x79')}})[_0x9d2d('0xa')](function(_0x4b0cec){if(_[_0x9d2d('0x13')](_0x4b0cec)){throw new Error(_0x9d2d('0x7a'));}_0x59e079=_0x4b0cec;return db[_0x1e610c+_0x9d2d('0x7b')][_0x9d2d('0x68')]({'where':{'id':_0x5f5db3['body'][_0x9d2d('0x69')]},'include':[{'model':db[_0x1e610c+_0x9d2d('0x6a')],'as':'Interaction'},{'model':db[_0x1e610c+_0x4765a1],'as':'Account'}]});})[_0x9d2d('0xa')](function(_0x270ae6){if(_['isNil'](_0x270ae6)){throw new Error(_0x1e610c+_0x9d2d('0x6b'));}_0x10d682=_0x270ae6;return _0x270ae6[_0x9d2d('0x6c')]({'read':0x0,'readAt':null,'UserId':null});})[_0x9d2d('0xa')](function(){var _0x2de374={'uniqueid':_0x4a8730+'.'+_0x10d682['id']+'.'+_0x10d682[_0x9d2d('0x6a')]['id'],'FromUserId':_0x5f5db3[_0x9d2d('0x2f')]['id'],'type':_0x9d2d('0x73'),'ToUserId':_0x59e079['id']};_0x2de374[_0x1e610c+_0x9d2d('0x6d')]=_0x10d682['id'];_0x2de374[_0x1e610c+'InteractionId']=_0x10d682['Interaction']['id'];_0x2de374[_0x9d2d('0x6f')+_0x1e610c+_0x4765a1+'Id']=_0x10d682[_0x9d2d('0x65')]['id'];return db[_0x1e610c+_0x9d2d('0x7c')][_0x9d2d('0x71')](_0x2de374);})['then'](function(){return respondWithRpcPromise(_0x9d2d('0x72'),{'channel':_0x4a8730,'interaction':_0x10d682[_0x9d2d('0x6a')],'message':_0x10d682,'account':_0x10d682[_0x9d2d('0x65')],'applications':[{'id':0x0,'priority':0x1,'app':_0x9d2d('0x79'),'appdata':_0x59e079[_0x9d2d('0x12')]+','+(_0x10d682['Account'][_0x9d2d('0x7d')]||0x12c),'interval':'*,*,*,*'}]},routingClient);})['then'](respondWithResult(_0x2b9072,null))[_0x9d2d('0xd')](handleError(_0x2b9072,null));};