Built motion from commit (unavailable).|2.5.31
[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 _0x8266=['channel','Channel\x20field\x20is\x20mandatory','capitalize','chat','Message','\x20Message\x20not\x20found','From','agentTransferTimeout','*,*,*,*','moment','lodash','../../mysqldb','../../config/logger','jayson/promise','client','http','request','then','error','code','message','catch','status','json','sendStatus','stack','name','isNil','rows','voiceChannels','VoiceChannels','VoiceChannelMixMonitor','merge','query','params','VoiceQueues','updateVoiceQueue','UpdateVoiceQueue','body','voiceQueuesPreview','VoiceQueuesPreview','voiceQueuesChannels','VoiceQueuesChannels','voiceQueuesChannel','VoiceQueuesChannelHangup','voiceQueuesChannelRedirect','VoiceQueuesChannelRedirect','Outbound','outboundChannels','OutboundChannels','Agents','interaction','user','hasOwnProperty','MemberReport','findAll','INTERACTION','length','format','YYYY-MM-DD\x20HH:mm:ss','updateAttributes','agent','internal','AgentCapacity','capacity','trunks','Trunks','campaigns','Campaigns','chatQueues','ChatQueues','mailQueues','showMailQueues','MailQueues','mailAccounts','MailAccounts','openchannelQueues','OpenchannelQueues','showOpenchannelQueues','SmsQueues','showSmsQueues','whatsappQueues','showWhatsappQueues','WhatsappQueues','faxQueues','FaxQueues','showFaxQueues','FaxAccounts','chatQueuesWaitingInteractions','mailQueuesWaitingInteractions','MailQueuesWaitingInteractions','OpenchannelQueuesWaitingInteractions','openchannelQueuesIdWaitingInteractions','type','map','queue_id','uniq','filter','smsQueuesWaitingInteractions','SmsQueuesWaitingInteractions','WhatsappQueuesWaitingInteractions','faxQueuesWaitingInteractions','FaxQueuesWaitingInteractions','queueNotify','Website','Account','Queue','findOne','\x20Queue\x20not\x20found','messageId','Interaction','update','queue','MessageId','InteractionId','QueueId','TransferReport','create','Start','queueTransferTimeout','agentNotify'];(function(_0x53c7f4,_0x9a4e68){var _0x4426e1=function(_0x15d404){while(--_0x15d404){_0x53c7f4['push'](_0x53c7f4['shift']());}};_0x4426e1(++_0x9a4e68);}(_0x8266,0x1ed));var _0x6826=function(_0x494c0a,_0x21968c){_0x494c0a=_0x494c0a-0x0;var _0xf8bad5=_0x8266[_0x494c0a];return _0xf8bad5;};'use strict';var BPromise=require('bluebird');var moment=require(_0x6826('0x0'));var _=require(_0x6826('0x1'));var util=require('util');var db=require(_0x6826('0x2'))['db'];var logger=require(_0x6826('0x3'))('api');var jayson=require(_0x6826('0x4'));var amiClient=jayson[_0x6826('0x5')][_0x6826('0x6')]({'port':0x232a});var mailClient=jayson[_0x6826('0x5')][_0x6826('0x6')]({'port':0x232b});var routingClient=jayson[_0x6826('0x5')][_0x6826('0x6')]({'port':0x232c});function respondWithRpcPromise(_0x2b5b6a,_0x332402,_0x54ba28){return new BPromise(function(_0x3d9c0c,_0xd0de5c){var _0x5d7dbc=_0x54ba28?_0x54ba28:amiClient;return _0x5d7dbc[_0x6826('0x7')](_0x2b5b6a,_0x332402)[_0x6826('0x8')](function(_0x178e61){if(_0x178e61[_0x6826('0x9')]){if(_0x178e61['error'][_0x6826('0xa')]===0x1f4){return _0xd0de5c(_0x178e61['error'][_0x6826('0xb')]);}return _0x3d9c0c(_0x178e61[_0x6826('0x9')][_0x6826('0xb')]);}else{_0x3d9c0c(_0x178e61['result']);}})[_0x6826('0xc')](function(_0x4a2874){_0xd0de5c(_0x4a2874);});});}function respondWithResult(_0x3700cf,_0x37e9f3){_0x37e9f3=_0x37e9f3||0xc8;return function(_0x3852e2){if(_0x3852e2){return _0x3700cf[_0x6826('0xd')](_0x37e9f3)[_0x6826('0xe')](_0x3852e2);}return _0x3700cf[_0x6826('0xf')](0x194);};}function handleError(_0x10be3e,_0x3d9dfd){_0x3d9dfd=_0x3d9dfd||0x1f4;return function(_0x43aa81){logger[_0x6826('0x9')](_0x43aa81[_0x6826('0x10')]);if(_0x43aa81[_0x6826('0x11')]){delete _0x43aa81[_0x6826('0x11')];}_0x10be3e[_0x6826('0xd')](_0x3d9dfd)['send'](_0x43aa81);};}function findById(_0xeb5f6d){return function(_0x5208a7){if(!_['isNil'](_0xeb5f6d)&&!_['isNil'](_0x5208a7)&&!_[_0x6826('0x12')](_0x5208a7[_0x6826('0x13')])){return _['find'](_0x5208a7['rows'],function(_0x18f502){return _0x18f502['id']==_0xeb5f6d;});}return null;};}exports[_0x6826('0x14')]=function(_0x52366a,_0x5c852d){return respondWithRpcPromise(_0x6826('0x15'),_0x52366a['query'])[_0x6826('0x8')](respondWithResult(_0x5c852d,null))[_0x6826('0xc')](handleError(_0x5c852d,null));};exports['voiceChannelMixMonitor']=function(_0x2f1844,_0x9bd1f6){return respondWithRpcPromise(_0x6826('0x16'),_[_0x6826('0x17')](_0x2f1844[_0x6826('0x18')],_0x2f1844[_0x6826('0x19')]))['then'](respondWithResult(_0x9bd1f6,null))[_0x6826('0xc')](handleError(_0x9bd1f6,null));};exports['voiceChannelStopMixMonitor']=function(_0x56eef0,_0x552485){return respondWithRpcPromise('VoiceChannelStopMixMonitor',_['merge'](_0x56eef0['query'],_0x56eef0[_0x6826('0x19')]))[_0x6826('0x8')](respondWithResult(_0x552485,null))[_0x6826('0xc')](handleError(_0x552485,null));};exports['voiceQueues']=function(_0x6e9ec9,_0x4112a8){return respondWithRpcPromise(_0x6826('0x1a'),_0x6e9ec9['query'])[_0x6826('0x8')](respondWithResult(_0x4112a8,null))[_0x6826('0xc')](handleError(_0x4112a8,null));};exports['showVoiceQueues']=function(_0x3275e6,_0x55fbd6){return respondWithRpcPromise(_0x6826('0x1a'),_0x3275e6[_0x6826('0x18')])[_0x6826('0x8')](findById(_0x3275e6['params']['id']))[_0x6826('0x8')](respondWithResult(_0x55fbd6,null))[_0x6826('0xc')](handleError(_0x55fbd6,null));};exports[_0x6826('0x1b')]=function(_0x1fb8cf,_0x5a5229){return respondWithRpcPromise(_0x6826('0x1c'),_[_0x6826('0x17')](_0x1fb8cf[_0x6826('0x1d')],_0x1fb8cf[_0x6826('0x19')]))['then'](respondWithResult(_0x5a5229,null))['catch'](handleError(_0x5a5229,null));};exports[_0x6826('0x1e')]=function(_0x383ace,_0x505673){return respondWithRpcPromise(_0x6826('0x1f'),_['merge'](_0x383ace[_0x6826('0x18')],_0x383ace['params']))[_0x6826('0x8')](respondWithResult(_0x505673,null))[_0x6826('0xc')](handleError(_0x505673,null));};exports[_0x6826('0x20')]=function(_0x5d7d5b,_0x38e6eb){return respondWithRpcPromise(_0x6826('0x21'),_0x5d7d5b[_0x6826('0x18')])[_0x6826('0x8')](respondWithResult(_0x38e6eb,null))[_0x6826('0xc')](handleError(_0x38e6eb,null));};exports[_0x6826('0x22')]=function(_0x489978,_0x3ef4d0){return respondWithRpcPromise('VoiceQueuesChannel',_[_0x6826('0x17')](_0x489978[_0x6826('0x18')],_0x489978['params']))[_0x6826('0x8')](respondWithResult(_0x3ef4d0,null))[_0x6826('0xc')](handleError(_0x3ef4d0,null));};exports['voiceQueuesChannelHangup']=function(_0x3790a9,_0x204420){return respondWithRpcPromise(_0x6826('0x23'),_[_0x6826('0x17')](_0x3790a9[_0x6826('0x18')],_0x3790a9['params']))[_0x6826('0x8')](respondWithResult(_0x204420,null))[_0x6826('0xc')](handleError(_0x204420,null));};exports[_0x6826('0x24')]=function(_0x2bc996,_0xc6e85f){return respondWithRpcPromise(_0x6826('0x25'),_[_0x6826('0x17')](_0x2bc996['query'],_0x2bc996[_0x6826('0x19')]))[_0x6826('0x8')](respondWithResult(_0xc6e85f,null))[_0x6826('0xc')](handleError(_0xc6e85f,null));};exports['outbound']=function(_0x452d04,_0x200b1a){return respondWithRpcPromise(_0x6826('0x26'),_0x452d04[_0x6826('0x18')])['then'](respondWithResult(_0x200b1a,null))[_0x6826('0xc')](handleError(_0x200b1a,null));};exports[_0x6826('0x27')]=function(_0x19a7c5,_0x402f63){return respondWithRpcPromise(_0x6826('0x28'),_0x19a7c5['query'])['then'](respondWithResult(_0x402f63,null))[_0x6826('0xc')](handleError(_0x402f63,null));};exports['agents']=function(_0x8b2ff9,_0x151d90){var _0x2d735d;return respondWithRpcPromise(_0x6826('0x29'),_0x8b2ff9[_0x6826('0x18')])[_0x6826('0x8')](function(_0x125a18){_0x2d735d=_0x125a18;return respondWithRpcPromise(_0x6826('0x29'),_0x8b2ff9[_0x6826('0x18')],routingClient);})[_0x6826('0x8')](function(_0x88be7b){return _[_0x6826('0x17')]({},_0x88be7b,_0x2d735d);})[_0x6826('0x8')](respondWithResult(_0x151d90,null))[_0x6826('0xc')](handleError(_0x151d90,null));};exports['agentCapacity']=function(_0x45f2fc,_0x3672f1){if(_0x45f2fc[_0x6826('0x1d')]&&_0x45f2fc[_0x6826('0x1d')][_0x6826('0x2a')]&&_0x45f2fc[_0x6826('0x2b')]&&_0x45f2fc[_0x6826('0x2b')][_0x6826('0x11')]){for(var _0x7c8ab0 in _0x45f2fc[_0x6826('0x1d')][_0x6826('0x2a')]){if(_0x45f2fc[_0x6826('0x1d')][_0x6826('0x2a')][_0x6826('0x2c')](_0x7c8ab0)){db[_0x6826('0x2d')][_0x6826('0x2e')]({'where':{'channel':_0x7c8ab0,'membername':_0x45f2fc[_0x6826('0x2b')][_0x6826('0x11')],'type':_0x6826('0x2f'),'exitAt':null,'uniqueid':_0x45f2fc[_0x6826('0x1d')]['interaction'][_0x7c8ab0]&&_0x45f2fc[_0x6826('0x1d')]['interaction'][_0x7c8ab0][_0x6826('0x30')]?{'$notIn':_0x45f2fc['body']['interaction'][_0x7c8ab0]}:{'$ne':null}}})[_0x6826('0x8')](function(_0x5e8466){var _0x4cbdf2=moment()[_0x6826('0x31')](_0x6826('0x32'));for(var _0x5041b0=0x0,_0x34b121=_0x5e8466[_0x6826('0x30')];_0x5041b0<_0x34b121;_0x5041b0+=0x1){_0x5e8466[_0x5041b0][_0x6826('0x33')]({'exitAt':_0x4cbdf2});}});for(var _0x59dde6=0x0;_0x59dde6<_0x45f2fc['body'][_0x6826('0x2a')][_0x7c8ab0][_0x6826('0x30')];_0x59dde6+=0x1){db['MemberReport']['findOrCreate']({'where':{'channel':_0x7c8ab0,'membername':_0x45f2fc[_0x6826('0x2b')][_0x6826('0x11')],'type':_0x6826('0x2f'),'uniqueid':_0x45f2fc[_0x6826('0x1d')]['interaction'][_0x7c8ab0][_0x59dde6],'exitAt':null},'defaults':{'channel':_0x7c8ab0,'membername':_0x45f2fc['user'][_0x6826('0x11')],'interface':_['isNil'](_0x45f2fc[_0x6826('0x2b')]['interface'])?util[_0x6826('0x31')]('SIP/%s',_0x45f2fc['user'][_0x6826('0x11')]):_0x45f2fc['user']['interface'],'type':'INTERACTION','enterAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'role':_0x6826('0x34'),'internal':_0x45f2fc[_0x6826('0x2b')][_0x6826('0x35')],'uniqueid':_0x45f2fc[_0x6826('0x1d')][_0x6826('0x2a')][_0x7c8ab0][_0x59dde6]}});}}}}return respondWithRpcPromise(_0x6826('0x36'),{'id':_0x45f2fc[_0x6826('0x19')]['id'],'capacity':_0x45f2fc[_0x6826('0x1d')][_0x6826('0x37')]},routingClient)[_0x6826('0x8')](respondWithResult(_0x3672f1,null))[_0x6826('0xc')](handleError(_0x3672f1,null));};exports['telephones']=function(_0x33e4d1,_0x41418f){return respondWithRpcPromise('Telephones',_0x33e4d1[_0x6826('0x18')])['then'](respondWithResult(_0x41418f,null))[_0x6826('0xc')](handleError(_0x41418f,null));};exports[_0x6826('0x38')]=function(_0x2de2df,_0x4b2787){return respondWithRpcPromise(_0x6826('0x39'),_0x2de2df[_0x6826('0x18')])[_0x6826('0x8')](respondWithResult(_0x4b2787,null))[_0x6826('0xc')](handleError(_0x4b2787,null));};exports[_0x6826('0x3a')]=function(_0x1967f2,_0x24d4ea){return respondWithRpcPromise(_0x6826('0x3b'),_0x1967f2[_0x6826('0x18')])[_0x6826('0x8')](respondWithResult(_0x24d4ea,null))[_0x6826('0xc')](handleError(_0x24d4ea,null));};exports[_0x6826('0x3c')]=function(_0x15777b,_0xda3160){return respondWithRpcPromise(_0x6826('0x3d'),_0x15777b[_0x6826('0x18')],routingClient)[_0x6826('0x8')](respondWithResult(_0xda3160,null))[_0x6826('0xc')](handleError(_0xda3160,null));};exports['showChatQueues']=function(_0x111e5b,_0x3872fe){return respondWithRpcPromise(_0x6826('0x3d'),_0x111e5b[_0x6826('0x18')],routingClient)[_0x6826('0x8')](findById(_0x111e5b[_0x6826('0x19')]['id']))[_0x6826('0x8')](respondWithResult(_0x3872fe,null))[_0x6826('0xc')](handleError(_0x3872fe,null));};exports[_0x6826('0x3e')]=function(_0x2388e6,_0x2bc650){return respondWithRpcPromise('MailQueues',_0x2388e6[_0x6826('0x18')],routingClient)[_0x6826('0x8')](respondWithResult(_0x2bc650,null))[_0x6826('0xc')](handleError(_0x2bc650,null));};exports[_0x6826('0x3f')]=function(_0x3107ca,_0x16aa3d){return respondWithRpcPromise(_0x6826('0x40'),_0x3107ca['query'],routingClient)[_0x6826('0x8')](findById(_0x3107ca[_0x6826('0x19')]['id']))[_0x6826('0x8')](respondWithResult(_0x16aa3d,null))[_0x6826('0xc')](handleError(_0x16aa3d,null));};exports[_0x6826('0x41')]=function(_0x57b4a9,_0x297f40){return respondWithRpcPromise(_0x6826('0x42'),_0x57b4a9[_0x6826('0x18')],mailClient)[_0x6826('0x8')](respondWithResult(_0x297f40,null))[_0x6826('0xc')](handleError(_0x297f40,null));};exports[_0x6826('0x43')]=function(_0x42c7ba,_0x49076e){return respondWithRpcPromise(_0x6826('0x44'),_0x42c7ba[_0x6826('0x18')],routingClient)[_0x6826('0x8')](respondWithResult(_0x49076e,null))['catch'](handleError(_0x49076e,null));};exports[_0x6826('0x45')]=function(_0x1e156a,_0xb458a2){return respondWithRpcPromise('OpenchannelQueues',_0x1e156a[_0x6826('0x18')],routingClient)['then'](findById(_0x1e156a[_0x6826('0x19')]['id']))[_0x6826('0x8')](respondWithResult(_0xb458a2,null))[_0x6826('0xc')](handleError(_0xb458a2,null));};exports['smsQueues']=function(_0x4ecd2c,_0x2c788e){return respondWithRpcPromise(_0x6826('0x46'),_0x4ecd2c[_0x6826('0x18')],routingClient)[_0x6826('0x8')](respondWithResult(_0x2c788e,null))[_0x6826('0xc')](handleError(_0x2c788e,null));};exports[_0x6826('0x47')]=function(_0x33c420,_0x15fe3f){return respondWithRpcPromise('SmsQueues',_0x33c420['query'],routingClient)[_0x6826('0x8')](findById(_0x33c420[_0x6826('0x19')]['id']))[_0x6826('0x8')](respondWithResult(_0x15fe3f,null))['catch'](handleError(_0x15fe3f,null));};exports[_0x6826('0x48')]=function(_0x10c6aa,_0x23978f){return respondWithRpcPromise('WhatsappQueues',_0x10c6aa[_0x6826('0x18')],routingClient)['then'](respondWithResult(_0x23978f,null))[_0x6826('0xc')](handleError(_0x23978f,null));};exports[_0x6826('0x49')]=function(_0x3959f3,_0x2b90da){return respondWithRpcPromise(_0x6826('0x4a'),_0x3959f3[_0x6826('0x18')],routingClient)[_0x6826('0x8')](findById(_0x3959f3[_0x6826('0x19')]['id']))['then'](respondWithResult(_0x2b90da,null))[_0x6826('0xc')](handleError(_0x2b90da,null));};exports[_0x6826('0x4b')]=function(_0x2b60fc,_0x53f914){return respondWithRpcPromise(_0x6826('0x4c'),_0x2b60fc[_0x6826('0x18')],routingClient)[_0x6826('0x8')](respondWithResult(_0x53f914,null))[_0x6826('0xc')](handleError(_0x53f914,null));};exports[_0x6826('0x4d')]=function(_0x12f580,_0x13c7e9){return respondWithRpcPromise('FaxQueues',_0x12f580[_0x6826('0x18')],routingClient)[_0x6826('0x8')](findById(_0x12f580[_0x6826('0x19')]['id']))['then'](respondWithResult(_0x13c7e9,null))[_0x6826('0xc')](handleError(_0x13c7e9,null));};exports['faxAccounts']=function(_0x55f5eb,_0x3cdd39){return respondWithRpcPromise(_0x6826('0x4e'),_0x55f5eb[_0x6826('0x18')])[_0x6826('0x8')](respondWithResult(_0x3cdd39,null))[_0x6826('0xc')](handleError(_0x3cdd39,null));};exports[_0x6826('0x4f')]=function(_0x235776,_0x47b061){return respondWithRpcPromise('ChatQueuesWaitingInteractions',_0x235776[_0x6826('0x18')],routingClient)['then'](respondWithResult(_0x47b061,null))[_0x6826('0xc')](handleError(_0x47b061,null));};exports[_0x6826('0x50')]=function(_0x5ed803,_0x457d70){return respondWithRpcPromise(_0x6826('0x51'),_0x5ed803[_0x6826('0x18')],routingClient)['then'](respondWithResult(_0x457d70,null))[_0x6826('0xc')](handleError(_0x457d70,null));};exports['openchannelQueuesWaitingInteractions']=function(_0x1236eb,_0x40b3c8){return respondWithRpcPromise(_0x6826('0x52'),_0x1236eb[_0x6826('0x18')],routingClient)[_0x6826('0x8')](respondWithResult(_0x40b3c8,null))[_0x6826('0xc')](handleError(_0x40b3c8,null));};exports[_0x6826('0x53')]=function(_0x5d1962,_0x296ab7){return respondWithRpcPromise(_0x6826('0x52'),_0x5d1962[_0x6826('0x18')],routingClient)[_0x6826('0x8')](function(_0x1416bf){if(_0x5d1962[_0x6826('0x18')][_0x6826('0x54')]!==undefined){var _0x45f3b0=_(_0x1416bf[_0x6826('0x13')])['filter']([_0x5d1962[_0x6826('0x18')][_0x6826('0x54')],_0x5d1962[_0x6826('0x19')]['id']])[_0x6826('0x55')](_0x6826('0x56'))[_0x6826('0x57')]()['value']();return _0x1416bf[_0x6826('0x13')][_0x6826('0x58')](function(_0x858db1){return _0x45f3b0['indexOf'](_0x858db1[_0x6826('0x56')])>-0x1;});}else{return _0x1416bf['rows'][_0x6826('0x58')](function(_0x20001e){return _0x20001e[_0x6826('0x56')]===parseInt(_0x5d1962['params']['id']);});}})[_0x6826('0x8')](respondWithResult(_0x296ab7,null))[_0x6826('0xc')](handleError(_0x296ab7,null));};exports[_0x6826('0x59')]=function(_0x519e02,_0x31cc66){return respondWithRpcPromise(_0x6826('0x5a'),_0x519e02['query'],routingClient)[_0x6826('0x8')](respondWithResult(_0x31cc66,null))[_0x6826('0xc')](handleError(_0x31cc66,null));};exports['whatsappQueuesWaitingInteractions']=function(_0x500644,_0x30715e){return respondWithRpcPromise(_0x6826('0x5b'),_0x500644[_0x6826('0x18')],routingClient)['then'](respondWithResult(_0x30715e,null))[_0x6826('0xc')](handleError(_0x30715e,null));};exports[_0x6826('0x5c')]=function(_0x162722,_0x19915d){return respondWithRpcPromise(_0x6826('0x5d'),_0x162722['query'],routingClient)[_0x6826('0x8')](respondWithResult(_0x19915d,null))[_0x6826('0xc')](handleError(_0x19915d,null));};exports[_0x6826('0x5e')]=function(_0x3c40ac){return function(_0x357e20,_0x28005e){var _0x43d03a,_0x316556;var _0x387bf3=_['capitalize'](_0x3c40ac);var _0x59738a=_0x3c40ac==='chat'?_0x6826('0x5f'):_0x6826('0x60');return db[_0x387bf3+_0x6826('0x61')][_0x6826('0x62')]({'raw':!![],'where':{'id':_0x357e20[_0x6826('0x19')]['id']}})[_0x6826('0x8')](function(_0x20f76f){if(_[_0x6826('0x12')](_0x20f76f)){throw new Error(_0x387bf3+_0x6826('0x63'));}_0x43d03a=_0x20f76f;return db[_0x387bf3+'Message'][_0x6826('0x62')]({'where':{'id':_0x357e20[_0x6826('0x1d')][_0x6826('0x64')]},'include':[{'model':db[_0x387bf3+'Interaction'],'as':_0x6826('0x65')},{'model':db[_0x387bf3+_0x59738a],'as':'Account'}]});})['then'](function(_0x3aef57){if(_[_0x6826('0x12')](_0x3aef57)){throw new Error(_0x387bf3+'\x20Message\x20not\x20found');}_0x316556=_0x3aef57;return _0x3aef57[_0x6826('0x66')]({'read':0x0,'readAt':null,'UserId':null});})[_0x6826('0x8')](function(){var _0xea4283={'uniqueid':_0x3c40ac+'.'+_0x316556['id']+'.'+_0x316556[_0x6826('0x65')]['id'],'FromUserId':_0x357e20[_0x6826('0x2b')]['id'],'type':_0x6826('0x67')};_0xea4283[_0x387bf3+_0x6826('0x68')]=_0x316556['id'];_0xea4283[_0x387bf3+_0x6826('0x69')]=_0x316556['Interaction']['id'];_0xea4283['From'+_0x387bf3+_0x59738a+'Id']=_0x316556[_0x6826('0x60')]['id'];_0xea4283['To'+_0x387bf3+_0x6826('0x6a')]=_0x43d03a['id'];return db[_0x387bf3+_0x6826('0x6b')][_0x6826('0x6c')](_0xea4283);})[_0x6826('0x8')](function(){return respondWithRpcPromise(_0x6826('0x6d'),{'channel':_0x3c40ac,'interaction':_0x316556[_0x6826('0x65')],'message':_0x316556,'account':_0x316556['Account'],'applications':[{'id':0x0,'priority':0x1,'app':'queue','appdata':_0x43d03a['name']+','+(_0x316556[_0x6826('0x60')][_0x6826('0x6e')]||0x12c),'interval':'*,*,*,*'}]},routingClient);})[_0x6826('0x8')](respondWithResult(_0x28005e,null))['catch'](handleError(_0x28005e,null));};};exports[_0x6826('0x6f')]=function(_0x523d34,_0x5c48fa){var _0x4d2ab4,_0x3edd85;if(_[_0x6826('0x12')](_0x523d34[_0x6826('0x1d')][_0x6826('0x70')])){throw new Error(_0x6826('0x71'));}var _0x25b5fa=_0x523d34[_0x6826('0x1d')][_0x6826('0x70')];var _0x5cf82d=_[_0x6826('0x72')](_0x25b5fa);var _0x2c50e2=_0x25b5fa===_0x6826('0x73')?'Website':'Account';return db['User']['findOne']({'raw':!![],'where':{'id':_0x523d34['params']['id'],'role':'agent'}})[_0x6826('0x8')](function(_0x45117b){if(_[_0x6826('0x12')](_0x45117b)){throw new Error('Agent\x20not\x20found');}_0x4d2ab4=_0x45117b;return db[_0x5cf82d+_0x6826('0x74')][_0x6826('0x62')]({'where':{'id':_0x523d34['body'][_0x6826('0x64')]},'include':[{'model':db[_0x5cf82d+'Interaction'],'as':_0x6826('0x65')},{'model':db[_0x5cf82d+_0x2c50e2],'as':'Account'}]});})[_0x6826('0x8')](function(_0x198d57){if(_['isNil'](_0x198d57)){throw new Error(_0x5cf82d+_0x6826('0x75'));}_0x3edd85=_0x198d57;return _0x198d57[_0x6826('0x66')]({'read':0x0,'readAt':null,'UserId':null});})['then'](function(){var _0x73db6e={'uniqueid':_0x25b5fa+'.'+_0x3edd85['id']+'.'+_0x3edd85['Interaction']['id'],'FromUserId':_0x523d34['user']['id'],'type':_0x6826('0x67'),'ToUserId':_0x4d2ab4['id']};_0x73db6e[_0x5cf82d+'MessageId']=_0x3edd85['id'];_0x73db6e[_0x5cf82d+_0x6826('0x69')]=_0x3edd85[_0x6826('0x65')]['id'];_0x73db6e[_0x6826('0x76')+_0x5cf82d+_0x2c50e2+'Id']=_0x3edd85[_0x6826('0x60')]['id'];return db[_0x5cf82d+'TransferReport'][_0x6826('0x6c')](_0x73db6e);})['then'](function(){return respondWithRpcPromise('Start',{'channel':_0x25b5fa,'interaction':_0x3edd85[_0x6826('0x65')],'message':_0x3edd85,'account':_0x3edd85[_0x6826('0x60')],'applications':[{'id':0x0,'priority':0x1,'app':_0x6826('0x34'),'appdata':_0x4d2ab4[_0x6826('0x11')]+','+(_0x3edd85[_0x6826('0x60')][_0x6826('0x77')]||0x12c),'interval':_0x6826('0x78')}]},routingClient);})['then'](respondWithResult(_0x5c48fa,null))[_0x6826('0xc')](handleError(_0x5c48fa,null));};