2f885ca65d5b2c9be89639a16b6bbd39bc476d3f
[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 _0xac72=['Website','Account','Queue','\x20Queue\x20not\x20found','findOne','messageId','Interaction','update','queue','MessageId','InteractionId','From','QueueId','TransferReport','queueTransferTimeout','*,*,*,*','agentNotify','Channel\x20field\x20is\x20mandatory','Agent\x20not\x20found','Message','\x20Message\x20not\x20found','create','agentTransferTimeout','bluebird','moment','lodash','util','../../config/logger','api','client','http','request','then','error','code','message','result','catch','status','json','name','send','isNil','rows','find','VoiceChannels','query','VoiceChannelMixMonitor','merge','VoiceChannelStopMixMonitor','params','VoiceQueues','showVoiceQueues','voiceQueuesPreview','VoiceQueuesPreview','voiceQueuesChannels','VoiceQueuesChannels','voiceQueuesChannel','VoiceQueuesChannel','voiceQueuesChannelHangup','VoiceQueuesChannelHangup','voiceQueuesChannelRedirect','VoiceQueuesChannelRedirect','Outbound','OutboundChannels','agents','Agents','agentCapacity','body','user','interaction','hasOwnProperty','MemberReport','findAll','INTERACTION','length','format','updateAttributes','findOrCreate','interface','SIP/%s','YYYY-MM-DD\x20HH:mm:ss','agent','internal','AgentCapacity','capacity','telephones','Telephones','trunks','campaigns','Campaigns','chatQueues','showChatQueues','ChatQueues','mailQueues','showMailQueues','MailQueues','openchannelQueues','OpenchannelQueues','showOpenchannelQueues','smsQueues','showSmsQueues','SmsQueues','faxQueues','FaxQueues','showFaxQueues','chatQueuesWaitingInteractions','ChatQueuesWaitingInteractions','smsQueuesWaitingInteractions','SmsQueuesWaitingInteractions','faxQueuesWaitingInteractions','FaxQueuesWaitingInteractions','queueNotify','capitalize'];(function(_0x50ae92,_0x11e899){var _0x375128=function(_0xbdc369){while(--_0xbdc369){_0x50ae92['push'](_0x50ae92['shift']());}};_0x375128(++_0x11e899);}(_0xac72,0xfb));var _0x2ac7=function(_0xd0e8e3,_0x225e3a){_0xd0e8e3=_0xd0e8e3-0x0;var _0x331828=_0xac72[_0xd0e8e3];return _0x331828;};'use strict';var BPromise=require(_0x2ac7('0x0'));var moment=require(_0x2ac7('0x1'));var _=require(_0x2ac7('0x2'));var util=require(_0x2ac7('0x3'));var db=require('../../mysqldb')['db'];var logger=require(_0x2ac7('0x4'))(_0x2ac7('0x5'));var jayson=require('jayson/promise');var amiClient=jayson[_0x2ac7('0x6')][_0x2ac7('0x7')]({'port':0x232a});var mailClient=jayson[_0x2ac7('0x6')][_0x2ac7('0x7')]({'port':0x232b});var routingClient=jayson['client']['http']({'port':0x232c});function respondWithRpcPromise(_0x357a95,_0x310c03,_0x2c1ace){return new BPromise(function(_0x232bff,_0x190c4d){var _0x3a3e9d=_0x2c1ace?_0x2c1ace:amiClient;return _0x3a3e9d[_0x2ac7('0x8')](_0x357a95,_0x310c03)[_0x2ac7('0x9')](function(_0x25294f){if(_0x25294f[_0x2ac7('0xa')]){if(_0x25294f['error'][_0x2ac7('0xb')]===0x1f4){return _0x190c4d(_0x25294f[_0x2ac7('0xa')][_0x2ac7('0xc')]);}return _0x232bff(_0x25294f[_0x2ac7('0xa')][_0x2ac7('0xc')]);}else{_0x232bff(_0x25294f[_0x2ac7('0xd')]);}})[_0x2ac7('0xe')](function(_0x5b44d1){_0x190c4d(_0x5b44d1);});});}function respondWithResult(_0x24d533,_0x3fd61e){_0x3fd61e=_0x3fd61e||0xc8;return function(_0xa12b90){if(_0xa12b90){return _0x24d533[_0x2ac7('0xf')](_0x3fd61e)[_0x2ac7('0x10')](_0xa12b90);}return _0x24d533['sendStatus'](0x194);};}function handleError(_0x75f793,_0x291a1b){_0x291a1b=_0x291a1b||0x1f4;return function(_0x5938f5){logger[_0x2ac7('0xa')](_0x5938f5['stack']);if(_0x5938f5[_0x2ac7('0x11')]){delete _0x5938f5['name'];}_0x75f793[_0x2ac7('0xf')](_0x291a1b)[_0x2ac7('0x12')](_0x5938f5);};}function findById(_0x1a8484){return function(_0x3b2625){if(!_[_0x2ac7('0x13')](_0x1a8484)&&!_[_0x2ac7('0x13')](_0x3b2625)&&!_['isNil'](_0x3b2625[_0x2ac7('0x14')])){return _[_0x2ac7('0x15')](_0x3b2625[_0x2ac7('0x14')],function(_0x513131){return _0x513131['id']==_0x1a8484;});}return null;};}exports['voiceChannels']=function(_0x256409,_0x41dedd){return respondWithRpcPromise(_0x2ac7('0x16'),_0x256409[_0x2ac7('0x17')])[_0x2ac7('0x9')](respondWithResult(_0x41dedd,null))[_0x2ac7('0xe')](handleError(_0x41dedd,null));};exports['voiceChannelMixMonitor']=function(_0xd14f5d,_0x2d4e20){return respondWithRpcPromise(_0x2ac7('0x18'),_[_0x2ac7('0x19')](_0xd14f5d[_0x2ac7('0x17')],_0xd14f5d['params']))['then'](respondWithResult(_0x2d4e20,null))[_0x2ac7('0xe')](handleError(_0x2d4e20,null));};exports['voiceChannelStopMixMonitor']=function(_0x5acfaf,_0x706db1){return respondWithRpcPromise(_0x2ac7('0x1a'),_['merge'](_0x5acfaf[_0x2ac7('0x17')],_0x5acfaf[_0x2ac7('0x1b')]))[_0x2ac7('0x9')](respondWithResult(_0x706db1,null))[_0x2ac7('0xe')](handleError(_0x706db1,null));};exports['voiceQueues']=function(_0x21d8ec,_0x1f94d2){return respondWithRpcPromise(_0x2ac7('0x1c'),_0x21d8ec['query'])[_0x2ac7('0x9')](respondWithResult(_0x1f94d2,null))[_0x2ac7('0xe')](handleError(_0x1f94d2,null));};exports[_0x2ac7('0x1d')]=function(_0x26f8c0,_0x5d162c){return respondWithRpcPromise(_0x2ac7('0x1c'),_0x26f8c0[_0x2ac7('0x17')])[_0x2ac7('0x9')](findById(_0x26f8c0['params']['id']))['then'](respondWithResult(_0x5d162c,null))[_0x2ac7('0xe')](handleError(_0x5d162c,null));};exports[_0x2ac7('0x1e')]=function(_0x5c9741,_0x1e6a3b){return respondWithRpcPromise(_0x2ac7('0x1f'),_[_0x2ac7('0x19')](_0x5c9741[_0x2ac7('0x17')],_0x5c9741['params']))[_0x2ac7('0x9')](respondWithResult(_0x1e6a3b,null))[_0x2ac7('0xe')](handleError(_0x1e6a3b,null));};exports[_0x2ac7('0x20')]=function(_0x1a1765,_0x5151e6){return respondWithRpcPromise(_0x2ac7('0x21'),_0x1a1765[_0x2ac7('0x17')])[_0x2ac7('0x9')](respondWithResult(_0x5151e6,null))[_0x2ac7('0xe')](handleError(_0x5151e6,null));};exports[_0x2ac7('0x22')]=function(_0x2fc600,_0x19a43a){return respondWithRpcPromise(_0x2ac7('0x23'),_[_0x2ac7('0x19')](_0x2fc600[_0x2ac7('0x17')],_0x2fc600['params']))[_0x2ac7('0x9')](respondWithResult(_0x19a43a,null))[_0x2ac7('0xe')](handleError(_0x19a43a,null));};exports[_0x2ac7('0x24')]=function(_0x1730ab,_0x4b3f46){return respondWithRpcPromise(_0x2ac7('0x25'),_[_0x2ac7('0x19')](_0x1730ab[_0x2ac7('0x17')],_0x1730ab[_0x2ac7('0x1b')]))[_0x2ac7('0x9')](respondWithResult(_0x4b3f46,null))['catch'](handleError(_0x4b3f46,null));};exports[_0x2ac7('0x26')]=function(_0x59779a,_0x1d01c7){return respondWithRpcPromise(_0x2ac7('0x27'),_['merge'](_0x59779a[_0x2ac7('0x17')],_0x59779a[_0x2ac7('0x1b')]))['then'](respondWithResult(_0x1d01c7,null))[_0x2ac7('0xe')](handleError(_0x1d01c7,null));};exports['outbound']=function(_0x59a11c,_0x5ce257){return respondWithRpcPromise(_0x2ac7('0x28'),_0x59a11c[_0x2ac7('0x17')])[_0x2ac7('0x9')](respondWithResult(_0x5ce257,null))[_0x2ac7('0xe')](handleError(_0x5ce257,null));};exports['outboundChannels']=function(_0x1d9bc9,_0x1b0131){return respondWithRpcPromise(_0x2ac7('0x29'),_0x1d9bc9[_0x2ac7('0x17')])['then'](respondWithResult(_0x1b0131,null))['catch'](handleError(_0x1b0131,null));};exports[_0x2ac7('0x2a')]=function(_0x1a360f,_0x2b6ab0){var _0x3c752c;return respondWithRpcPromise(_0x2ac7('0x2b'),_0x1a360f[_0x2ac7('0x17')])[_0x2ac7('0x9')](function(_0x5a6d06){_0x3c752c=_0x5a6d06;return respondWithRpcPromise(_0x2ac7('0x2b'),_0x1a360f['query'],routingClient);})[_0x2ac7('0x9')](function(_0x4f39bb){return _[_0x2ac7('0x19')]({},_0x4f39bb,_0x3c752c);})[_0x2ac7('0x9')](respondWithResult(_0x2b6ab0,null))['catch'](handleError(_0x2b6ab0,null));};exports[_0x2ac7('0x2c')]=function(_0x2a9315,_0x4142ae){if(_0x2a9315[_0x2ac7('0x2d')]&&_0x2a9315[_0x2ac7('0x2d')]['interaction']&&_0x2a9315['user']&&_0x2a9315[_0x2ac7('0x2e')][_0x2ac7('0x11')]){for(var _0x4a4758 in _0x2a9315['body'][_0x2ac7('0x2f')]){if(_0x2a9315['body'][_0x2ac7('0x2f')][_0x2ac7('0x30')](_0x4a4758)){db[_0x2ac7('0x31')][_0x2ac7('0x32')]({'where':{'channel':_0x4a4758,'membername':_0x2a9315[_0x2ac7('0x2e')][_0x2ac7('0x11')],'type':_0x2ac7('0x33'),'exitAt':null,'uniqueid':_0x2a9315[_0x2ac7('0x2d')]['interaction'][_0x4a4758]&&_0x2a9315[_0x2ac7('0x2d')]['interaction'][_0x4a4758][_0x2ac7('0x34')]?{'$notIn':_0x2a9315[_0x2ac7('0x2d')][_0x2ac7('0x2f')][_0x4a4758]}:{'$ne':null}}})[_0x2ac7('0x9')](function(_0x1d1633){var _0x523fb2=moment()[_0x2ac7('0x35')]('YYYY-MM-DD\x20HH:mm:ss');for(var _0x429352=0x0,_0x111043=_0x1d1633['length'];_0x429352<_0x111043;_0x429352+=0x1){_0x1d1633[_0x429352][_0x2ac7('0x36')]({'exitAt':_0x523fb2});}});for(var _0x51949b=0x0;_0x51949b<_0x2a9315['body']['interaction'][_0x4a4758]['length'];_0x51949b+=0x1){db[_0x2ac7('0x31')][_0x2ac7('0x37')]({'where':{'channel':_0x4a4758,'membername':_0x2a9315[_0x2ac7('0x2e')][_0x2ac7('0x11')],'type':_0x2ac7('0x33'),'uniqueid':_0x2a9315[_0x2ac7('0x2d')][_0x2ac7('0x2f')][_0x4a4758][_0x51949b],'exitAt':null},'defaults':{'channel':_0x4a4758,'membername':_0x2a9315['user'][_0x2ac7('0x11')],'interface':_[_0x2ac7('0x13')](_0x2a9315[_0x2ac7('0x2e')][_0x2ac7('0x38')])?util[_0x2ac7('0x35')](_0x2ac7('0x39'),_0x2a9315[_0x2ac7('0x2e')][_0x2ac7('0x11')]):_0x2a9315[_0x2ac7('0x2e')]['interface'],'type':_0x2ac7('0x33'),'enterAt':moment()['format'](_0x2ac7('0x3a')),'role':_0x2ac7('0x3b'),'internal':_0x2a9315['user'][_0x2ac7('0x3c')],'uniqueid':_0x2a9315['body'][_0x2ac7('0x2f')][_0x4a4758][_0x51949b]}});}}}}return respondWithRpcPromise(_0x2ac7('0x3d'),{'id':_0x2a9315[_0x2ac7('0x1b')]['id'],'capacity':_0x2a9315[_0x2ac7('0x2d')][_0x2ac7('0x3e')]},routingClient)['then'](respondWithResult(_0x4142ae,null))[_0x2ac7('0xe')](handleError(_0x4142ae,null));};exports[_0x2ac7('0x3f')]=function(_0x484be6,_0x4f866c){return respondWithRpcPromise(_0x2ac7('0x40'),_0x484be6['query'])[_0x2ac7('0x9')](respondWithResult(_0x4f866c,null))[_0x2ac7('0xe')](handleError(_0x4f866c,null));};exports[_0x2ac7('0x41')]=function(_0xed8823,_0x242d0d){return respondWithRpcPromise('Trunks',_0xed8823[_0x2ac7('0x17')])['then'](respondWithResult(_0x242d0d,null))['catch'](handleError(_0x242d0d,null));};exports[_0x2ac7('0x42')]=function(_0x45fef4,_0x428163){return respondWithRpcPromise(_0x2ac7('0x43'),_0x45fef4[_0x2ac7('0x17')])['then'](respondWithResult(_0x428163,null))[_0x2ac7('0xe')](handleError(_0x428163,null));};exports[_0x2ac7('0x44')]=function(_0x21ce3a,_0x1f478e){return respondWithRpcPromise('ChatQueues',_0x21ce3a[_0x2ac7('0x17')],routingClient)[_0x2ac7('0x9')](respondWithResult(_0x1f478e,null))[_0x2ac7('0xe')](handleError(_0x1f478e,null));};exports[_0x2ac7('0x45')]=function(_0x2a44fa,_0x5a338){return respondWithRpcPromise(_0x2ac7('0x46'),_0x2a44fa[_0x2ac7('0x17')],routingClient)[_0x2ac7('0x9')](findById(_0x2a44fa[_0x2ac7('0x1b')]['id']))[_0x2ac7('0x9')](respondWithResult(_0x5a338,null))[_0x2ac7('0xe')](handleError(_0x5a338,null));};exports[_0x2ac7('0x47')]=function(_0x13e0fb,_0x37f57d){return respondWithRpcPromise('MailQueues',_0x13e0fb[_0x2ac7('0x17')],routingClient)[_0x2ac7('0x9')](respondWithResult(_0x37f57d,null))[_0x2ac7('0xe')](handleError(_0x37f57d,null));};exports[_0x2ac7('0x48')]=function(_0x3675ba,_0x3e0004){return respondWithRpcPromise(_0x2ac7('0x49'),_0x3675ba[_0x2ac7('0x17')],routingClient)['then'](findById(_0x3675ba['params']['id']))[_0x2ac7('0x9')](respondWithResult(_0x3e0004,null))[_0x2ac7('0xe')](handleError(_0x3e0004,null));};exports['mailAccounts']=function(_0x13dbe6,_0x155b68){return respondWithRpcPromise('MailAccounts',_0x13dbe6[_0x2ac7('0x17')],mailClient)[_0x2ac7('0x9')](respondWithResult(_0x155b68,null))[_0x2ac7('0xe')](handleError(_0x155b68,null));};exports[_0x2ac7('0x4a')]=function(_0x3b90c6,_0x45a83c){return respondWithRpcPromise(_0x2ac7('0x4b'),_0x3b90c6[_0x2ac7('0x17')],routingClient)[_0x2ac7('0x9')](respondWithResult(_0x45a83c,null))[_0x2ac7('0xe')](handleError(_0x45a83c,null));};exports[_0x2ac7('0x4c')]=function(_0x579da9,_0xda6813){return respondWithRpcPromise('OpenchannelQueues',_0x579da9[_0x2ac7('0x17')],routingClient)[_0x2ac7('0x9')](findById(_0x579da9[_0x2ac7('0x1b')]['id']))[_0x2ac7('0x9')](respondWithResult(_0xda6813,null))[_0x2ac7('0xe')](handleError(_0xda6813,null));};exports[_0x2ac7('0x4d')]=function(_0x78f118,_0x5541fd){return respondWithRpcPromise('SmsQueues',_0x78f118[_0x2ac7('0x17')],routingClient)[_0x2ac7('0x9')](respondWithResult(_0x5541fd,null))[_0x2ac7('0xe')](handleError(_0x5541fd,null));};exports[_0x2ac7('0x4e')]=function(_0x7ab662,_0x370a40){return respondWithRpcPromise(_0x2ac7('0x4f'),_0x7ab662['query'],routingClient)['then'](findById(_0x7ab662[_0x2ac7('0x1b')]['id']))[_0x2ac7('0x9')](respondWithResult(_0x370a40,null))[_0x2ac7('0xe')](handleError(_0x370a40,null));};exports[_0x2ac7('0x50')]=function(_0x4a7569,_0x4fa2b9){return respondWithRpcPromise(_0x2ac7('0x51'),_0x4a7569[_0x2ac7('0x17')],routingClient)[_0x2ac7('0x9')](respondWithResult(_0x4fa2b9,null))[_0x2ac7('0xe')](handleError(_0x4fa2b9,null));};exports[_0x2ac7('0x52')]=function(_0x579530,_0x57f7d5){return respondWithRpcPromise(_0x2ac7('0x51'),_0x579530[_0x2ac7('0x17')],routingClient)[_0x2ac7('0x9')](findById(_0x579530[_0x2ac7('0x1b')]['id']))[_0x2ac7('0x9')](respondWithResult(_0x57f7d5,null))[_0x2ac7('0xe')](handleError(_0x57f7d5,null));};exports['faxAccounts']=function(_0x3667e2,_0x1e1d56){return respondWithRpcPromise('FaxAccounts',_0x3667e2['query'])[_0x2ac7('0x9')](respondWithResult(_0x1e1d56,null))[_0x2ac7('0xe')](handleError(_0x1e1d56,null));};exports[_0x2ac7('0x53')]=function(_0x2318b2,_0x29155f){return respondWithRpcPromise(_0x2ac7('0x54'),_0x2318b2[_0x2ac7('0x17')],routingClient)[_0x2ac7('0x9')](respondWithResult(_0x29155f,null))[_0x2ac7('0xe')](handleError(_0x29155f,null));};exports['mailQueuesWaitingInteractions']=function(_0x3b99a0,_0x6462f2){return respondWithRpcPromise('MailQueuesWaitingInteractions',_0x3b99a0[_0x2ac7('0x17')],routingClient)['then'](respondWithResult(_0x6462f2,null))['catch'](handleError(_0x6462f2,null));};exports['openchannelQueuesWaitingInteractions']=function(_0x341a7a,_0x10f70c){return respondWithRpcPromise('OpenchannelQueuesWaitingInteractions',_0x341a7a[_0x2ac7('0x17')],routingClient)['then'](respondWithResult(_0x10f70c,null))['catch'](handleError(_0x10f70c,null));};exports[_0x2ac7('0x55')]=function(_0x40be47,_0x137051){return respondWithRpcPromise(_0x2ac7('0x56'),_0x40be47[_0x2ac7('0x17')],routingClient)[_0x2ac7('0x9')](respondWithResult(_0x137051,null))[_0x2ac7('0xe')](handleError(_0x137051,null));};exports[_0x2ac7('0x57')]=function(_0x3eaa33,_0x31b4db){return respondWithRpcPromise(_0x2ac7('0x58'),_0x3eaa33[_0x2ac7('0x17')],routingClient)[_0x2ac7('0x9')](respondWithResult(_0x31b4db,null))[_0x2ac7('0xe')](handleError(_0x31b4db,null));};exports[_0x2ac7('0x59')]=function(_0x233ce2){return function(_0x4d1965,_0x16e675){var _0x10af9f,_0x29810c;var _0x4d5cae=_[_0x2ac7('0x5a')](_0x233ce2);var _0x253e40=_0x233ce2==='chat'?_0x2ac7('0x5b'):_0x2ac7('0x5c');return db[_0x4d5cae+_0x2ac7('0x5d')]['findOne']({'raw':!![],'where':{'id':_0x4d1965['params']['id']}})[_0x2ac7('0x9')](function(_0x54136b){if(_[_0x2ac7('0x13')](_0x54136b)){throw new Error(_0x4d5cae+_0x2ac7('0x5e'));}_0x10af9f=_0x54136b;return db[_0x4d5cae+'Message'][_0x2ac7('0x5f')]({'where':{'id':_0x4d1965[_0x2ac7('0x2d')][_0x2ac7('0x60')]},'include':[{'model':db[_0x4d5cae+_0x2ac7('0x61')],'as':'Interaction'},{'model':db[_0x4d5cae+_0x253e40],'as':_0x2ac7('0x5c')}]});})[_0x2ac7('0x9')](function(_0x5d6ec0){if(_[_0x2ac7('0x13')](_0x5d6ec0)){throw new Error(_0x4d5cae+'\x20Message\x20not\x20found');}_0x29810c=_0x5d6ec0;return _0x5d6ec0[_0x2ac7('0x62')]({'read':0x0,'readAt':null,'UserId':null});})['then'](function(){var _0x10fb6e={'uniqueid':_0x233ce2+'.'+_0x29810c['id']+'.'+_0x29810c[_0x2ac7('0x61')]['id'],'FromUserId':_0x4d1965[_0x2ac7('0x2e')]['id'],'type':_0x2ac7('0x63')};_0x10fb6e[_0x4d5cae+_0x2ac7('0x64')]=_0x29810c['id'];_0x10fb6e[_0x4d5cae+_0x2ac7('0x65')]=_0x29810c['Interaction']['id'];_0x10fb6e[_0x2ac7('0x66')+_0x4d5cae+_0x253e40+'Id']=_0x29810c[_0x2ac7('0x5c')]['id'];_0x10fb6e['To'+_0x4d5cae+_0x2ac7('0x67')]=_0x10af9f['id'];return db[_0x4d5cae+_0x2ac7('0x68')]['create'](_0x10fb6e);})['then'](function(){return respondWithRpcPromise('Start',{'channel':_0x233ce2,'interaction':_0x29810c[_0x2ac7('0x61')],'message':_0x29810c,'account':_0x29810c[_0x2ac7('0x5c')],'applications':[{'id':0x0,'priority':0x1,'app':_0x2ac7('0x63'),'appdata':_0x10af9f[_0x2ac7('0x11')]+','+(_0x29810c[_0x2ac7('0x5c')][_0x2ac7('0x69')]||0x12c),'interval':_0x2ac7('0x6a')}]},routingClient);})['then'](respondWithResult(_0x16e675,null))[_0x2ac7('0xe')](handleError(_0x16e675,null));};};exports[_0x2ac7('0x6b')]=function(_0x1e0b45,_0x276fbf){var _0x3e5ad7,_0x2bbbd1;if(_['isNil'](_0x1e0b45[_0x2ac7('0x2d')]['channel'])){throw new Error(_0x2ac7('0x6c'));}var _0x27814f=_0x1e0b45['body']['channel'];var _0x208409=_['capitalize'](_0x27814f);var _0x17ea62=_0x27814f==='chat'?_0x2ac7('0x5b'):_0x2ac7('0x5c');return db['User']['findOne']({'raw':!![],'where':{'id':_0x1e0b45[_0x2ac7('0x1b')]['id'],'role':_0x2ac7('0x3b')}})[_0x2ac7('0x9')](function(_0x10c0a9){if(_[_0x2ac7('0x13')](_0x10c0a9)){throw new Error(_0x2ac7('0x6d'));}_0x3e5ad7=_0x10c0a9;return db[_0x208409+_0x2ac7('0x6e')][_0x2ac7('0x5f')]({'where':{'id':_0x1e0b45[_0x2ac7('0x2d')]['messageId']},'include':[{'model':db[_0x208409+'Interaction'],'as':_0x2ac7('0x61')},{'model':db[_0x208409+_0x17ea62],'as':_0x2ac7('0x5c')}]});})[_0x2ac7('0x9')](function(_0x3cf331){if(_[_0x2ac7('0x13')](_0x3cf331)){throw new Error(_0x208409+_0x2ac7('0x6f'));}_0x2bbbd1=_0x3cf331;return _0x3cf331['update']({'read':0x0,'readAt':null,'UserId':null});})[_0x2ac7('0x9')](function(){var _0x5c8600={'uniqueid':_0x27814f+'.'+_0x2bbbd1['id']+'.'+_0x2bbbd1[_0x2ac7('0x61')]['id'],'FromUserId':_0x1e0b45[_0x2ac7('0x2e')]['id'],'type':_0x2ac7('0x63'),'ToUserId':_0x3e5ad7['id']};_0x5c8600[_0x208409+'MessageId']=_0x2bbbd1['id'];_0x5c8600[_0x208409+_0x2ac7('0x65')]=_0x2bbbd1[_0x2ac7('0x61')]['id'];_0x5c8600[_0x2ac7('0x66')+_0x208409+_0x17ea62+'Id']=_0x2bbbd1[_0x2ac7('0x5c')]['id'];return db[_0x208409+_0x2ac7('0x68')][_0x2ac7('0x70')](_0x5c8600);})[_0x2ac7('0x9')](function(){return respondWithRpcPromise('Start',{'channel':_0x27814f,'interaction':_0x2bbbd1[_0x2ac7('0x61')],'message':_0x2bbbd1,'account':_0x2bbbd1[_0x2ac7('0x5c')],'applications':[{'id':0x0,'priority':0x1,'app':_0x2ac7('0x3b'),'appdata':_0x3e5ad7[_0x2ac7('0x11')]+','+(_0x2bbbd1[_0x2ac7('0x5c')][_0x2ac7('0x71')]||0x12c),'interval':_0x2ac7('0x6a')}]},routingClient);})[_0x2ac7('0x9')](respondWithResult(_0x276fbf,null))[_0x2ac7('0xe')](handleError(_0x276fbf,null));};