c75b751c410d52ecc9d4c3c2eb70cbc245267380
[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 _0xb458=['InteractionId','TransferReport','agentTransferTimeout','bluebird','moment','lodash','../../config/logger','api','jayson/promise','client','http','request','then','error','code','catch','status','json','sendStatus','stack','name','send','isNil','rows','find','voiceChannels','VoiceChannels','voiceChannelMixMonitor','VoiceChannelMixMonitor','merge','query','VoiceChannelStopMixMonitor','params','showVoiceQueues','VoiceQueues','updateVoiceQueue','UpdateVoiceQueue','body','voiceQueuesPreview','VoiceQueuesPreview','voiceQueuesChannels','VoiceQueuesChannels','VoiceQueuesChannel','voiceQueuesChannelHangup','voiceQueuesChannelRedirect','VoiceQueuesChannelRedirect','outbound','Outbound','outboundChannels','OutboundChannels','Agents','agentCapacity','interaction','user','hasOwnProperty','findAll','INTERACTION','format','YYYY-MM-DD\x20HH:mm:ss','length','updateAttributes','MemberReport','interface','SIP/%s','agent','internal','AgentCapacity','capacity','Telephones','trunks','Trunks','Campaigns','ChatQueues','showChatQueues','MailQueues','showMailQueues','mailAccounts','MailAccounts','openchannelQueues','OpenchannelQueues','smsQueues','SmsQueues','WhatsappQueues','showFaxQueues','FaxQueues','FaxAccounts','chatQueuesWaitingInteractions','ChatQueuesWaitingInteractions','mailQueuesWaitingInteractions','MailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','OpenchannelQueuesWaitingInteractions','openchannelQueuesIdWaitingInteractions','type','filter','map','queue_id','uniq','value','indexOf','smsQueuesWaitingInteractions','WhatsappQueuesWaitingInteractions','faxQueuesWaitingInteractions','FaxQueuesWaitingInteractions','queueNotify','capitalize','chat','Website','Account','Queue','Message','Interaction','update','queue','MessageId','From','QueueId','create','Start','queueTransferTimeout','*,*,*,*','agentNotify','channel','User','findOne','Agent\x20not\x20found','messageId','\x20Message\x20not\x20found'];(function(_0x7c2bce,_0x370cf3){var _0xc7ae58=function(_0x1ad430){while(--_0x1ad430){_0x7c2bce['push'](_0x7c2bce['shift']());}};_0xc7ae58(++_0x370cf3);}(_0xb458,0x103));var _0x8b45=function(_0x24ae77,_0x1fcf25){_0x24ae77=_0x24ae77-0x0;var _0x8e7cd5=_0xb458[_0x24ae77];return _0x8e7cd5;};'use strict';var BPromise=require(_0x8b45('0x0'));var moment=require(_0x8b45('0x1'));var _=require(_0x8b45('0x2'));var util=require('util');var db=require('../../mysqldb')['db'];var logger=require(_0x8b45('0x3'))(_0x8b45('0x4'));var jayson=require(_0x8b45('0x5'));var amiClient=jayson[_0x8b45('0x6')]['http']({'port':0x232a});var mailClient=jayson[_0x8b45('0x6')]['http']({'port':0x232b});var routingClient=jayson['client'][_0x8b45('0x7')]({'port':0x232c});function respondWithRpcPromise(_0x12bd05,_0x2daa9a,_0x3a8ccb){return new BPromise(function(_0x32342f,_0x4d1718){var _0xa54725=_0x3a8ccb?_0x3a8ccb:amiClient;return _0xa54725[_0x8b45('0x8')](_0x12bd05,_0x2daa9a)[_0x8b45('0x9')](function(_0x2bc809){if(_0x2bc809[_0x8b45('0xa')]){if(_0x2bc809['error'][_0x8b45('0xb')]===0x1f4){return _0x4d1718(_0x2bc809[_0x8b45('0xa')]['message']);}return _0x32342f(_0x2bc809['error']['message']);}else{_0x32342f(_0x2bc809['result']);}})[_0x8b45('0xc')](function(_0x285728){_0x4d1718(_0x285728);});});}function respondWithResult(_0x37c220,_0x52c4db){_0x52c4db=_0x52c4db||0xc8;return function(_0x30d38c){if(_0x30d38c){return _0x37c220[_0x8b45('0xd')](_0x52c4db)[_0x8b45('0xe')](_0x30d38c);}return _0x37c220[_0x8b45('0xf')](0x194);};}function handleError(_0x32babc,_0x2ad2ae){_0x2ad2ae=_0x2ad2ae||0x1f4;return function(_0x5f0b20){logger['error'](_0x5f0b20[_0x8b45('0x10')]);if(_0x5f0b20[_0x8b45('0x11')]){delete _0x5f0b20[_0x8b45('0x11')];}_0x32babc[_0x8b45('0xd')](_0x2ad2ae)[_0x8b45('0x12')](_0x5f0b20);};}function findById(_0x27ebb3){return function(_0x902c50){if(!_[_0x8b45('0x13')](_0x27ebb3)&&!_[_0x8b45('0x13')](_0x902c50)&&!_[_0x8b45('0x13')](_0x902c50[_0x8b45('0x14')])){return _[_0x8b45('0x15')](_0x902c50[_0x8b45('0x14')],function(_0x43ffb7){return _0x43ffb7['id']==_0x27ebb3;});}return null;};}exports[_0x8b45('0x16')]=function(_0x31c6b4,_0x23c520){return respondWithRpcPromise(_0x8b45('0x17'),_0x31c6b4['query'])[_0x8b45('0x9')](respondWithResult(_0x23c520,null))[_0x8b45('0xc')](handleError(_0x23c520,null));};exports[_0x8b45('0x18')]=function(_0x46e21a,_0x3e1438){return respondWithRpcPromise(_0x8b45('0x19'),_[_0x8b45('0x1a')](_0x46e21a[_0x8b45('0x1b')],_0x46e21a['params']))['then'](respondWithResult(_0x3e1438,null))[_0x8b45('0xc')](handleError(_0x3e1438,null));};exports['voiceChannelStopMixMonitor']=function(_0x1952fc,_0x3ddb50){return respondWithRpcPromise(_0x8b45('0x1c'),_[_0x8b45('0x1a')](_0x1952fc[_0x8b45('0x1b')],_0x1952fc[_0x8b45('0x1d')]))[_0x8b45('0x9')](respondWithResult(_0x3ddb50,null))['catch'](handleError(_0x3ddb50,null));};exports['voiceQueues']=function(_0x11ffcc,_0x2c2c06){return respondWithRpcPromise('VoiceQueues',_0x11ffcc['query'])[_0x8b45('0x9')](respondWithResult(_0x2c2c06,null))[_0x8b45('0xc')](handleError(_0x2c2c06,null));};exports[_0x8b45('0x1e')]=function(_0x2f37bc,_0x4e84cc){return respondWithRpcPromise(_0x8b45('0x1f'),_0x2f37bc[_0x8b45('0x1b')])[_0x8b45('0x9')](findById(_0x2f37bc[_0x8b45('0x1d')]['id']))[_0x8b45('0x9')](respondWithResult(_0x4e84cc,null))[_0x8b45('0xc')](handleError(_0x4e84cc,null));};exports[_0x8b45('0x20')]=function(_0x234f62,_0x1733a7){return respondWithRpcPromise(_0x8b45('0x21'),_[_0x8b45('0x1a')](_0x234f62[_0x8b45('0x22')],_0x234f62[_0x8b45('0x1d')]))['then'](respondWithResult(_0x1733a7,null))[_0x8b45('0xc')](handleError(_0x1733a7,null));};exports[_0x8b45('0x23')]=function(_0x34eb03,_0x15107a){return respondWithRpcPromise(_0x8b45('0x24'),_[_0x8b45('0x1a')](_0x34eb03[_0x8b45('0x1b')],_0x34eb03[_0x8b45('0x1d')]))['then'](respondWithResult(_0x15107a,null))[_0x8b45('0xc')](handleError(_0x15107a,null));};exports[_0x8b45('0x25')]=function(_0x50302,_0xc2ae94){return respondWithRpcPromise(_0x8b45('0x26'),_0x50302['query'])[_0x8b45('0x9')](respondWithResult(_0xc2ae94,null))['catch'](handleError(_0xc2ae94,null));};exports['voiceQueuesChannel']=function(_0x1f8a11,_0x94e3b6){return respondWithRpcPromise(_0x8b45('0x27'),_[_0x8b45('0x1a')](_0x1f8a11[_0x8b45('0x1b')],_0x1f8a11[_0x8b45('0x1d')]))['then'](respondWithResult(_0x94e3b6,null))[_0x8b45('0xc')](handleError(_0x94e3b6,null));};exports[_0x8b45('0x28')]=function(_0x264be7,_0x1f66a3){return respondWithRpcPromise('VoiceQueuesChannelHangup',_[_0x8b45('0x1a')](_0x264be7[_0x8b45('0x1b')],_0x264be7[_0x8b45('0x1d')]))['then'](respondWithResult(_0x1f66a3,null))[_0x8b45('0xc')](handleError(_0x1f66a3,null));};exports[_0x8b45('0x29')]=function(_0x1571b7,_0x58f32e){return respondWithRpcPromise(_0x8b45('0x2a'),_[_0x8b45('0x1a')](_0x1571b7[_0x8b45('0x1b')],_0x1571b7[_0x8b45('0x1d')]))['then'](respondWithResult(_0x58f32e,null))[_0x8b45('0xc')](handleError(_0x58f32e,null));};exports[_0x8b45('0x2b')]=function(_0x2de02d,_0x15df7c){return respondWithRpcPromise(_0x8b45('0x2c'),_0x2de02d[_0x8b45('0x1b')])['then'](respondWithResult(_0x15df7c,null))['catch'](handleError(_0x15df7c,null));};exports[_0x8b45('0x2d')]=function(_0x179f3b,_0x41d6b5){return respondWithRpcPromise(_0x8b45('0x2e'),_0x179f3b[_0x8b45('0x1b')])['then'](respondWithResult(_0x41d6b5,null))[_0x8b45('0xc')](handleError(_0x41d6b5,null));};exports['agents']=function(_0x67c59a,_0x17e9a8){var _0x5fae26;return respondWithRpcPromise(_0x8b45('0x2f'),_0x67c59a[_0x8b45('0x1b')])[_0x8b45('0x9')](function(_0x14d665){_0x5fae26=_0x14d665;return respondWithRpcPromise(_0x8b45('0x2f'),_0x67c59a[_0x8b45('0x1b')],routingClient);})[_0x8b45('0x9')](function(_0x3a97d5){return _['merge']({},_0x3a97d5,_0x5fae26);})[_0x8b45('0x9')](respondWithResult(_0x17e9a8,null))['catch'](handleError(_0x17e9a8,null));};exports[_0x8b45('0x30')]=function(_0x4eda71,_0x412c53){if(_0x4eda71[_0x8b45('0x22')]&&_0x4eda71[_0x8b45('0x22')][_0x8b45('0x31')]&&_0x4eda71[_0x8b45('0x32')]&&_0x4eda71[_0x8b45('0x32')]['name']){for(var _0x6fbca4 in _0x4eda71['body']['interaction']){if(_0x4eda71[_0x8b45('0x22')][_0x8b45('0x31')][_0x8b45('0x33')](_0x6fbca4)){db['MemberReport'][_0x8b45('0x34')]({'where':{'channel':_0x6fbca4,'membername':_0x4eda71['user'][_0x8b45('0x11')],'type':_0x8b45('0x35'),'exitAt':null,'uniqueid':_0x4eda71[_0x8b45('0x22')][_0x8b45('0x31')][_0x6fbca4]&&_0x4eda71[_0x8b45('0x22')][_0x8b45('0x31')][_0x6fbca4]['length']?{'$notIn':_0x4eda71[_0x8b45('0x22')][_0x8b45('0x31')][_0x6fbca4]}:{'$ne':null}}})[_0x8b45('0x9')](function(_0xee45ac){var _0x1a13dd=moment()[_0x8b45('0x36')](_0x8b45('0x37'));for(var _0x3de3c2=0x0,_0x37b94a=_0xee45ac[_0x8b45('0x38')];_0x3de3c2<_0x37b94a;_0x3de3c2+=0x1){_0xee45ac[_0x3de3c2][_0x8b45('0x39')]({'exitAt':_0x1a13dd});}});for(var _0x3385db=0x0;_0x3385db<_0x4eda71[_0x8b45('0x22')][_0x8b45('0x31')][_0x6fbca4][_0x8b45('0x38')];_0x3385db+=0x1){db[_0x8b45('0x3a')]['findOrCreate']({'where':{'channel':_0x6fbca4,'membername':_0x4eda71['user']['name'],'type':_0x8b45('0x35'),'uniqueid':_0x4eda71[_0x8b45('0x22')][_0x8b45('0x31')][_0x6fbca4][_0x3385db],'exitAt':null},'defaults':{'channel':_0x6fbca4,'membername':_0x4eda71[_0x8b45('0x32')][_0x8b45('0x11')],'interface':_[_0x8b45('0x13')](_0x4eda71[_0x8b45('0x32')][_0x8b45('0x3b')])?util['format'](_0x8b45('0x3c'),_0x4eda71['user'][_0x8b45('0x11')]):_0x4eda71[_0x8b45('0x32')][_0x8b45('0x3b')],'type':_0x8b45('0x35'),'enterAt':moment()['format'](_0x8b45('0x37')),'role':_0x8b45('0x3d'),'internal':_0x4eda71['user'][_0x8b45('0x3e')],'uniqueid':_0x4eda71[_0x8b45('0x22')]['interaction'][_0x6fbca4][_0x3385db]}});}}}}return respondWithRpcPromise(_0x8b45('0x3f'),{'id':_0x4eda71[_0x8b45('0x1d')]['id'],'capacity':_0x4eda71[_0x8b45('0x22')][_0x8b45('0x40')]},routingClient)[_0x8b45('0x9')](respondWithResult(_0x412c53,null))[_0x8b45('0xc')](handleError(_0x412c53,null));};exports['telephones']=function(_0x4b8826,_0x3f7a16){return respondWithRpcPromise(_0x8b45('0x41'),_0x4b8826[_0x8b45('0x1b')])['then'](respondWithResult(_0x3f7a16,null))[_0x8b45('0xc')](handleError(_0x3f7a16,null));};exports[_0x8b45('0x42')]=function(_0x20a68b,_0x3e8a7d){return respondWithRpcPromise(_0x8b45('0x43'),_0x20a68b['query'])[_0x8b45('0x9')](respondWithResult(_0x3e8a7d,null))[_0x8b45('0xc')](handleError(_0x3e8a7d,null));};exports['campaigns']=function(_0x422da0,_0x4c3f38){return respondWithRpcPromise(_0x8b45('0x44'),_0x422da0[_0x8b45('0x1b')])[_0x8b45('0x9')](respondWithResult(_0x4c3f38,null))[_0x8b45('0xc')](handleError(_0x4c3f38,null));};exports['chatQueues']=function(_0xb9f390,_0x423231){return respondWithRpcPromise(_0x8b45('0x45'),_0xb9f390[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](respondWithResult(_0x423231,null))[_0x8b45('0xc')](handleError(_0x423231,null));};exports[_0x8b45('0x46')]=function(_0x2a35c1,_0x446fe5){return respondWithRpcPromise(_0x8b45('0x45'),_0x2a35c1[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](findById(_0x2a35c1[_0x8b45('0x1d')]['id']))[_0x8b45('0x9')](respondWithResult(_0x446fe5,null))[_0x8b45('0xc')](handleError(_0x446fe5,null));};exports['mailQueues']=function(_0x1744f8,_0x1477bd){return respondWithRpcPromise(_0x8b45('0x47'),_0x1744f8['query'],routingClient)[_0x8b45('0x9')](respondWithResult(_0x1477bd,null))[_0x8b45('0xc')](handleError(_0x1477bd,null));};exports[_0x8b45('0x48')]=function(_0x9eacc1,_0x5795ca){return respondWithRpcPromise(_0x8b45('0x47'),_0x9eacc1[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](findById(_0x9eacc1[_0x8b45('0x1d')]['id']))['then'](respondWithResult(_0x5795ca,null))[_0x8b45('0xc')](handleError(_0x5795ca,null));};exports[_0x8b45('0x49')]=function(_0x417778,_0x27503f){return respondWithRpcPromise(_0x8b45('0x4a'),_0x417778['query'],mailClient)[_0x8b45('0x9')](respondWithResult(_0x27503f,null))['catch'](handleError(_0x27503f,null));};exports[_0x8b45('0x4b')]=function(_0x2f7ab0,_0x19152b){return respondWithRpcPromise(_0x8b45('0x4c'),_0x2f7ab0[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](respondWithResult(_0x19152b,null))['catch'](handleError(_0x19152b,null));};exports['showOpenchannelQueues']=function(_0x5ace1,_0x2224b7){return respondWithRpcPromise('OpenchannelQueues',_0x5ace1[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](findById(_0x5ace1[_0x8b45('0x1d')]['id']))['then'](respondWithResult(_0x2224b7,null))['catch'](handleError(_0x2224b7,null));};exports[_0x8b45('0x4d')]=function(_0x8e5a41,_0x5abc79){return respondWithRpcPromise(_0x8b45('0x4e'),_0x8e5a41['query'],routingClient)[_0x8b45('0x9')](respondWithResult(_0x5abc79,null))['catch'](handleError(_0x5abc79,null));};exports['showSmsQueues']=function(_0x28e57a,_0x7f5a4e){return respondWithRpcPromise('SmsQueues',_0x28e57a[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](findById(_0x28e57a[_0x8b45('0x1d')]['id']))[_0x8b45('0x9')](respondWithResult(_0x7f5a4e,null))[_0x8b45('0xc')](handleError(_0x7f5a4e,null));};exports['whatsappQueues']=function(_0x37f580,_0x3b3d21){return respondWithRpcPromise(_0x8b45('0x4f'),_0x37f580['query'],routingClient)['then'](respondWithResult(_0x3b3d21,null))[_0x8b45('0xc')](handleError(_0x3b3d21,null));};exports['showWhatsappQueues']=function(_0x43f031,_0x5a4834){return respondWithRpcPromise('WhatsappQueues',_0x43f031['query'],routingClient)[_0x8b45('0x9')](findById(_0x43f031['params']['id']))[_0x8b45('0x9')](respondWithResult(_0x5a4834,null))[_0x8b45('0xc')](handleError(_0x5a4834,null));};exports['faxQueues']=function(_0x3db84e,_0x1b3890){return respondWithRpcPromise('FaxQueues',_0x3db84e[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](respondWithResult(_0x1b3890,null))[_0x8b45('0xc')](handleError(_0x1b3890,null));};exports[_0x8b45('0x50')]=function(_0x15cf9d,_0x877766){return respondWithRpcPromise(_0x8b45('0x51'),_0x15cf9d[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](findById(_0x15cf9d[_0x8b45('0x1d')]['id']))[_0x8b45('0x9')](respondWithResult(_0x877766,null))[_0x8b45('0xc')](handleError(_0x877766,null));};exports['faxAccounts']=function(_0x225180,_0x403ee2){return respondWithRpcPromise(_0x8b45('0x52'),_0x225180[_0x8b45('0x1b')])[_0x8b45('0x9')](respondWithResult(_0x403ee2,null))[_0x8b45('0xc')](handleError(_0x403ee2,null));};exports[_0x8b45('0x53')]=function(_0x3d3216,_0x243632){return respondWithRpcPromise(_0x8b45('0x54'),_0x3d3216[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](respondWithResult(_0x243632,null))[_0x8b45('0xc')](handleError(_0x243632,null));};exports[_0x8b45('0x55')]=function(_0x562c5f,_0x53143d){return respondWithRpcPromise(_0x8b45('0x56'),_0x562c5f[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](respondWithResult(_0x53143d,null))[_0x8b45('0xc')](handleError(_0x53143d,null));};exports[_0x8b45('0x57')]=function(_0xd88538,_0x1ebbca){return respondWithRpcPromise(_0x8b45('0x58'),_0xd88538['query'],routingClient)[_0x8b45('0x9')](respondWithResult(_0x1ebbca,null))[_0x8b45('0xc')](handleError(_0x1ebbca,null));};exports[_0x8b45('0x59')]=function(_0xa22bd0,_0xa44ba5){return respondWithRpcPromise(_0x8b45('0x58'),_0xa22bd0[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](function(_0x2a6fee){if(_0xa22bd0[_0x8b45('0x1b')][_0x8b45('0x5a')]!==undefined){var _0x5e54c6=_(_0x2a6fee['rows'])[_0x8b45('0x5b')]([_0xa22bd0[_0x8b45('0x1b')][_0x8b45('0x5a')],_0xa22bd0[_0x8b45('0x1d')]['id']])[_0x8b45('0x5c')](_0x8b45('0x5d'))[_0x8b45('0x5e')]()[_0x8b45('0x5f')]();return _0x2a6fee[_0x8b45('0x14')]['filter'](function(_0x55acf0){return _0x5e54c6[_0x8b45('0x60')](_0x55acf0[_0x8b45('0x5d')])>-0x1;});}else{return _0x2a6fee[_0x8b45('0x14')][_0x8b45('0x5b')](function(_0x55bafb){return _0x55bafb[_0x8b45('0x5d')]===parseInt(_0xa22bd0[_0x8b45('0x1d')]['id']);});}})[_0x8b45('0x9')](respondWithResult(_0xa44ba5,null))[_0x8b45('0xc')](handleError(_0xa44ba5,null));};exports[_0x8b45('0x61')]=function(_0x17588b,_0x4ed113){return respondWithRpcPromise('SmsQueuesWaitingInteractions',_0x17588b[_0x8b45('0x1b')],routingClient)['then'](respondWithResult(_0x4ed113,null))['catch'](handleError(_0x4ed113,null));};exports['whatsappQueuesWaitingInteractions']=function(_0xf602c7,_0x170b95){return respondWithRpcPromise(_0x8b45('0x62'),_0xf602c7[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](respondWithResult(_0x170b95,null))[_0x8b45('0xc')](handleError(_0x170b95,null));};exports[_0x8b45('0x63')]=function(_0xc9be77,_0xc89fc6){return respondWithRpcPromise(_0x8b45('0x64'),_0xc9be77[_0x8b45('0x1b')],routingClient)[_0x8b45('0x9')](respondWithResult(_0xc89fc6,null))[_0x8b45('0xc')](handleError(_0xc89fc6,null));};exports[_0x8b45('0x65')]=function(_0x42b192){return function(_0x4a42e1,_0x29bfcc){var _0x91270d,_0x217798;var _0x19a135=_[_0x8b45('0x66')](_0x42b192);var _0x1446b1=_0x42b192===_0x8b45('0x67')?_0x8b45('0x68'):_0x8b45('0x69');return db[_0x19a135+_0x8b45('0x6a')]['findOne']({'raw':!![],'where':{'id':_0x4a42e1[_0x8b45('0x1d')]['id']}})[_0x8b45('0x9')](function(_0x408fff){if(_[_0x8b45('0x13')](_0x408fff)){throw new Error(_0x19a135+'\x20Queue\x20not\x20found');}_0x91270d=_0x408fff;return db[_0x19a135+_0x8b45('0x6b')]['findOne']({'where':{'id':_0x4a42e1[_0x8b45('0x22')]['messageId']},'include':[{'model':db[_0x19a135+_0x8b45('0x6c')],'as':_0x8b45('0x6c')},{'model':db[_0x19a135+_0x1446b1],'as':_0x8b45('0x69')}]});})[_0x8b45('0x9')](function(_0x16bb83){if(_[_0x8b45('0x13')](_0x16bb83)){throw new Error(_0x19a135+'\x20Message\x20not\x20found');}_0x217798=_0x16bb83;return _0x16bb83[_0x8b45('0x6d')]({'read':0x0,'readAt':null,'UserId':null});})[_0x8b45('0x9')](function(){var _0x17364d={'uniqueid':_0x42b192+'.'+_0x217798['id']+'.'+_0x217798[_0x8b45('0x6c')]['id'],'FromUserId':_0x4a42e1['user']['id'],'type':_0x8b45('0x6e')};_0x17364d[_0x19a135+_0x8b45('0x6f')]=_0x217798['id'];_0x17364d[_0x19a135+'InteractionId']=_0x217798['Interaction']['id'];_0x17364d[_0x8b45('0x70')+_0x19a135+_0x1446b1+'Id']=_0x217798[_0x8b45('0x69')]['id'];_0x17364d['To'+_0x19a135+_0x8b45('0x71')]=_0x91270d['id'];return db[_0x19a135+'TransferReport'][_0x8b45('0x72')](_0x17364d);})['then'](function(){return respondWithRpcPromise(_0x8b45('0x73'),{'channel':_0x42b192,'interaction':_0x217798[_0x8b45('0x6c')],'message':_0x217798,'account':_0x217798['Account'],'applications':[{'id':0x0,'priority':0x1,'app':'queue','appdata':_0x91270d[_0x8b45('0x11')]+','+(_0x217798[_0x8b45('0x69')][_0x8b45('0x74')]||0x12c),'interval':_0x8b45('0x75')}]},routingClient);})['then'](respondWithResult(_0x29bfcc,null))[_0x8b45('0xc')](handleError(_0x29bfcc,null));};};exports[_0x8b45('0x76')]=function(_0x376416,_0x1d475c){var _0x2680d5,_0x1abe69;if(_['isNil'](_0x376416[_0x8b45('0x22')][_0x8b45('0x77')])){throw new Error('Channel\x20field\x20is\x20mandatory');}var _0x10a91a=_0x376416[_0x8b45('0x22')]['channel'];var _0x4837af=_['capitalize'](_0x10a91a);var _0x186aa2=_0x10a91a===_0x8b45('0x67')?_0x8b45('0x68'):_0x8b45('0x69');return db[_0x8b45('0x78')][_0x8b45('0x79')]({'raw':!![],'where':{'id':_0x376416[_0x8b45('0x1d')]['id'],'role':'agent'}})[_0x8b45('0x9')](function(_0x3d321f){if(_[_0x8b45('0x13')](_0x3d321f)){throw new Error(_0x8b45('0x7a'));}_0x2680d5=_0x3d321f;return db[_0x4837af+_0x8b45('0x6b')][_0x8b45('0x79')]({'where':{'id':_0x376416['body'][_0x8b45('0x7b')]},'include':[{'model':db[_0x4837af+_0x8b45('0x6c')],'as':_0x8b45('0x6c')},{'model':db[_0x4837af+_0x186aa2],'as':_0x8b45('0x69')}]});})[_0x8b45('0x9')](function(_0x4c3bc9){if(_['isNil'](_0x4c3bc9)){throw new Error(_0x4837af+_0x8b45('0x7c'));}_0x1abe69=_0x4c3bc9;return _0x4c3bc9[_0x8b45('0x6d')]({'read':0x0,'readAt':null,'UserId':null});})[_0x8b45('0x9')](function(){var _0x9993ce={'uniqueid':_0x10a91a+'.'+_0x1abe69['id']+'.'+_0x1abe69[_0x8b45('0x6c')]['id'],'FromUserId':_0x376416['user']['id'],'type':_0x8b45('0x6e'),'ToUserId':_0x2680d5['id']};_0x9993ce[_0x4837af+'MessageId']=_0x1abe69['id'];_0x9993ce[_0x4837af+_0x8b45('0x7d')]=_0x1abe69['Interaction']['id'];_0x9993ce[_0x8b45('0x70')+_0x4837af+_0x186aa2+'Id']=_0x1abe69[_0x8b45('0x69')]['id'];return db[_0x4837af+_0x8b45('0x7e')][_0x8b45('0x72')](_0x9993ce);})[_0x8b45('0x9')](function(){return respondWithRpcPromise(_0x8b45('0x73'),{'channel':_0x10a91a,'interaction':_0x1abe69[_0x8b45('0x6c')],'message':_0x1abe69,'account':_0x1abe69[_0x8b45('0x69')],'applications':[{'id':0x0,'priority':0x1,'app':_0x8b45('0x3d'),'appdata':_0x2680d5[_0x8b45('0x11')]+','+(_0x1abe69[_0x8b45('0x69')][_0x8b45('0x7f')]||0x12c),'interval':_0x8b45('0x75')}]},routingClient);})[_0x8b45('0x9')](respondWithResult(_0x1d475c,null))['catch'](handleError(_0x1d475c,null));};