b97a6c10a1866916ac4acf827b6616c1a2089342
[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 _0xf300=['agentNotify','Channel\x20field\x20is\x20mandatory','channel','chat','User','Agent\x20not\x20found','InteractionId','bluebird','moment','lodash','util','../../mysqldb','../../config/logger','api','jayson/promise','client','http','then','error','message','catch','status','sendStatus','stack','name','send','isNil','rows','find','voiceChannels','query','voiceChannelMixMonitor','merge','params','voiceQueues','showVoiceQueues','VoiceQueues','voiceQueuesPreview','voiceQueuesChannels','VoiceQueuesChannels','VoiceQueuesChannel','voiceQueuesChannelHangup','VoiceQueuesChannelHangup','voiceQueuesChannelRedirect','VoiceQueuesChannelRedirect','outbound','outboundChannels','OutboundChannels','agents','Agents','agentCapacity','body','interaction','user','MemberReport','INTERACTION','length','format','updateAttributes','findOrCreate','interface','SIP/%s','YYYY-MM-DD\x20HH:mm:ss','agent','internal','AgentCapacity','telephones','Telephones','Trunks','campaigns','Campaigns','chatQueues','ChatQueues','showChatQueues','mailQueues','showMailQueues','mailAccounts','openchannelQueues','OpenchannelQueues','showOpenchannelQueues','SmsQueues','showSmsQueues','WhatsappQueues','showWhatsappQueues','faxQueues','FaxQueues','showFaxQueues','faxAccounts','FaxAccounts','chatQueuesWaitingInteractions','mailQueuesWaitingInteractions','MailQueuesWaitingInteractions','OpenchannelQueuesWaitingInteractions','type','filter','map','queue_id','uniq','indexOf','smsQueuesWaitingInteractions','whatsappQueuesWaitingInteractions','WhatsappQueuesWaitingInteractions','faxQueuesWaitingInteractions','FaxQueuesWaitingInteractions','queueNotify','capitalize','Account','Queue','findOne','Message','messageId','Interaction','\x20Message\x20not\x20found','queue','MessageId','TransferReport','create','Start','*,*,*,*'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xf300,0x16c));var _0x0f30=function(_0x52f159,_0x419d8a){_0x52f159=_0x52f159-0x0;var _0x156799=_0xf300[_0x52f159];return _0x156799;};'use strict';var BPromise=require(_0x0f30('0x0'));var moment=require(_0x0f30('0x1'));var _=require(_0x0f30('0x2'));var util=require(_0x0f30('0x3'));var db=require(_0x0f30('0x4'))['db'];var logger=require(_0x0f30('0x5'))(_0x0f30('0x6'));var jayson=require(_0x0f30('0x7'));var amiClient=jayson[_0x0f30('0x8')][_0x0f30('0x9')]({'port':0x232a});var mailClient=jayson[_0x0f30('0x8')]['http']({'port':0x232b});var routingClient=jayson[_0x0f30('0x8')][_0x0f30('0x9')]({'port':0x232c});function respondWithRpcPromise(_0xf78d18,_0x4da2d5,_0x3eab14){return new BPromise(function(_0x313ddd,_0x415491){var _0x37016a=_0x3eab14?_0x3eab14:amiClient;return _0x37016a['request'](_0xf78d18,_0x4da2d5)[_0x0f30('0xa')](function(_0x3312df){if(_0x3312df[_0x0f30('0xb')]){if(_0x3312df[_0x0f30('0xb')]['code']===0x1f4){return _0x415491(_0x3312df[_0x0f30('0xb')][_0x0f30('0xc')]);}return _0x313ddd(_0x3312df[_0x0f30('0xb')][_0x0f30('0xc')]);}else{_0x313ddd(_0x3312df['result']);}})[_0x0f30('0xd')](function(_0x1a8f65){_0x415491(_0x1a8f65);});});}function respondWithResult(_0x56ae24,_0x4862f5){_0x4862f5=_0x4862f5||0xc8;return function(_0x190399){if(_0x190399){return _0x56ae24[_0x0f30('0xe')](_0x4862f5)['json'](_0x190399);}return _0x56ae24[_0x0f30('0xf')](0x194);};}function handleError(_0x5b75e6,_0x2fc1e4){_0x2fc1e4=_0x2fc1e4||0x1f4;return function(_0x5be9a8){logger[_0x0f30('0xb')](_0x5be9a8[_0x0f30('0x10')]);if(_0x5be9a8['name']){delete _0x5be9a8[_0x0f30('0x11')];}_0x5b75e6[_0x0f30('0xe')](_0x2fc1e4)[_0x0f30('0x12')](_0x5be9a8);};}function findById(_0x1b9c2d){return function(_0x5b1020){if(!_['isNil'](_0x1b9c2d)&&!_[_0x0f30('0x13')](_0x5b1020)&&!_[_0x0f30('0x13')](_0x5b1020[_0x0f30('0x14')])){return _[_0x0f30('0x15')](_0x5b1020[_0x0f30('0x14')],function(_0x25a148){return _0x25a148['id']==_0x1b9c2d;});}return null;};}exports[_0x0f30('0x16')]=function(_0x125524,_0xb0dd60){return respondWithRpcPromise('VoiceChannels',_0x125524[_0x0f30('0x17')])[_0x0f30('0xa')](respondWithResult(_0xb0dd60,null))[_0x0f30('0xd')](handleError(_0xb0dd60,null));};exports[_0x0f30('0x18')]=function(_0x7726ec,_0x244067){return respondWithRpcPromise('VoiceChannelMixMonitor',_[_0x0f30('0x19')](_0x7726ec[_0x0f30('0x17')],_0x7726ec['params']))[_0x0f30('0xa')](respondWithResult(_0x244067,null))[_0x0f30('0xd')](handleError(_0x244067,null));};exports['voiceChannelStopMixMonitor']=function(_0x51c28b,_0x2314ee){return respondWithRpcPromise('VoiceChannelStopMixMonitor',_[_0x0f30('0x19')](_0x51c28b[_0x0f30('0x17')],_0x51c28b[_0x0f30('0x1a')]))[_0x0f30('0xa')](respondWithResult(_0x2314ee,null))[_0x0f30('0xd')](handleError(_0x2314ee,null));};exports[_0x0f30('0x1b')]=function(_0x3d3836,_0x3fa887){return respondWithRpcPromise('VoiceQueues',_0x3d3836[_0x0f30('0x17')])['then'](respondWithResult(_0x3fa887,null))[_0x0f30('0xd')](handleError(_0x3fa887,null));};exports[_0x0f30('0x1c')]=function(_0xb7821a,_0x3dcc9d){return respondWithRpcPromise(_0x0f30('0x1d'),_0xb7821a[_0x0f30('0x17')])[_0x0f30('0xa')](findById(_0xb7821a[_0x0f30('0x1a')]['id']))['then'](respondWithResult(_0x3dcc9d,null))['catch'](handleError(_0x3dcc9d,null));};exports[_0x0f30('0x1e')]=function(_0x1b3450,_0x4eb4a4){return respondWithRpcPromise('VoiceQueuesPreview',_[_0x0f30('0x19')](_0x1b3450['query'],_0x1b3450[_0x0f30('0x1a')]))[_0x0f30('0xa')](respondWithResult(_0x4eb4a4,null))[_0x0f30('0xd')](handleError(_0x4eb4a4,null));};exports[_0x0f30('0x1f')]=function(_0x308abf,_0x36c173){return respondWithRpcPromise(_0x0f30('0x20'),_0x308abf['query'])[_0x0f30('0xa')](respondWithResult(_0x36c173,null))[_0x0f30('0xd')](handleError(_0x36c173,null));};exports['voiceQueuesChannel']=function(_0x266765,_0x5e7c7d){return respondWithRpcPromise(_0x0f30('0x21'),_[_0x0f30('0x19')](_0x266765[_0x0f30('0x17')],_0x266765[_0x0f30('0x1a')]))[_0x0f30('0xa')](respondWithResult(_0x5e7c7d,null))[_0x0f30('0xd')](handleError(_0x5e7c7d,null));};exports[_0x0f30('0x22')]=function(_0x12b8c4,_0x3d6460){return respondWithRpcPromise(_0x0f30('0x23'),_['merge'](_0x12b8c4['query'],_0x12b8c4['params']))[_0x0f30('0xa')](respondWithResult(_0x3d6460,null))[_0x0f30('0xd')](handleError(_0x3d6460,null));};exports[_0x0f30('0x24')]=function(_0x21bb2f,_0x5cbfe5){return respondWithRpcPromise(_0x0f30('0x25'),_[_0x0f30('0x19')](_0x21bb2f[_0x0f30('0x17')],_0x21bb2f[_0x0f30('0x1a')]))[_0x0f30('0xa')](respondWithResult(_0x5cbfe5,null))[_0x0f30('0xd')](handleError(_0x5cbfe5,null));};exports[_0x0f30('0x26')]=function(_0x4f7069,_0x1fd679){return respondWithRpcPromise('Outbound',_0x4f7069[_0x0f30('0x17')])[_0x0f30('0xa')](respondWithResult(_0x1fd679,null))['catch'](handleError(_0x1fd679,null));};exports[_0x0f30('0x27')]=function(_0x5a073b,_0x2c95e5){return respondWithRpcPromise(_0x0f30('0x28'),_0x5a073b[_0x0f30('0x17')])[_0x0f30('0xa')](respondWithResult(_0x2c95e5,null))[_0x0f30('0xd')](handleError(_0x2c95e5,null));};exports[_0x0f30('0x29')]=function(_0x5a1b5a,_0x2061e5){var _0x46634c;return respondWithRpcPromise(_0x0f30('0x2a'),_0x5a1b5a[_0x0f30('0x17')])[_0x0f30('0xa')](function(_0x4fc282){_0x46634c=_0x4fc282;return respondWithRpcPromise(_0x0f30('0x2a'),_0x5a1b5a['query'],routingClient);})[_0x0f30('0xa')](function(_0x4206a9){return _[_0x0f30('0x19')]({},_0x4206a9,_0x46634c);})['then'](respondWithResult(_0x2061e5,null))[_0x0f30('0xd')](handleError(_0x2061e5,null));};exports[_0x0f30('0x2b')]=function(_0x4746ad,_0x4119f1){if(_0x4746ad[_0x0f30('0x2c')]&&_0x4746ad['body'][_0x0f30('0x2d')]&&_0x4746ad[_0x0f30('0x2e')]&&_0x4746ad[_0x0f30('0x2e')][_0x0f30('0x11')]){for(var _0x5acf7b in _0x4746ad[_0x0f30('0x2c')]['interaction']){if(_0x4746ad[_0x0f30('0x2c')][_0x0f30('0x2d')]['hasOwnProperty'](_0x5acf7b)){db[_0x0f30('0x2f')]['findAll']({'where':{'channel':_0x5acf7b,'membername':_0x4746ad[_0x0f30('0x2e')]['name'],'type':_0x0f30('0x30'),'exitAt':null,'uniqueid':_0x4746ad[_0x0f30('0x2c')][_0x0f30('0x2d')][_0x5acf7b]&&_0x4746ad[_0x0f30('0x2c')][_0x0f30('0x2d')][_0x5acf7b][_0x0f30('0x31')]?{'$notIn':_0x4746ad[_0x0f30('0x2c')][_0x0f30('0x2d')][_0x5acf7b]}:{'$ne':null}}})['then'](function(_0x2ba7b8){var _0x35fc47=moment()[_0x0f30('0x32')]('YYYY-MM-DD\x20HH:mm:ss');for(var _0x4b327b=0x0,_0x40b59a=_0x2ba7b8['length'];_0x4b327b<_0x40b59a;_0x4b327b+=0x1){_0x2ba7b8[_0x4b327b][_0x0f30('0x33')]({'exitAt':_0x35fc47});}});for(var _0x568a5d=0x0;_0x568a5d<_0x4746ad['body'][_0x0f30('0x2d')][_0x5acf7b][_0x0f30('0x31')];_0x568a5d+=0x1){db[_0x0f30('0x2f')][_0x0f30('0x34')]({'where':{'channel':_0x5acf7b,'membername':_0x4746ad[_0x0f30('0x2e')]['name'],'type':_0x0f30('0x30'),'uniqueid':_0x4746ad[_0x0f30('0x2c')][_0x0f30('0x2d')][_0x5acf7b][_0x568a5d],'exitAt':null},'defaults':{'channel':_0x5acf7b,'membername':_0x4746ad[_0x0f30('0x2e')]['name'],'interface':_[_0x0f30('0x13')](_0x4746ad['user'][_0x0f30('0x35')])?util[_0x0f30('0x32')](_0x0f30('0x36'),_0x4746ad[_0x0f30('0x2e')][_0x0f30('0x11')]):_0x4746ad[_0x0f30('0x2e')]['interface'],'type':_0x0f30('0x30'),'enterAt':moment()[_0x0f30('0x32')](_0x0f30('0x37')),'role':_0x0f30('0x38'),'internal':_0x4746ad[_0x0f30('0x2e')][_0x0f30('0x39')],'uniqueid':_0x4746ad[_0x0f30('0x2c')]['interaction'][_0x5acf7b][_0x568a5d]}});}}}}return respondWithRpcPromise(_0x0f30('0x3a'),{'id':_0x4746ad['params']['id'],'capacity':_0x4746ad[_0x0f30('0x2c')]['capacity']},routingClient)['then'](respondWithResult(_0x4119f1,null))['catch'](handleError(_0x4119f1,null));};exports[_0x0f30('0x3b')]=function(_0x9e59f1,_0x588c1f){return respondWithRpcPromise(_0x0f30('0x3c'),_0x9e59f1[_0x0f30('0x17')])[_0x0f30('0xa')](respondWithResult(_0x588c1f,null))[_0x0f30('0xd')](handleError(_0x588c1f,null));};exports['trunks']=function(_0x1a1c0e,_0x2dd97a){return respondWithRpcPromise(_0x0f30('0x3d'),_0x1a1c0e[_0x0f30('0x17')])[_0x0f30('0xa')](respondWithResult(_0x2dd97a,null))[_0x0f30('0xd')](handleError(_0x2dd97a,null));};exports[_0x0f30('0x3e')]=function(_0x494ecd,_0x745137){return respondWithRpcPromise(_0x0f30('0x3f'),_0x494ecd[_0x0f30('0x17')])['then'](respondWithResult(_0x745137,null))[_0x0f30('0xd')](handleError(_0x745137,null));};exports[_0x0f30('0x40')]=function(_0x51e381,_0x5cc808){return respondWithRpcPromise(_0x0f30('0x41'),_0x51e381[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](respondWithResult(_0x5cc808,null))['catch'](handleError(_0x5cc808,null));};exports[_0x0f30('0x42')]=function(_0x559e7e,_0x4fec41){return respondWithRpcPromise(_0x0f30('0x41'),_0x559e7e['query'],routingClient)[_0x0f30('0xa')](findById(_0x559e7e['params']['id']))[_0x0f30('0xa')](respondWithResult(_0x4fec41,null))[_0x0f30('0xd')](handleError(_0x4fec41,null));};exports[_0x0f30('0x43')]=function(_0x1a5a47,_0x522ed9){return respondWithRpcPromise('MailQueues',_0x1a5a47[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](respondWithResult(_0x522ed9,null))['catch'](handleError(_0x522ed9,null));};exports[_0x0f30('0x44')]=function(_0x46a032,_0x54e0e2){return respondWithRpcPromise('MailQueues',_0x46a032[_0x0f30('0x17')],routingClient)['then'](findById(_0x46a032[_0x0f30('0x1a')]['id']))[_0x0f30('0xa')](respondWithResult(_0x54e0e2,null))['catch'](handleError(_0x54e0e2,null));};exports[_0x0f30('0x45')]=function(_0x3ca917,_0x38bb2b){return respondWithRpcPromise('MailAccounts',_0x3ca917[_0x0f30('0x17')],mailClient)[_0x0f30('0xa')](respondWithResult(_0x38bb2b,null))[_0x0f30('0xd')](handleError(_0x38bb2b,null));};exports[_0x0f30('0x46')]=function(_0x28b29d,_0x39e7b8){return respondWithRpcPromise(_0x0f30('0x47'),_0x28b29d[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](respondWithResult(_0x39e7b8,null))[_0x0f30('0xd')](handleError(_0x39e7b8,null));};exports[_0x0f30('0x48')]=function(_0x32d5fc,_0x58e88f){return respondWithRpcPromise(_0x0f30('0x47'),_0x32d5fc[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](findById(_0x32d5fc['params']['id']))[_0x0f30('0xa')](respondWithResult(_0x58e88f,null))[_0x0f30('0xd')](handleError(_0x58e88f,null));};exports['smsQueues']=function(_0x15652c,_0x49b12c){return respondWithRpcPromise(_0x0f30('0x49'),_0x15652c[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](respondWithResult(_0x49b12c,null))['catch'](handleError(_0x49b12c,null));};exports[_0x0f30('0x4a')]=function(_0x4661ff,_0x4cde19){return respondWithRpcPromise('SmsQueues',_0x4661ff[_0x0f30('0x17')],routingClient)['then'](findById(_0x4661ff['params']['id']))[_0x0f30('0xa')](respondWithResult(_0x4cde19,null))[_0x0f30('0xd')](handleError(_0x4cde19,null));};exports['whatsappQueues']=function(_0x14a8cf,_0x39b88c){return respondWithRpcPromise(_0x0f30('0x4b'),_0x14a8cf[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](respondWithResult(_0x39b88c,null))[_0x0f30('0xd')](handleError(_0x39b88c,null));};exports[_0x0f30('0x4c')]=function(_0x2efedd,_0x148ca8){return respondWithRpcPromise(_0x0f30('0x4b'),_0x2efedd[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](findById(_0x2efedd['params']['id']))[_0x0f30('0xa')](respondWithResult(_0x148ca8,null))[_0x0f30('0xd')](handleError(_0x148ca8,null));};exports[_0x0f30('0x4d')]=function(_0x124470,_0x2b5724){return respondWithRpcPromise(_0x0f30('0x4e'),_0x124470[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](respondWithResult(_0x2b5724,null))[_0x0f30('0xd')](handleError(_0x2b5724,null));};exports[_0x0f30('0x4f')]=function(_0x559747,_0x1dbfad){return respondWithRpcPromise(_0x0f30('0x4e'),_0x559747[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](findById(_0x559747[_0x0f30('0x1a')]['id']))[_0x0f30('0xa')](respondWithResult(_0x1dbfad,null))['catch'](handleError(_0x1dbfad,null));};exports[_0x0f30('0x50')]=function(_0x2d37f5,_0x3243a4){return respondWithRpcPromise(_0x0f30('0x51'),_0x2d37f5[_0x0f30('0x17')])['then'](respondWithResult(_0x3243a4,null))[_0x0f30('0xd')](handleError(_0x3243a4,null));};exports[_0x0f30('0x52')]=function(_0x30faaf,_0x34da20){return respondWithRpcPromise('ChatQueuesWaitingInteractions',_0x30faaf['query'],routingClient)['then'](respondWithResult(_0x34da20,null))[_0x0f30('0xd')](handleError(_0x34da20,null));};exports[_0x0f30('0x53')]=function(_0x370c82,_0x4657e1){return respondWithRpcPromise(_0x0f30('0x54'),_0x370c82[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](respondWithResult(_0x4657e1,null))[_0x0f30('0xd')](handleError(_0x4657e1,null));};exports['openchannelQueuesWaitingInteractions']=function(_0x136b04,_0x1a9d7d){return respondWithRpcPromise('OpenchannelQueuesWaitingInteractions',_0x136b04[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](respondWithResult(_0x1a9d7d,null))[_0x0f30('0xd')](handleError(_0x1a9d7d,null));};exports['openchannelQueuesIdWaitingInteractions']=function(_0x258301,_0x597bf7){return respondWithRpcPromise(_0x0f30('0x55'),_0x258301[_0x0f30('0x17')],routingClient)['then'](function(_0x30e5d2){if(_0x258301['query'][_0x0f30('0x56')]!==undefined){var _0x56f280=_(_0x30e5d2[_0x0f30('0x14')])[_0x0f30('0x57')]([_0x258301['query']['type'],_0x258301['params']['id']])[_0x0f30('0x58')](_0x0f30('0x59'))[_0x0f30('0x5a')]()['value']();return _0x30e5d2[_0x0f30('0x14')][_0x0f30('0x57')](function(_0x3171fe){return _0x56f280[_0x0f30('0x5b')](_0x3171fe[_0x0f30('0x59')])>-0x1;});}else{return _0x30e5d2['rows'][_0x0f30('0x57')](function(_0xa162da){return _0xa162da[_0x0f30('0x59')]===parseInt(_0x258301[_0x0f30('0x1a')]['id']);});}})[_0x0f30('0xa')](respondWithResult(_0x597bf7,null))[_0x0f30('0xd')](handleError(_0x597bf7,null));};exports[_0x0f30('0x5c')]=function(_0x5497ba,_0x2e4bf6){return respondWithRpcPromise('SmsQueuesWaitingInteractions',_0x5497ba[_0x0f30('0x17')],routingClient)[_0x0f30('0xa')](respondWithResult(_0x2e4bf6,null))['catch'](handleError(_0x2e4bf6,null));};exports[_0x0f30('0x5d')]=function(_0x10154a,_0x529db2){return respondWithRpcPromise(_0x0f30('0x5e'),_0x10154a['query'],routingClient)[_0x0f30('0xa')](respondWithResult(_0x529db2,null))['catch'](handleError(_0x529db2,null));};exports[_0x0f30('0x5f')]=function(_0x9b90e4,_0xbee020){return respondWithRpcPromise(_0x0f30('0x60'),_0x9b90e4['query'],routingClient)[_0x0f30('0xa')](respondWithResult(_0xbee020,null))[_0x0f30('0xd')](handleError(_0xbee020,null));};exports[_0x0f30('0x61')]=function(_0x4f0a5e){return function(_0x43b088,_0x2a1fac){var _0x58aec2,_0x5cf6b6;var _0x22c5c2=_[_0x0f30('0x62')](_0x4f0a5e);var _0x5959fd=_0x4f0a5e==='chat'?'Website':_0x0f30('0x63');return db[_0x22c5c2+_0x0f30('0x64')][_0x0f30('0x65')]({'raw':!![],'where':{'id':_0x43b088[_0x0f30('0x1a')]['id']}})['then'](function(_0x283f24){if(_[_0x0f30('0x13')](_0x283f24)){throw new Error(_0x22c5c2+'\x20Queue\x20not\x20found');}_0x58aec2=_0x283f24;return db[_0x22c5c2+_0x0f30('0x66')][_0x0f30('0x65')]({'where':{'id':_0x43b088[_0x0f30('0x2c')][_0x0f30('0x67')]},'include':[{'model':db[_0x22c5c2+_0x0f30('0x68')],'as':_0x0f30('0x68')},{'model':db[_0x22c5c2+_0x5959fd],'as':_0x0f30('0x63')}]});})[_0x0f30('0xa')](function(_0x36f8c4){if(_[_0x0f30('0x13')](_0x36f8c4)){throw new Error(_0x22c5c2+_0x0f30('0x69'));}_0x5cf6b6=_0x36f8c4;return _0x36f8c4['update']({'read':0x0,'readAt':null,'UserId':null});})[_0x0f30('0xa')](function(){var _0x135cf7={'uniqueid':_0x4f0a5e+'.'+_0x5cf6b6['id']+'.'+_0x5cf6b6['Interaction']['id'],'FromUserId':_0x43b088[_0x0f30('0x2e')]['id'],'type':_0x0f30('0x6a')};_0x135cf7[_0x22c5c2+_0x0f30('0x6b')]=_0x5cf6b6['id'];_0x135cf7[_0x22c5c2+'InteractionId']=_0x5cf6b6[_0x0f30('0x68')]['id'];_0x135cf7['From'+_0x22c5c2+_0x5959fd+'Id']=_0x5cf6b6['Account']['id'];_0x135cf7['To'+_0x22c5c2+'QueueId']=_0x58aec2['id'];return db[_0x22c5c2+_0x0f30('0x6c')][_0x0f30('0x6d')](_0x135cf7);})[_0x0f30('0xa')](function(){return respondWithRpcPromise(_0x0f30('0x6e'),{'channel':_0x4f0a5e,'interaction':_0x5cf6b6[_0x0f30('0x68')],'message':_0x5cf6b6,'account':_0x5cf6b6['Account'],'applications':[{'id':0x0,'priority':0x1,'app':'queue','appdata':_0x58aec2[_0x0f30('0x11')]+','+(_0x5cf6b6[_0x0f30('0x63')]['queueTransferTimeout']||0x12c),'interval':_0x0f30('0x6f')}]},routingClient);})[_0x0f30('0xa')](respondWithResult(_0x2a1fac,null))[_0x0f30('0xd')](handleError(_0x2a1fac,null));};};exports[_0x0f30('0x70')]=function(_0x2dc1f9,_0x40721d){var _0x5119e8,_0x5185cc;if(_['isNil'](_0x2dc1f9[_0x0f30('0x2c')]['channel'])){throw new Error(_0x0f30('0x71'));}var _0x571cb7=_0x2dc1f9[_0x0f30('0x2c')][_0x0f30('0x72')];var _0x3b3a28=_[_0x0f30('0x62')](_0x571cb7);var _0x7eb574=_0x571cb7===_0x0f30('0x73')?'Website':_0x0f30('0x63');return db[_0x0f30('0x74')][_0x0f30('0x65')]({'raw':!![],'where':{'id':_0x2dc1f9['params']['id'],'role':'agent'}})[_0x0f30('0xa')](function(_0x40586d){if(_[_0x0f30('0x13')](_0x40586d)){throw new Error(_0x0f30('0x75'));}_0x5119e8=_0x40586d;return db[_0x3b3a28+_0x0f30('0x66')][_0x0f30('0x65')]({'where':{'id':_0x2dc1f9[_0x0f30('0x2c')]['messageId']},'include':[{'model':db[_0x3b3a28+'Interaction'],'as':_0x0f30('0x68')},{'model':db[_0x3b3a28+_0x7eb574],'as':_0x0f30('0x63')}]});})[_0x0f30('0xa')](function(_0x3a94f3){if(_[_0x0f30('0x13')](_0x3a94f3)){throw new Error(_0x3b3a28+_0x0f30('0x69'));}_0x5185cc=_0x3a94f3;return _0x3a94f3['update']({'read':0x0,'readAt':null,'UserId':null});})['then'](function(){var _0x34cf63={'uniqueid':_0x571cb7+'.'+_0x5185cc['id']+'.'+_0x5185cc['Interaction']['id'],'FromUserId':_0x2dc1f9['user']['id'],'type':_0x0f30('0x6a'),'ToUserId':_0x5119e8['id']};_0x34cf63[_0x3b3a28+_0x0f30('0x6b')]=_0x5185cc['id'];_0x34cf63[_0x3b3a28+_0x0f30('0x76')]=_0x5185cc[_0x0f30('0x68')]['id'];_0x34cf63['From'+_0x3b3a28+_0x7eb574+'Id']=_0x5185cc[_0x0f30('0x63')]['id'];return db[_0x3b3a28+_0x0f30('0x6c')][_0x0f30('0x6d')](_0x34cf63);})[_0x0f30('0xa')](function(){return respondWithRpcPromise(_0x0f30('0x6e'),{'channel':_0x571cb7,'interaction':_0x5185cc[_0x0f30('0x68')],'message':_0x5185cc,'account':_0x5185cc[_0x0f30('0x63')],'applications':[{'id':0x0,'priority':0x1,'app':'agent','appdata':_0x5119e8['name']+','+(_0x5185cc[_0x0f30('0x63')]['agentTransferTimeout']||0x12c),'interval':_0x0f30('0x6f')}]},routingClient);})[_0x0f30('0xa')](respondWithResult(_0x40721d,null))[_0x0f30('0xd')](handleError(_0x40721d,null));};