4f5f9f6534cd2d548b5228976edcdbdd293b4503
[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 _0xf9e2=['showChatQueues','mailQueues','MailQueues','showMailQueues','MailAccounts','openchannelQueues','OpenchannelQueues','showOpenchannelQueues','smsQueues','SmsQueues','showSmsQueues','whatsappQueues','WhatsappQueues','showWhatsappQueues','faxQueues','FaxQueues','showFaxQueues','chatQueuesWaitingInteractions','ChatQueuesWaitingInteractions','mailQueuesWaitingInteractions','MailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','SmsQueuesWaitingInteractions','whatsappQueuesWaitingInteractions','WhatsappQueuesWaitingInteractions','faxQueuesWaitingInteractions','queueNotify','chat','Account','Queue','findOne','Message','messageId','Interaction','\x20Message\x20not\x20found','update','From','QueueId','TransferReport','create','queue','queueTransferTimeout','channel','capitalize','User','agent','MessageId','InteractionId','Start','agentTransferTimeout','*,*,*,*','bluebird','moment','lodash','util','../../mysqldb','../../config/logger','api','jayson/promise','http','client','request','code','error','message','catch','status','sendStatus','stack','name','send','rows','find','voiceChannels','VoiceChannels','query','then','voiceChannelMixMonitor','VoiceChannelMixMonitor','merge','params','VoiceChannelStopMixMonitor','VoiceQueues','voiceQueuesPreview','VoiceQueuesPreview','voiceQueuesChannels','voiceQueuesChannelHangup','VoiceQueuesChannelHangup','voiceQueuesChannelRedirect','VoiceQueuesChannelRedirect','outbound','Outbound','outboundChannels','OutboundChannels','agents','Agents','agentCapacity','body','interaction','user','hasOwnProperty','MemberReport','findAll','INTERACTION','format','YYYY-MM-DD\x20HH:mm:ss','length','updateAttributes','findOrCreate','isNil','interface','SIP/%s','internal','AgentCapacity','capacity','telephones','Trunks','Campaigns','chatQueues','ChatQueues'];(function(_0x5f2dbe,_0x26437a){var _0x43352e=function(_0x54e888){while(--_0x54e888){_0x5f2dbe['push'](_0x5f2dbe['shift']());}};_0x43352e(++_0x26437a);}(_0xf9e2,0x126));var _0x2f9e=function(_0x2d96ab,_0x334ed7){_0x2d96ab=_0x2d96ab-0x0;var _0x3db2ab=_0xf9e2[_0x2d96ab];return _0x3db2ab;};'use strict';var BPromise=require(_0x2f9e('0x0'));var moment=require(_0x2f9e('0x1'));var _=require(_0x2f9e('0x2'));var util=require(_0x2f9e('0x3'));var db=require(_0x2f9e('0x4'))['db'];var logger=require(_0x2f9e('0x5'))(_0x2f9e('0x6'));var jayson=require(_0x2f9e('0x7'));var amiClient=jayson['client'][_0x2f9e('0x8')]({'port':0x232a});var mailClient=jayson['client'][_0x2f9e('0x8')]({'port':0x232b});var routingClient=jayson[_0x2f9e('0x9')]['http']({'port':0x232c});function respondWithRpcPromise(_0x55a8ba,_0x1d95c5,_0x8292c7){return new BPromise(function(_0x51228d,_0x1afa7d){var _0x56dcc9=_0x8292c7?_0x8292c7:amiClient;return _0x56dcc9[_0x2f9e('0xa')](_0x55a8ba,_0x1d95c5)['then'](function(_0x10b2bd){if(_0x10b2bd['error']){if(_0x10b2bd['error'][_0x2f9e('0xb')]===0x1f4){return _0x1afa7d(_0x10b2bd[_0x2f9e('0xc')][_0x2f9e('0xd')]);}return _0x51228d(_0x10b2bd['error']['message']);}else{_0x51228d(_0x10b2bd['result']);}})[_0x2f9e('0xe')](function(_0x439d24){_0x1afa7d(_0x439d24);});});}function respondWithResult(_0x4e7258,_0x24a3de){_0x24a3de=_0x24a3de||0xc8;return function(_0x431b9b){if(_0x431b9b){return _0x4e7258[_0x2f9e('0xf')](_0x24a3de)['json'](_0x431b9b);}return _0x4e7258[_0x2f9e('0x10')](0x194);};}function handleError(_0x22ea75,_0x367e95){_0x367e95=_0x367e95||0x1f4;return function(_0x24f4e6){logger[_0x2f9e('0xc')](_0x24f4e6[_0x2f9e('0x11')]);if(_0x24f4e6[_0x2f9e('0x12')]){delete _0x24f4e6['name'];}_0x22ea75[_0x2f9e('0xf')](_0x367e95)[_0x2f9e('0x13')](_0x24f4e6);};}function findById(_0x1ccaf3){return function(_0x477e00){if(!_['isNil'](_0x1ccaf3)&&!_['isNil'](_0x477e00)&&!_['isNil'](_0x477e00[_0x2f9e('0x14')])){return _[_0x2f9e('0x15')](_0x477e00[_0x2f9e('0x14')],function(_0xe58fc){return _0xe58fc['id']==_0x1ccaf3;});}return null;};}exports[_0x2f9e('0x16')]=function(_0x4c121a,_0x3e919e){return respondWithRpcPromise(_0x2f9e('0x17'),_0x4c121a[_0x2f9e('0x18')])[_0x2f9e('0x19')](respondWithResult(_0x3e919e,null))[_0x2f9e('0xe')](handleError(_0x3e919e,null));};exports[_0x2f9e('0x1a')]=function(_0x48268b,_0x3e8a05){return respondWithRpcPromise(_0x2f9e('0x1b'),_[_0x2f9e('0x1c')](_0x48268b[_0x2f9e('0x18')],_0x48268b[_0x2f9e('0x1d')]))[_0x2f9e('0x19')](respondWithResult(_0x3e8a05,null))['catch'](handleError(_0x3e8a05,null));};exports['voiceChannelStopMixMonitor']=function(_0x5a5b2a,_0x5c77f2){return respondWithRpcPromise(_0x2f9e('0x1e'),_[_0x2f9e('0x1c')](_0x5a5b2a['query'],_0x5a5b2a[_0x2f9e('0x1d')]))[_0x2f9e('0x19')](respondWithResult(_0x5c77f2,null))['catch'](handleError(_0x5c77f2,null));};exports['voiceQueues']=function(_0x2d17a5,_0x5cc8bc){return respondWithRpcPromise(_0x2f9e('0x1f'),_0x2d17a5[_0x2f9e('0x18')])[_0x2f9e('0x19')](respondWithResult(_0x5cc8bc,null))[_0x2f9e('0xe')](handleError(_0x5cc8bc,null));};exports['showVoiceQueues']=function(_0x5808c4,_0xd823a){return respondWithRpcPromise(_0x2f9e('0x1f'),_0x5808c4[_0x2f9e('0x18')])['then'](findById(_0x5808c4[_0x2f9e('0x1d')]['id']))['then'](respondWithResult(_0xd823a,null))[_0x2f9e('0xe')](handleError(_0xd823a,null));};exports[_0x2f9e('0x20')]=function(_0x5091dd,_0x550e55){return respondWithRpcPromise(_0x2f9e('0x21'),_['merge'](_0x5091dd['query'],_0x5091dd[_0x2f9e('0x1d')]))[_0x2f9e('0x19')](respondWithResult(_0x550e55,null))[_0x2f9e('0xe')](handleError(_0x550e55,null));};exports[_0x2f9e('0x22')]=function(_0x59e774,_0x16d710){return respondWithRpcPromise('VoiceQueuesChannels',_0x59e774[_0x2f9e('0x18')])[_0x2f9e('0x19')](respondWithResult(_0x16d710,null))[_0x2f9e('0xe')](handleError(_0x16d710,null));};exports['voiceQueuesChannel']=function(_0x41b45a,_0x485e6b){return respondWithRpcPromise('VoiceQueuesChannel',_[_0x2f9e('0x1c')](_0x41b45a[_0x2f9e('0x18')],_0x41b45a[_0x2f9e('0x1d')]))[_0x2f9e('0x19')](respondWithResult(_0x485e6b,null))[_0x2f9e('0xe')](handleError(_0x485e6b,null));};exports[_0x2f9e('0x23')]=function(_0x2ef1b1,_0x505acd){return respondWithRpcPromise(_0x2f9e('0x24'),_[_0x2f9e('0x1c')](_0x2ef1b1[_0x2f9e('0x18')],_0x2ef1b1[_0x2f9e('0x1d')]))[_0x2f9e('0x19')](respondWithResult(_0x505acd,null))['catch'](handleError(_0x505acd,null));};exports[_0x2f9e('0x25')]=function(_0x2ff020,_0x26160e){return respondWithRpcPromise(_0x2f9e('0x26'),_[_0x2f9e('0x1c')](_0x2ff020[_0x2f9e('0x18')],_0x2ff020[_0x2f9e('0x1d')]))[_0x2f9e('0x19')](respondWithResult(_0x26160e,null))[_0x2f9e('0xe')](handleError(_0x26160e,null));};exports[_0x2f9e('0x27')]=function(_0x4338df,_0x14dfac){return respondWithRpcPromise(_0x2f9e('0x28'),_0x4338df[_0x2f9e('0x18')])[_0x2f9e('0x19')](respondWithResult(_0x14dfac,null))[_0x2f9e('0xe')](handleError(_0x14dfac,null));};exports[_0x2f9e('0x29')]=function(_0x27687e,_0x1dce1a){return respondWithRpcPromise(_0x2f9e('0x2a'),_0x27687e[_0x2f9e('0x18')])[_0x2f9e('0x19')](respondWithResult(_0x1dce1a,null))[_0x2f9e('0xe')](handleError(_0x1dce1a,null));};exports[_0x2f9e('0x2b')]=function(_0x2d353e,_0x55bedb){var _0x433b63;return respondWithRpcPromise(_0x2f9e('0x2c'),_0x2d353e['query'])[_0x2f9e('0x19')](function(_0x3c477b){_0x433b63=_0x3c477b;return respondWithRpcPromise(_0x2f9e('0x2c'),_0x2d353e[_0x2f9e('0x18')],routingClient);})[_0x2f9e('0x19')](function(_0x271223){return _['merge']({},_0x271223,_0x433b63);})['then'](respondWithResult(_0x55bedb,null))['catch'](handleError(_0x55bedb,null));};exports[_0x2f9e('0x2d')]=function(_0x36d74b,_0xfdd3ec){if(_0x36d74b['body']&&_0x36d74b[_0x2f9e('0x2e')][_0x2f9e('0x2f')]&&_0x36d74b[_0x2f9e('0x30')]&&_0x36d74b[_0x2f9e('0x30')][_0x2f9e('0x12')]){for(var _0x478a3d in _0x36d74b[_0x2f9e('0x2e')][_0x2f9e('0x2f')]){if(_0x36d74b[_0x2f9e('0x2e')]['interaction'][_0x2f9e('0x31')](_0x478a3d)){db[_0x2f9e('0x32')][_0x2f9e('0x33')]({'where':{'channel':_0x478a3d,'membername':_0x36d74b['user'][_0x2f9e('0x12')],'type':_0x2f9e('0x34'),'exitAt':null,'uniqueid':_0x36d74b['body'][_0x2f9e('0x2f')][_0x478a3d]&&_0x36d74b[_0x2f9e('0x2e')][_0x2f9e('0x2f')][_0x478a3d]['length']?{'$notIn':_0x36d74b['body'][_0x2f9e('0x2f')][_0x478a3d]}:{'$ne':null}}})['then'](function(_0x424f8f){var _0x30d9fe=moment()[_0x2f9e('0x35')](_0x2f9e('0x36'));for(var _0x5bf584=0x0,_0x9b8c3d=_0x424f8f[_0x2f9e('0x37')];_0x5bf584<_0x9b8c3d;_0x5bf584+=0x1){_0x424f8f[_0x5bf584][_0x2f9e('0x38')]({'exitAt':_0x30d9fe});}});for(var _0x22d0a1=0x0;_0x22d0a1<_0x36d74b[_0x2f9e('0x2e')][_0x2f9e('0x2f')][_0x478a3d]['length'];_0x22d0a1+=0x1){db[_0x2f9e('0x32')][_0x2f9e('0x39')]({'where':{'channel':_0x478a3d,'membername':_0x36d74b[_0x2f9e('0x30')]['name'],'type':_0x2f9e('0x34'),'uniqueid':_0x36d74b['body'][_0x2f9e('0x2f')][_0x478a3d][_0x22d0a1],'exitAt':null},'defaults':{'channel':_0x478a3d,'membername':_0x36d74b[_0x2f9e('0x30')][_0x2f9e('0x12')],'interface':_[_0x2f9e('0x3a')](_0x36d74b[_0x2f9e('0x30')][_0x2f9e('0x3b')])?util['format'](_0x2f9e('0x3c'),_0x36d74b['user'][_0x2f9e('0x12')]):_0x36d74b[_0x2f9e('0x30')][_0x2f9e('0x3b')],'type':_0x2f9e('0x34'),'enterAt':moment()[_0x2f9e('0x35')](_0x2f9e('0x36')),'role':'agent','internal':_0x36d74b['user'][_0x2f9e('0x3d')],'uniqueid':_0x36d74b[_0x2f9e('0x2e')][_0x2f9e('0x2f')][_0x478a3d][_0x22d0a1]}});}}}}return respondWithRpcPromise(_0x2f9e('0x3e'),{'id':_0x36d74b[_0x2f9e('0x1d')]['id'],'capacity':_0x36d74b[_0x2f9e('0x2e')][_0x2f9e('0x3f')]},routingClient)['then'](respondWithResult(_0xfdd3ec,null))['catch'](handleError(_0xfdd3ec,null));};exports[_0x2f9e('0x40')]=function(_0x2c24ee,_0x2d04fc){return respondWithRpcPromise('Telephones',_0x2c24ee[_0x2f9e('0x18')])[_0x2f9e('0x19')](respondWithResult(_0x2d04fc,null))[_0x2f9e('0xe')](handleError(_0x2d04fc,null));};exports['trunks']=function(_0x2bac31,_0x1c93a0){return respondWithRpcPromise(_0x2f9e('0x41'),_0x2bac31[_0x2f9e('0x18')])[_0x2f9e('0x19')](respondWithResult(_0x1c93a0,null))[_0x2f9e('0xe')](handleError(_0x1c93a0,null));};exports['campaigns']=function(_0x15cb33,_0x293501){return respondWithRpcPromise(_0x2f9e('0x42'),_0x15cb33[_0x2f9e('0x18')])['then'](respondWithResult(_0x293501,null))[_0x2f9e('0xe')](handleError(_0x293501,null));};exports[_0x2f9e('0x43')]=function(_0x36916f,_0xaffaaa){return respondWithRpcPromise(_0x2f9e('0x44'),_0x36916f['query'],routingClient)['then'](respondWithResult(_0xaffaaa,null))[_0x2f9e('0xe')](handleError(_0xaffaaa,null));};exports[_0x2f9e('0x45')]=function(_0x47859b,_0xda56a4){return respondWithRpcPromise(_0x2f9e('0x44'),_0x47859b[_0x2f9e('0x18')],routingClient)['then'](findById(_0x47859b[_0x2f9e('0x1d')]['id']))['then'](respondWithResult(_0xda56a4,null))['catch'](handleError(_0xda56a4,null));};exports[_0x2f9e('0x46')]=function(_0x2e192f,_0x3ca190){return respondWithRpcPromise(_0x2f9e('0x47'),_0x2e192f[_0x2f9e('0x18')],routingClient)[_0x2f9e('0x19')](respondWithResult(_0x3ca190,null))[_0x2f9e('0xe')](handleError(_0x3ca190,null));};exports[_0x2f9e('0x48')]=function(_0x36c504,_0x4b26cd){return respondWithRpcPromise(_0x2f9e('0x47'),_0x36c504['query'],routingClient)[_0x2f9e('0x19')](findById(_0x36c504[_0x2f9e('0x1d')]['id']))['then'](respondWithResult(_0x4b26cd,null))[_0x2f9e('0xe')](handleError(_0x4b26cd,null));};exports['mailAccounts']=function(_0x123de2,_0x2b4afe){return respondWithRpcPromise(_0x2f9e('0x49'),_0x123de2[_0x2f9e('0x18')],mailClient)[_0x2f9e('0x19')](respondWithResult(_0x2b4afe,null))[_0x2f9e('0xe')](handleError(_0x2b4afe,null));};exports[_0x2f9e('0x4a')]=function(_0x1ed1e8,_0x305cf1){return respondWithRpcPromise(_0x2f9e('0x4b'),_0x1ed1e8[_0x2f9e('0x18')],routingClient)[_0x2f9e('0x19')](respondWithResult(_0x305cf1,null))[_0x2f9e('0xe')](handleError(_0x305cf1,null));};exports[_0x2f9e('0x4c')]=function(_0x5d50cb,_0x17f656){return respondWithRpcPromise(_0x2f9e('0x4b'),_0x5d50cb['query'],routingClient)[_0x2f9e('0x19')](findById(_0x5d50cb['params']['id']))['then'](respondWithResult(_0x17f656,null))[_0x2f9e('0xe')](handleError(_0x17f656,null));};exports[_0x2f9e('0x4d')]=function(_0x476c59,_0x5a5705){return respondWithRpcPromise(_0x2f9e('0x4e'),_0x476c59[_0x2f9e('0x18')],routingClient)[_0x2f9e('0x19')](respondWithResult(_0x5a5705,null))['catch'](handleError(_0x5a5705,null));};exports[_0x2f9e('0x4f')]=function(_0x53fe6f,_0xf424e8){return respondWithRpcPromise(_0x2f9e('0x4e'),_0x53fe6f[_0x2f9e('0x18')],routingClient)[_0x2f9e('0x19')](findById(_0x53fe6f[_0x2f9e('0x1d')]['id']))[_0x2f9e('0x19')](respondWithResult(_0xf424e8,null))['catch'](handleError(_0xf424e8,null));};exports[_0x2f9e('0x50')]=function(_0x3bd339,_0x556705){return respondWithRpcPromise(_0x2f9e('0x51'),_0x3bd339['query'],routingClient)['then'](respondWithResult(_0x556705,null))[_0x2f9e('0xe')](handleError(_0x556705,null));};exports[_0x2f9e('0x52')]=function(_0x4e7903,_0xc40d45){return respondWithRpcPromise(_0x2f9e('0x51'),_0x4e7903[_0x2f9e('0x18')],routingClient)[_0x2f9e('0x19')](findById(_0x4e7903[_0x2f9e('0x1d')]['id']))[_0x2f9e('0x19')](respondWithResult(_0xc40d45,null))[_0x2f9e('0xe')](handleError(_0xc40d45,null));};exports[_0x2f9e('0x53')]=function(_0x4c09d0,_0x34f062){return respondWithRpcPromise(_0x2f9e('0x54'),_0x4c09d0[_0x2f9e('0x18')],routingClient)['then'](respondWithResult(_0x34f062,null))['catch'](handleError(_0x34f062,null));};exports[_0x2f9e('0x55')]=function(_0x200dd5,_0x17594f){return respondWithRpcPromise(_0x2f9e('0x54'),_0x200dd5[_0x2f9e('0x18')],routingClient)[_0x2f9e('0x19')](findById(_0x200dd5[_0x2f9e('0x1d')]['id']))[_0x2f9e('0x19')](respondWithResult(_0x17594f,null))[_0x2f9e('0xe')](handleError(_0x17594f,null));};exports['faxAccounts']=function(_0x4e44cb,_0x5ce7d5){return respondWithRpcPromise('FaxAccounts',_0x4e44cb['query'])[_0x2f9e('0x19')](respondWithResult(_0x5ce7d5,null))['catch'](handleError(_0x5ce7d5,null));};exports[_0x2f9e('0x56')]=function(_0x2d251c,_0x4ab651){return respondWithRpcPromise(_0x2f9e('0x57'),_0x2d251c[_0x2f9e('0x18')],routingClient)[_0x2f9e('0x19')](respondWithResult(_0x4ab651,null))[_0x2f9e('0xe')](handleError(_0x4ab651,null));};exports[_0x2f9e('0x58')]=function(_0x4c8511,_0x28b538){return respondWithRpcPromise(_0x2f9e('0x59'),_0x4c8511[_0x2f9e('0x18')],routingClient)[_0x2f9e('0x19')](respondWithResult(_0x28b538,null))[_0x2f9e('0xe')](handleError(_0x28b538,null));};exports[_0x2f9e('0x5a')]=function(_0x32cb2c,_0xe17f80){return respondWithRpcPromise('OpenchannelQueuesWaitingInteractions',_0x32cb2c[_0x2f9e('0x18')],routingClient)[_0x2f9e('0x19')](respondWithResult(_0xe17f80,null))['catch'](handleError(_0xe17f80,null));};exports[_0x2f9e('0x5b')]=function(_0x32eb58,_0x557989){return respondWithRpcPromise(_0x2f9e('0x5c'),_0x32eb58[_0x2f9e('0x18')],routingClient)['then'](respondWithResult(_0x557989,null))[_0x2f9e('0xe')](handleError(_0x557989,null));};exports[_0x2f9e('0x5d')]=function(_0x1d4182,_0x4f5a2c){return respondWithRpcPromise(_0x2f9e('0x5e'),_0x1d4182['query'],routingClient)[_0x2f9e('0x19')](respondWithResult(_0x4f5a2c,null))[_0x2f9e('0xe')](handleError(_0x4f5a2c,null));};exports[_0x2f9e('0x5f')]=function(_0x2c5752,_0x44939e){return respondWithRpcPromise('FaxQueuesWaitingInteractions',_0x2c5752['query'],routingClient)[_0x2f9e('0x19')](respondWithResult(_0x44939e,null))[_0x2f9e('0xe')](handleError(_0x44939e,null));};exports[_0x2f9e('0x60')]=function(_0x330039){return function(_0x2b1b07,_0x1e0782){var _0x4b332b,_0x7ef1e7;var _0x57fd0=_['capitalize'](_0x330039);var _0x37f3bc=_0x330039===_0x2f9e('0x61')?'Website':_0x2f9e('0x62');return db[_0x57fd0+_0x2f9e('0x63')][_0x2f9e('0x64')]({'raw':!![],'where':{'id':_0x2b1b07[_0x2f9e('0x1d')]['id']}})[_0x2f9e('0x19')](function(_0x118b4a){if(_[_0x2f9e('0x3a')](_0x118b4a)){throw new Error(_0x57fd0+'\x20Queue\x20not\x20found');}_0x4b332b=_0x118b4a;return db[_0x57fd0+_0x2f9e('0x65')][_0x2f9e('0x64')]({'where':{'id':_0x2b1b07[_0x2f9e('0x2e')][_0x2f9e('0x66')]},'include':[{'model':db[_0x57fd0+_0x2f9e('0x67')],'as':_0x2f9e('0x67')},{'model':db[_0x57fd0+_0x37f3bc],'as':'Account'}]});})[_0x2f9e('0x19')](function(_0xfb072d){if(_['isNil'](_0xfb072d)){throw new Error(_0x57fd0+_0x2f9e('0x68'));}_0x7ef1e7=_0xfb072d;return _0xfb072d[_0x2f9e('0x69')]({'read':0x0,'readAt':null,'UserId':null});})['then'](function(){var _0x8d54d9={'uniqueid':_0x330039+'.'+_0x7ef1e7['id']+'.'+_0x7ef1e7[_0x2f9e('0x67')]['id'],'FromUserId':_0x2b1b07[_0x2f9e('0x30')]['id'],'type':'queue'};_0x8d54d9[_0x57fd0+'MessageId']=_0x7ef1e7['id'];_0x8d54d9[_0x57fd0+'InteractionId']=_0x7ef1e7[_0x2f9e('0x67')]['id'];_0x8d54d9[_0x2f9e('0x6a')+_0x57fd0+_0x37f3bc+'Id']=_0x7ef1e7[_0x2f9e('0x62')]['id'];_0x8d54d9['To'+_0x57fd0+_0x2f9e('0x6b')]=_0x4b332b['id'];return db[_0x57fd0+_0x2f9e('0x6c')][_0x2f9e('0x6d')](_0x8d54d9);})['then'](function(){return respondWithRpcPromise('Start',{'channel':_0x330039,'interaction':_0x7ef1e7[_0x2f9e('0x67')],'message':_0x7ef1e7,'account':_0x7ef1e7[_0x2f9e('0x62')],'applications':[{'id':0x0,'priority':0x1,'app':_0x2f9e('0x6e'),'appdata':_0x4b332b[_0x2f9e('0x12')]+','+(_0x7ef1e7['Account'][_0x2f9e('0x6f')]||0x12c),'interval':'*,*,*,*'}]},routingClient);})[_0x2f9e('0x19')](respondWithResult(_0x1e0782,null))[_0x2f9e('0xe')](handleError(_0x1e0782,null));};};exports['agentNotify']=function(_0x1dc394,_0x3afbe4){var _0x5c7446,_0x13d29d;if(_[_0x2f9e('0x3a')](_0x1dc394[_0x2f9e('0x2e')]['channel'])){throw new Error('Channel\x20field\x20is\x20mandatory');}var _0x49d18a=_0x1dc394[_0x2f9e('0x2e')][_0x2f9e('0x70')];var _0x16eaf8=_[_0x2f9e('0x71')](_0x49d18a);var _0x18aa19=_0x49d18a===_0x2f9e('0x61')?'Website':_0x2f9e('0x62');return db[_0x2f9e('0x72')][_0x2f9e('0x64')]({'raw':!![],'where':{'id':_0x1dc394['params']['id'],'role':_0x2f9e('0x73')}})['then'](function(_0x3c961c){if(_[_0x2f9e('0x3a')](_0x3c961c)){throw new Error('Agent\x20not\x20found');}_0x5c7446=_0x3c961c;return db[_0x16eaf8+_0x2f9e('0x65')][_0x2f9e('0x64')]({'where':{'id':_0x1dc394['body']['messageId']},'include':[{'model':db[_0x16eaf8+'Interaction'],'as':_0x2f9e('0x67')},{'model':db[_0x16eaf8+_0x18aa19],'as':_0x2f9e('0x62')}]});})[_0x2f9e('0x19')](function(_0x33fbb0){if(_[_0x2f9e('0x3a')](_0x33fbb0)){throw new Error(_0x16eaf8+_0x2f9e('0x68'));}_0x13d29d=_0x33fbb0;return _0x33fbb0[_0x2f9e('0x69')]({'read':0x0,'readAt':null,'UserId':null});})[_0x2f9e('0x19')](function(){var _0x3a9a72={'uniqueid':_0x49d18a+'.'+_0x13d29d['id']+'.'+_0x13d29d['Interaction']['id'],'FromUserId':_0x1dc394['user']['id'],'type':_0x2f9e('0x6e'),'ToUserId':_0x5c7446['id']};_0x3a9a72[_0x16eaf8+_0x2f9e('0x74')]=_0x13d29d['id'];_0x3a9a72[_0x16eaf8+_0x2f9e('0x75')]=_0x13d29d['Interaction']['id'];_0x3a9a72[_0x2f9e('0x6a')+_0x16eaf8+_0x18aa19+'Id']=_0x13d29d[_0x2f9e('0x62')]['id'];return db[_0x16eaf8+_0x2f9e('0x6c')][_0x2f9e('0x6d')](_0x3a9a72);})[_0x2f9e('0x19')](function(){return respondWithRpcPromise(_0x2f9e('0x76'),{'channel':_0x49d18a,'interaction':_0x13d29d[_0x2f9e('0x67')],'message':_0x13d29d,'account':_0x13d29d[_0x2f9e('0x62')],'applications':[{'id':0x0,'priority':0x1,'app':_0x2f9e('0x73'),'appdata':_0x5c7446[_0x2f9e('0x12')]+','+(_0x13d29d[_0x2f9e('0x62')][_0x2f9e('0x77')]||0x12c),'interval':_0x2f9e('0x78')}]},routingClient);})[_0x2f9e('0x19')](respondWithResult(_0x3afbe4,null))[_0x2f9e('0xe')](handleError(_0x3afbe4,null));};