3f9e84eb8b4b22f0439a911e76124fa5e54e8b64
[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 _0x97f6=['MailAccounts','openchannelQueues','OpenchannelQueues','showOpenchannelQueues','SmsQueues','showSmsQueues','whatsappQueues','WhatsappQueues','showWhatsappQueues','faxQueues','FaxQueues','showFaxQueues','FaxAccounts','chatQueuesWaitingInteractions','ChatQueuesWaitingInteractions','mailQueuesWaitingInteractions','MailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','OpenchannelQueuesWaitingInteractions','openchannelQueuesIdWaitingInteractions','type','map','queue_id','uniq','value','indexOf','filter','smsQueuesWaitingInteractions','whatsappQueuesWaitingInteractions','WhatsappQueuesWaitingInteractions','faxQueuesWaitingInteractions','FaxQueuesWaitingInteractions','queueNotify','chat','Website','Queue','findOne','\x20Queue\x20not\x20found','Message','messageId','Interaction','\x20Message\x20not\x20found','update','queue','MessageId','InteractionId','From','Account','QueueId','TransferReport','create','Start','queueTransferTimeout','*,*,*,*','channel','Channel\x20field\x20is\x20mandatory','capitalize','User','Agent\x20not\x20found','agentTransferTimeout','moment','lodash','util','../../mysqldb','api','jayson/promise','client','http','request','error','code','message','result','catch','status','json','stack','name','isNil','rows','find','voiceChannels','VoiceChannels','query','then','voiceChannelMixMonitor','VoiceChannelMixMonitor','params','voiceChannelStopMixMonitor','VoiceChannelStopMixMonitor','merge','voiceQueues','VoiceQueues','showVoiceQueues','updateVoiceQueue','body','voiceQueuesPreview','VoiceQueuesPreview','voiceQueuesChannels','voiceQueuesChannel','VoiceQueuesChannel','voiceQueuesChannelHangup','VoiceQueuesChannelHangup','VoiceQueuesChannelRedirect','Outbound','outboundChannels','agents','Agents','user','interaction','MemberReport','INTERACTION','length','format','YYYY-MM-DD\x20HH:mm:ss','updateAttributes','findOrCreate','interface','SIP/%s','agent','internal','telephones','Telephones','Trunks','campaigns','Campaigns','chatQueues','showChatQueues','ChatQueues','mailQueues','MailQueues','mailAccounts'];(function(_0x53c53b,_0x257775){var _0x20a2e2=function(_0x17e251){while(--_0x17e251){_0x53c53b['push'](_0x53c53b['shift']());}};_0x20a2e2(++_0x257775);}(_0x97f6,0x1c8));var _0x697f=function(_0x233f79,_0x1a9615){_0x233f79=_0x233f79-0x0;var _0x34441f=_0x97f6[_0x233f79];return _0x34441f;};'use strict';var BPromise=require('bluebird');var moment=require(_0x697f('0x0'));var _=require(_0x697f('0x1'));var util=require(_0x697f('0x2'));var db=require(_0x697f('0x3'))['db'];var logger=require('../../config/logger')(_0x697f('0x4'));var jayson=require(_0x697f('0x5'));var amiClient=jayson[_0x697f('0x6')]['http']({'port':0x232a});var mailClient=jayson[_0x697f('0x6')][_0x697f('0x7')]({'port':0x232b});var routingClient=jayson[_0x697f('0x6')]['http']({'port':0x232c});function respondWithRpcPromise(_0x33795b,_0x525ac2,_0x3c496f){return new BPromise(function(_0x5ba69d,_0x336b31){var _0x483ef2=_0x3c496f?_0x3c496f:amiClient;return _0x483ef2[_0x697f('0x8')](_0x33795b,_0x525ac2)['then'](function(_0x48c560){if(_0x48c560[_0x697f('0x9')]){if(_0x48c560[_0x697f('0x9')][_0x697f('0xa')]===0x1f4){return _0x336b31(_0x48c560[_0x697f('0x9')][_0x697f('0xb')]);}return _0x5ba69d(_0x48c560[_0x697f('0x9')][_0x697f('0xb')]);}else{_0x5ba69d(_0x48c560[_0x697f('0xc')]);}})[_0x697f('0xd')](function(_0x93d178){_0x336b31(_0x93d178);});});}function respondWithResult(_0x372a17,_0x530d6c){_0x530d6c=_0x530d6c||0xc8;return function(_0x5fb99d){if(_0x5fb99d){return _0x372a17[_0x697f('0xe')](_0x530d6c)[_0x697f('0xf')](_0x5fb99d);}return _0x372a17['sendStatus'](0x194);};}function handleError(_0x6f3277,_0xd9d809){_0xd9d809=_0xd9d809||0x1f4;return function(_0x183050){logger[_0x697f('0x9')](_0x183050[_0x697f('0x10')]);if(_0x183050['name']){delete _0x183050[_0x697f('0x11')];}_0x6f3277[_0x697f('0xe')](_0xd9d809)['send'](_0x183050);};}function findById(_0x2127e9){return function(_0xd852a9){if(!_['isNil'](_0x2127e9)&&!_['isNil'](_0xd852a9)&&!_[_0x697f('0x12')](_0xd852a9[_0x697f('0x13')])){return _[_0x697f('0x14')](_0xd852a9[_0x697f('0x13')],function(_0x5e5fa4){return _0x5e5fa4['id']==_0x2127e9;});}return null;};}exports[_0x697f('0x15')]=function(_0x1a9570,_0x5e8553){return respondWithRpcPromise(_0x697f('0x16'),_0x1a9570[_0x697f('0x17')])[_0x697f('0x18')](respondWithResult(_0x5e8553,null))[_0x697f('0xd')](handleError(_0x5e8553,null));};exports[_0x697f('0x19')]=function(_0x1d9b1b,_0x14ba42){return respondWithRpcPromise(_0x697f('0x1a'),_['merge'](_0x1d9b1b[_0x697f('0x17')],_0x1d9b1b[_0x697f('0x1b')]))[_0x697f('0x18')](respondWithResult(_0x14ba42,null))[_0x697f('0xd')](handleError(_0x14ba42,null));};exports[_0x697f('0x1c')]=function(_0x340021,_0x3836ab){return respondWithRpcPromise(_0x697f('0x1d'),_[_0x697f('0x1e')](_0x340021[_0x697f('0x17')],_0x340021['params']))[_0x697f('0x18')](respondWithResult(_0x3836ab,null))[_0x697f('0xd')](handleError(_0x3836ab,null));};exports[_0x697f('0x1f')]=function(_0x36fa03,_0x5af3e6){return respondWithRpcPromise(_0x697f('0x20'),_0x36fa03[_0x697f('0x17')])[_0x697f('0x18')](respondWithResult(_0x5af3e6,null))[_0x697f('0xd')](handleError(_0x5af3e6,null));};exports[_0x697f('0x21')]=function(_0xfabdce,_0x38aa5c){return respondWithRpcPromise(_0x697f('0x20'),_0xfabdce[_0x697f('0x17')])['then'](findById(_0xfabdce[_0x697f('0x1b')]['id']))[_0x697f('0x18')](respondWithResult(_0x38aa5c,null))[_0x697f('0xd')](handleError(_0x38aa5c,null));};exports[_0x697f('0x22')]=function(_0xf266ad,_0x308413){return respondWithRpcPromise('UpdateVoiceQueue',_[_0x697f('0x1e')](_0xf266ad[_0x697f('0x23')],_0xf266ad[_0x697f('0x1b')]))[_0x697f('0x18')](respondWithResult(_0x308413,null))[_0x697f('0xd')](handleError(_0x308413,null));};exports[_0x697f('0x24')]=function(_0x12487a,_0x3206ff){return respondWithRpcPromise(_0x697f('0x25'),_[_0x697f('0x1e')](_0x12487a['query'],_0x12487a[_0x697f('0x1b')]))['then'](respondWithResult(_0x3206ff,null))[_0x697f('0xd')](handleError(_0x3206ff,null));};exports[_0x697f('0x26')]=function(_0x3463b7,_0x2e16ab){return respondWithRpcPromise('VoiceQueuesChannels',_0x3463b7[_0x697f('0x17')])['then'](respondWithResult(_0x2e16ab,null))['catch'](handleError(_0x2e16ab,null));};exports[_0x697f('0x27')]=function(_0x44c7cd,_0xd69c08){return respondWithRpcPromise(_0x697f('0x28'),_[_0x697f('0x1e')](_0x44c7cd[_0x697f('0x17')],_0x44c7cd['params']))[_0x697f('0x18')](respondWithResult(_0xd69c08,null))[_0x697f('0xd')](handleError(_0xd69c08,null));};exports[_0x697f('0x29')]=function(_0x17a84f,_0x31534d){return respondWithRpcPromise(_0x697f('0x2a'),_['merge'](_0x17a84f['query'],_0x17a84f[_0x697f('0x1b')]))[_0x697f('0x18')](respondWithResult(_0x31534d,null))['catch'](handleError(_0x31534d,null));};exports['voiceQueuesChannelRedirect']=function(_0x25eb54,_0x3c8862){return respondWithRpcPromise(_0x697f('0x2b'),_[_0x697f('0x1e')](_0x25eb54['query'],_0x25eb54[_0x697f('0x1b')]))['then'](respondWithResult(_0x3c8862,null))[_0x697f('0xd')](handleError(_0x3c8862,null));};exports['outbound']=function(_0x4cb696,_0x5da7e6){return respondWithRpcPromise(_0x697f('0x2c'),_0x4cb696['query'])[_0x697f('0x18')](respondWithResult(_0x5da7e6,null))[_0x697f('0xd')](handleError(_0x5da7e6,null));};exports[_0x697f('0x2d')]=function(_0x5465da,_0x4b05a3){return respondWithRpcPromise('OutboundChannels',_0x5465da[_0x697f('0x17')])['then'](respondWithResult(_0x4b05a3,null))[_0x697f('0xd')](handleError(_0x4b05a3,null));};exports[_0x697f('0x2e')]=function(_0x1dbff3,_0x13bfef){var _0x1fcbd5;return respondWithRpcPromise(_0x697f('0x2f'),_0x1dbff3[_0x697f('0x17')])['then'](function(_0x2d5104){_0x1fcbd5=_0x2d5104;return respondWithRpcPromise(_0x697f('0x2f'),_0x1dbff3[_0x697f('0x17')],routingClient);})[_0x697f('0x18')](function(_0x3d40a7){return _[_0x697f('0x1e')]({},_0x3d40a7,_0x1fcbd5);})['then'](respondWithResult(_0x13bfef,null))[_0x697f('0xd')](handleError(_0x13bfef,null));};exports['agentCapacity']=function(_0x44329f,_0x524224){if(_0x44329f[_0x697f('0x23')]&&_0x44329f['body']['interaction']&&_0x44329f[_0x697f('0x30')]&&_0x44329f[_0x697f('0x30')]['name']){for(var _0x1ff09c in _0x44329f[_0x697f('0x23')][_0x697f('0x31')]){if(_0x44329f[_0x697f('0x23')][_0x697f('0x31')]['hasOwnProperty'](_0x1ff09c)){db[_0x697f('0x32')]['findAll']({'where':{'channel':_0x1ff09c,'membername':_0x44329f[_0x697f('0x30')]['name'],'type':_0x697f('0x33'),'exitAt':null,'uniqueid':_0x44329f['body']['interaction'][_0x1ff09c]&&_0x44329f[_0x697f('0x23')][_0x697f('0x31')][_0x1ff09c][_0x697f('0x34')]?{'$notIn':_0x44329f[_0x697f('0x23')][_0x697f('0x31')][_0x1ff09c]}:{'$ne':null}}})['then'](function(_0x274055){var _0xdc18b7=moment()[_0x697f('0x35')](_0x697f('0x36'));for(var _0x17634e=0x0,_0x499eef=_0x274055['length'];_0x17634e<_0x499eef;_0x17634e+=0x1){_0x274055[_0x17634e][_0x697f('0x37')]({'exitAt':_0xdc18b7});}});for(var _0x3c1fab=0x0;_0x3c1fab<_0x44329f[_0x697f('0x23')][_0x697f('0x31')][_0x1ff09c][_0x697f('0x34')];_0x3c1fab+=0x1){db[_0x697f('0x32')][_0x697f('0x38')]({'where':{'channel':_0x1ff09c,'membername':_0x44329f['user'][_0x697f('0x11')],'type':_0x697f('0x33'),'uniqueid':_0x44329f[_0x697f('0x23')]['interaction'][_0x1ff09c][_0x3c1fab],'exitAt':null},'defaults':{'channel':_0x1ff09c,'membername':_0x44329f[_0x697f('0x30')][_0x697f('0x11')],'interface':_[_0x697f('0x12')](_0x44329f[_0x697f('0x30')][_0x697f('0x39')])?util[_0x697f('0x35')](_0x697f('0x3a'),_0x44329f[_0x697f('0x30')]['name']):_0x44329f[_0x697f('0x30')][_0x697f('0x39')],'type':'INTERACTION','enterAt':moment()[_0x697f('0x35')](_0x697f('0x36')),'role':_0x697f('0x3b'),'internal':_0x44329f[_0x697f('0x30')][_0x697f('0x3c')],'uniqueid':_0x44329f[_0x697f('0x23')][_0x697f('0x31')][_0x1ff09c][_0x3c1fab]}});}}}}return respondWithRpcPromise('AgentCapacity',{'id':_0x44329f[_0x697f('0x1b')]['id'],'capacity':_0x44329f[_0x697f('0x23')]['capacity']},routingClient)[_0x697f('0x18')](respondWithResult(_0x524224,null))['catch'](handleError(_0x524224,null));};exports[_0x697f('0x3d')]=function(_0x319976,_0x35c015){return respondWithRpcPromise(_0x697f('0x3e'),_0x319976[_0x697f('0x17')])[_0x697f('0x18')](respondWithResult(_0x35c015,null))['catch'](handleError(_0x35c015,null));};exports['trunks']=function(_0x232cc1,_0x471c60){return respondWithRpcPromise(_0x697f('0x3f'),_0x232cc1[_0x697f('0x17')])[_0x697f('0x18')](respondWithResult(_0x471c60,null))[_0x697f('0xd')](handleError(_0x471c60,null));};exports[_0x697f('0x40')]=function(_0xf27852,_0xd096ea){return respondWithRpcPromise(_0x697f('0x41'),_0xf27852[_0x697f('0x17')])[_0x697f('0x18')](respondWithResult(_0xd096ea,null))['catch'](handleError(_0xd096ea,null));};exports[_0x697f('0x42')]=function(_0x4be7ff,_0x2d2c6c){return respondWithRpcPromise('ChatQueues',_0x4be7ff[_0x697f('0x17')],routingClient)[_0x697f('0x18')](respondWithResult(_0x2d2c6c,null))[_0x697f('0xd')](handleError(_0x2d2c6c,null));};exports[_0x697f('0x43')]=function(_0x3e0eda,_0xb0296f){return respondWithRpcPromise(_0x697f('0x44'),_0x3e0eda[_0x697f('0x17')],routingClient)[_0x697f('0x18')](findById(_0x3e0eda[_0x697f('0x1b')]['id']))['then'](respondWithResult(_0xb0296f,null))[_0x697f('0xd')](handleError(_0xb0296f,null));};exports[_0x697f('0x45')]=function(_0x3e5781,_0x3de9d6){return respondWithRpcPromise(_0x697f('0x46'),_0x3e5781['query'],routingClient)[_0x697f('0x18')](respondWithResult(_0x3de9d6,null))[_0x697f('0xd')](handleError(_0x3de9d6,null));};exports['showMailQueues']=function(_0x489479,_0x261f74){return respondWithRpcPromise(_0x697f('0x46'),_0x489479[_0x697f('0x17')],routingClient)[_0x697f('0x18')](findById(_0x489479[_0x697f('0x1b')]['id']))[_0x697f('0x18')](respondWithResult(_0x261f74,null))[_0x697f('0xd')](handleError(_0x261f74,null));};exports[_0x697f('0x47')]=function(_0x4be693,_0xb76426){return respondWithRpcPromise(_0x697f('0x48'),_0x4be693['query'],mailClient)[_0x697f('0x18')](respondWithResult(_0xb76426,null))[_0x697f('0xd')](handleError(_0xb76426,null));};exports[_0x697f('0x49')]=function(_0x3c1024,_0x2bff7d){return respondWithRpcPromise(_0x697f('0x4a'),_0x3c1024[_0x697f('0x17')],routingClient)[_0x697f('0x18')](respondWithResult(_0x2bff7d,null))['catch'](handleError(_0x2bff7d,null));};exports[_0x697f('0x4b')]=function(_0x5b821f,_0x574954){return respondWithRpcPromise(_0x697f('0x4a'),_0x5b821f[_0x697f('0x17')],routingClient)[_0x697f('0x18')](findById(_0x5b821f[_0x697f('0x1b')]['id']))[_0x697f('0x18')](respondWithResult(_0x574954,null))['catch'](handleError(_0x574954,null));};exports['smsQueues']=function(_0x24a571,_0x2b0f93){return respondWithRpcPromise(_0x697f('0x4c'),_0x24a571[_0x697f('0x17')],routingClient)[_0x697f('0x18')](respondWithResult(_0x2b0f93,null))[_0x697f('0xd')](handleError(_0x2b0f93,null));};exports[_0x697f('0x4d')]=function(_0x1df3f1,_0x332df3){return respondWithRpcPromise('SmsQueues',_0x1df3f1[_0x697f('0x17')],routingClient)[_0x697f('0x18')](findById(_0x1df3f1[_0x697f('0x1b')]['id']))[_0x697f('0x18')](respondWithResult(_0x332df3,null))[_0x697f('0xd')](handleError(_0x332df3,null));};exports[_0x697f('0x4e')]=function(_0x4150e1,_0xef49c){return respondWithRpcPromise(_0x697f('0x4f'),_0x4150e1[_0x697f('0x17')],routingClient)['then'](respondWithResult(_0xef49c,null))[_0x697f('0xd')](handleError(_0xef49c,null));};exports[_0x697f('0x50')]=function(_0x3e7945,_0x59af20){return respondWithRpcPromise(_0x697f('0x4f'),_0x3e7945[_0x697f('0x17')],routingClient)[_0x697f('0x18')](findById(_0x3e7945['params']['id']))[_0x697f('0x18')](respondWithResult(_0x59af20,null))[_0x697f('0xd')](handleError(_0x59af20,null));};exports[_0x697f('0x51')]=function(_0x5c11f2,_0x9a8ccd){return respondWithRpcPromise(_0x697f('0x52'),_0x5c11f2[_0x697f('0x17')],routingClient)[_0x697f('0x18')](respondWithResult(_0x9a8ccd,null))[_0x697f('0xd')](handleError(_0x9a8ccd,null));};exports[_0x697f('0x53')]=function(_0xd4e48f,_0x14d90b){return respondWithRpcPromise(_0x697f('0x52'),_0xd4e48f[_0x697f('0x17')],routingClient)[_0x697f('0x18')](findById(_0xd4e48f[_0x697f('0x1b')]['id']))[_0x697f('0x18')](respondWithResult(_0x14d90b,null))[_0x697f('0xd')](handleError(_0x14d90b,null));};exports['faxAccounts']=function(_0x2cdb51,_0x12f7e5){return respondWithRpcPromise(_0x697f('0x54'),_0x2cdb51[_0x697f('0x17')])[_0x697f('0x18')](respondWithResult(_0x12f7e5,null))[_0x697f('0xd')](handleError(_0x12f7e5,null));};exports[_0x697f('0x55')]=function(_0x2a952f,_0x3c6118){return respondWithRpcPromise(_0x697f('0x56'),_0x2a952f[_0x697f('0x17')],routingClient)['then'](respondWithResult(_0x3c6118,null))[_0x697f('0xd')](handleError(_0x3c6118,null));};exports[_0x697f('0x57')]=function(_0x43f09f,_0x1ca379){return respondWithRpcPromise(_0x697f('0x58'),_0x43f09f['query'],routingClient)[_0x697f('0x18')](respondWithResult(_0x1ca379,null))['catch'](handleError(_0x1ca379,null));};exports[_0x697f('0x59')]=function(_0x278831,_0x11fdc1){return respondWithRpcPromise(_0x697f('0x5a'),_0x278831['query'],routingClient)['then'](respondWithResult(_0x11fdc1,null))['catch'](handleError(_0x11fdc1,null));};exports[_0x697f('0x5b')]=function(_0x19c3eb,_0x649796){return respondWithRpcPromise('OpenchannelQueuesWaitingInteractions',_0x19c3eb[_0x697f('0x17')],routingClient)[_0x697f('0x18')](function(_0x4fe7fa){if(_0x19c3eb[_0x697f('0x17')][_0x697f('0x5c')]!==undefined){var _0x248639=_(_0x4fe7fa[_0x697f('0x13')])['filter']([_0x19c3eb[_0x697f('0x17')][_0x697f('0x5c')],_0x19c3eb[_0x697f('0x1b')]['id']])[_0x697f('0x5d')](_0x697f('0x5e'))[_0x697f('0x5f')]()[_0x697f('0x60')]();return _0x4fe7fa[_0x697f('0x13')]['filter'](function(_0x1afc4d){return _0x248639[_0x697f('0x61')](_0x1afc4d[_0x697f('0x5e')])>-0x1;});}else{return _0x4fe7fa['rows'][_0x697f('0x62')](function(_0x486504){return _0x486504[_0x697f('0x5e')]===parseInt(_0x19c3eb[_0x697f('0x1b')]['id']);});}})[_0x697f('0x18')](respondWithResult(_0x649796,null))[_0x697f('0xd')](handleError(_0x649796,null));};exports[_0x697f('0x63')]=function(_0x412077,_0x4ec986){return respondWithRpcPromise('SmsQueuesWaitingInteractions',_0x412077['query'],routingClient)['then'](respondWithResult(_0x4ec986,null))[_0x697f('0xd')](handleError(_0x4ec986,null));};exports[_0x697f('0x64')]=function(_0x33e5ed,_0x1bd656){return respondWithRpcPromise(_0x697f('0x65'),_0x33e5ed[_0x697f('0x17')],routingClient)[_0x697f('0x18')](respondWithResult(_0x1bd656,null))[_0x697f('0xd')](handleError(_0x1bd656,null));};exports[_0x697f('0x66')]=function(_0x2eff73,_0x5981f3){return respondWithRpcPromise(_0x697f('0x67'),_0x2eff73[_0x697f('0x17')],routingClient)[_0x697f('0x18')](respondWithResult(_0x5981f3,null))['catch'](handleError(_0x5981f3,null));};exports[_0x697f('0x68')]=function(_0x2057e2){return function(_0x219e68,_0x49272a){var _0x211567,_0x5d655a;var _0x5b5a78=_['capitalize'](_0x2057e2);var _0x427b06=_0x2057e2===_0x697f('0x69')?_0x697f('0x6a'):'Account';return db[_0x5b5a78+_0x697f('0x6b')][_0x697f('0x6c')]({'raw':!![],'where':{'id':_0x219e68[_0x697f('0x1b')]['id']}})['then'](function(_0x3a29e4){if(_['isNil'](_0x3a29e4)){throw new Error(_0x5b5a78+_0x697f('0x6d'));}_0x211567=_0x3a29e4;return db[_0x5b5a78+_0x697f('0x6e')][_0x697f('0x6c')]({'where':{'id':_0x219e68[_0x697f('0x23')][_0x697f('0x6f')]},'include':[{'model':db[_0x5b5a78+'Interaction'],'as':_0x697f('0x70')},{'model':db[_0x5b5a78+_0x427b06],'as':'Account'}]});})[_0x697f('0x18')](function(_0x46797f){if(_['isNil'](_0x46797f)){throw new Error(_0x5b5a78+_0x697f('0x71'));}_0x5d655a=_0x46797f;return _0x46797f[_0x697f('0x72')]({'read':0x0,'readAt':null,'UserId':null});})[_0x697f('0x18')](function(){var _0x27ce95={'uniqueid':_0x2057e2+'.'+_0x5d655a['id']+'.'+_0x5d655a['Interaction']['id'],'FromUserId':_0x219e68[_0x697f('0x30')]['id'],'type':_0x697f('0x73')};_0x27ce95[_0x5b5a78+_0x697f('0x74')]=_0x5d655a['id'];_0x27ce95[_0x5b5a78+_0x697f('0x75')]=_0x5d655a[_0x697f('0x70')]['id'];_0x27ce95[_0x697f('0x76')+_0x5b5a78+_0x427b06+'Id']=_0x5d655a[_0x697f('0x77')]['id'];_0x27ce95['To'+_0x5b5a78+_0x697f('0x78')]=_0x211567['id'];return db[_0x5b5a78+_0x697f('0x79')][_0x697f('0x7a')](_0x27ce95);})['then'](function(){return respondWithRpcPromise(_0x697f('0x7b'),{'channel':_0x2057e2,'interaction':_0x5d655a[_0x697f('0x70')],'message':_0x5d655a,'account':_0x5d655a['Account'],'applications':[{'id':0x0,'priority':0x1,'app':_0x697f('0x73'),'appdata':_0x211567['name']+','+(_0x5d655a[_0x697f('0x77')][_0x697f('0x7c')]||0x12c),'interval':_0x697f('0x7d')}]},routingClient);})['then'](respondWithResult(_0x49272a,null))[_0x697f('0xd')](handleError(_0x49272a,null));};};exports['agentNotify']=function(_0x5159ba,_0x1a8479){var _0x5b3f9d,_0x1ff1b1;if(_[_0x697f('0x12')](_0x5159ba[_0x697f('0x23')][_0x697f('0x7e')])){throw new Error(_0x697f('0x7f'));}var _0x53e0c3=_0x5159ba[_0x697f('0x23')][_0x697f('0x7e')];var _0x29c447=_[_0x697f('0x80')](_0x53e0c3);var _0x10a8c9=_0x53e0c3===_0x697f('0x69')?_0x697f('0x6a'):'Account';return db[_0x697f('0x81')][_0x697f('0x6c')]({'raw':!![],'where':{'id':_0x5159ba[_0x697f('0x1b')]['id'],'role':_0x697f('0x3b')}})[_0x697f('0x18')](function(_0x11c7d2){if(_['isNil'](_0x11c7d2)){throw new Error(_0x697f('0x82'));}_0x5b3f9d=_0x11c7d2;return db[_0x29c447+_0x697f('0x6e')][_0x697f('0x6c')]({'where':{'id':_0x5159ba[_0x697f('0x23')][_0x697f('0x6f')]},'include':[{'model':db[_0x29c447+_0x697f('0x70')],'as':_0x697f('0x70')},{'model':db[_0x29c447+_0x10a8c9],'as':'Account'}]});})[_0x697f('0x18')](function(_0x227554){if(_[_0x697f('0x12')](_0x227554)){throw new Error(_0x29c447+_0x697f('0x71'));}_0x1ff1b1=_0x227554;return _0x227554[_0x697f('0x72')]({'read':0x0,'readAt':null,'UserId':null});})[_0x697f('0x18')](function(){var _0x503c30={'uniqueid':_0x53e0c3+'.'+_0x1ff1b1['id']+'.'+_0x1ff1b1['Interaction']['id'],'FromUserId':_0x5159ba[_0x697f('0x30')]['id'],'type':_0x697f('0x73'),'ToUserId':_0x5b3f9d['id']};_0x503c30[_0x29c447+_0x697f('0x74')]=_0x1ff1b1['id'];_0x503c30[_0x29c447+_0x697f('0x75')]=_0x1ff1b1[_0x697f('0x70')]['id'];_0x503c30['From'+_0x29c447+_0x10a8c9+'Id']=_0x1ff1b1[_0x697f('0x77')]['id'];return db[_0x29c447+_0x697f('0x79')][_0x697f('0x7a')](_0x503c30);})[_0x697f('0x18')](function(){return respondWithRpcPromise(_0x697f('0x7b'),{'channel':_0x53e0c3,'interaction':_0x1ff1b1[_0x697f('0x70')],'message':_0x1ff1b1,'account':_0x1ff1b1[_0x697f('0x77')],'applications':[{'id':0x0,'priority':0x1,'app':_0x697f('0x3b'),'appdata':_0x5b3f9d[_0x697f('0x11')]+','+(_0x1ff1b1[_0x697f('0x77')][_0x697f('0x83')]||0x12c),'interval':_0x697f('0x7d')}]},routingClient);})[_0x697f('0x18')](respondWithResult(_0x1a8479,null))[_0x697f('0xd')](handleError(_0x1a8479,null));};