6da80ffbd9b8b6557b97bf60163d43269ee20876
[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 _0x6d26=['jayson/promise','client','http','request','then','error','message','result','catch','status','json','sendStatus','stack','name','send','isNil','find','rows','voiceChannels','voiceChannelMixMonitor','VoiceChannelMixMonitor','merge','params','voiceChannelStopMixMonitor','query','voiceQueues','VoiceQueues','voiceQueuesPreview','VoiceQueuesPreview','voiceQueuesChannels','VoiceQueuesChannel','voiceQueuesChannelHangup','VoiceQueuesChannelRedirect','outbound','Outbound','outboundChannels','agents','Agents','body','interaction','hasOwnProperty','MemberReport','findAll','user','INTERACTION','length','format','YYYY-MM-DD\x20HH:mm:ss','updateAttributes','interface','SIP/%s','agent','internal','telephones','Telephones','Trunks','campaigns','Campaigns','chatQueues','showChatQueues','ChatQueues','mailQueues','showMailQueues','MailQueues','OpenchannelQueues','showOpenchannelQueues','smsQueues','SmsQueues','showSmsQueues','whatsappQueues','WhatsappQueues','showWhatsappQueues','faxQueues','FaxQueues','faxAccounts','chatQueuesWaitingInteractions','ChatQueuesWaitingInteractions','mailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','OpenchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','SmsQueuesWaitingInteractions','whatsappQueuesWaitingInteractions','faxQueuesWaitingInteractions','FaxQueuesWaitingInteractions','queueNotify','capitalize','chat','Account','Queue','findOne','\x20Queue\x20not\x20found','Message','messageId','Interaction','\x20Message\x20not\x20found','queue','MessageId','InteractionId','TransferReport','Start','*,*,*,*','agentNotify','channel','Website','User','Agent\x20not\x20found','update','From','create','agentTransferTimeout','bluebird','moment','util','../../mysqldb','../../config/logger','api'];(function(_0x2bc1e5,_0x93f3d7){var _0x54617c=function(_0x59c832){while(--_0x59c832){_0x2bc1e5['push'](_0x2bc1e5['shift']());}};_0x54617c(++_0x93f3d7);}(_0x6d26,0xe4));var _0x66d2=function(_0x5835e9,_0x2f1605){_0x5835e9=_0x5835e9-0x0;var _0x192877=_0x6d26[_0x5835e9];return _0x192877;};'use strict';var BPromise=require(_0x66d2('0x0'));var moment=require(_0x66d2('0x1'));var _=require('lodash');var util=require(_0x66d2('0x2'));var db=require(_0x66d2('0x3'))['db'];var logger=require(_0x66d2('0x4'))(_0x66d2('0x5'));var jayson=require(_0x66d2('0x6'));var amiClient=jayson[_0x66d2('0x7')]['http']({'port':0x232a});var mailClient=jayson[_0x66d2('0x7')][_0x66d2('0x8')]({'port':0x232b});var routingClient=jayson[_0x66d2('0x7')][_0x66d2('0x8')]({'port':0x232c});function respondWithRpcPromise(_0x28a81d,_0x52a48d,_0x3299f2){return new BPromise(function(_0x1b6365,_0x4174e6){var _0x47aa10=_0x3299f2?_0x3299f2:amiClient;return _0x47aa10[_0x66d2('0x9')](_0x28a81d,_0x52a48d)[_0x66d2('0xa')](function(_0x9cdddc){if(_0x9cdddc[_0x66d2('0xb')]){if(_0x9cdddc['error']['code']===0x1f4){return _0x4174e6(_0x9cdddc[_0x66d2('0xb')][_0x66d2('0xc')]);}return _0x1b6365(_0x9cdddc['error'][_0x66d2('0xc')]);}else{_0x1b6365(_0x9cdddc[_0x66d2('0xd')]);}})[_0x66d2('0xe')](function(_0x2179a3){_0x4174e6(_0x2179a3);});});}function respondWithResult(_0x53d569,_0xf92809){_0xf92809=_0xf92809||0xc8;return function(_0x5700b9){if(_0x5700b9){return _0x53d569[_0x66d2('0xf')](_0xf92809)[_0x66d2('0x10')](_0x5700b9);}return _0x53d569[_0x66d2('0x11')](0x194);};}function handleError(_0x93d8e9,_0x37739c){_0x37739c=_0x37739c||0x1f4;return function(_0xf0596e){logger[_0x66d2('0xb')](_0xf0596e[_0x66d2('0x12')]);if(_0xf0596e[_0x66d2('0x13')]){delete _0xf0596e[_0x66d2('0x13')];}_0x93d8e9[_0x66d2('0xf')](_0x37739c)[_0x66d2('0x14')](_0xf0596e);};}function findById(_0xc62bd9){return function(_0x4d57e9){if(!_[_0x66d2('0x15')](_0xc62bd9)&&!_['isNil'](_0x4d57e9)&&!_[_0x66d2('0x15')](_0x4d57e9['rows'])){return _[_0x66d2('0x16')](_0x4d57e9[_0x66d2('0x17')],function(_0x57d986){return _0x57d986['id']==_0xc62bd9;});}return null;};}exports[_0x66d2('0x18')]=function(_0xa0f5da,_0x577677){return respondWithRpcPromise('VoiceChannels',_0xa0f5da['query'])['then'](respondWithResult(_0x577677,null))['catch'](handleError(_0x577677,null));};exports[_0x66d2('0x19')]=function(_0xe3497b,_0x9ae326){return respondWithRpcPromise(_0x66d2('0x1a'),_[_0x66d2('0x1b')](_0xe3497b['query'],_0xe3497b[_0x66d2('0x1c')]))['then'](respondWithResult(_0x9ae326,null))['catch'](handleError(_0x9ae326,null));};exports[_0x66d2('0x1d')]=function(_0x3cb6a4,_0x2003d5){return respondWithRpcPromise('VoiceChannelStopMixMonitor',_[_0x66d2('0x1b')](_0x3cb6a4[_0x66d2('0x1e')],_0x3cb6a4['params']))[_0x66d2('0xa')](respondWithResult(_0x2003d5,null))['catch'](handleError(_0x2003d5,null));};exports[_0x66d2('0x1f')]=function(_0x1e1449,_0x102040){return respondWithRpcPromise(_0x66d2('0x20'),_0x1e1449[_0x66d2('0x1e')])[_0x66d2('0xa')](respondWithResult(_0x102040,null))[_0x66d2('0xe')](handleError(_0x102040,null));};exports['showVoiceQueues']=function(_0x34deee,_0xb748a7){return respondWithRpcPromise('VoiceQueues',_0x34deee[_0x66d2('0x1e')])['then'](findById(_0x34deee['params']['id']))[_0x66d2('0xa')](respondWithResult(_0xb748a7,null))[_0x66d2('0xe')](handleError(_0xb748a7,null));};exports[_0x66d2('0x21')]=function(_0x46000e,_0xd29309){return respondWithRpcPromise(_0x66d2('0x22'),_[_0x66d2('0x1b')](_0x46000e[_0x66d2('0x1e')],_0x46000e[_0x66d2('0x1c')]))['then'](respondWithResult(_0xd29309,null))['catch'](handleError(_0xd29309,null));};exports[_0x66d2('0x23')]=function(_0x1414e9,_0x2bb41c){return respondWithRpcPromise('VoiceQueuesChannels',_0x1414e9['query'])[_0x66d2('0xa')](respondWithResult(_0x2bb41c,null))['catch'](handleError(_0x2bb41c,null));};exports['voiceQueuesChannel']=function(_0x3ad557,_0x3620fe){return respondWithRpcPromise(_0x66d2('0x24'),_[_0x66d2('0x1b')](_0x3ad557[_0x66d2('0x1e')],_0x3ad557[_0x66d2('0x1c')]))[_0x66d2('0xa')](respondWithResult(_0x3620fe,null))[_0x66d2('0xe')](handleError(_0x3620fe,null));};exports[_0x66d2('0x25')]=function(_0x2c64fe,_0x5c9beb){return respondWithRpcPromise('VoiceQueuesChannelHangup',_[_0x66d2('0x1b')](_0x2c64fe[_0x66d2('0x1e')],_0x2c64fe['params']))[_0x66d2('0xa')](respondWithResult(_0x5c9beb,null))['catch'](handleError(_0x5c9beb,null));};exports['voiceQueuesChannelRedirect']=function(_0x5ea0bd,_0x1368ff){return respondWithRpcPromise(_0x66d2('0x26'),_['merge'](_0x5ea0bd[_0x66d2('0x1e')],_0x5ea0bd[_0x66d2('0x1c')]))['then'](respondWithResult(_0x1368ff,null))[_0x66d2('0xe')](handleError(_0x1368ff,null));};exports[_0x66d2('0x27')]=function(_0x14f4d8,_0x51a3f1){return respondWithRpcPromise(_0x66d2('0x28'),_0x14f4d8[_0x66d2('0x1e')])[_0x66d2('0xa')](respondWithResult(_0x51a3f1,null))['catch'](handleError(_0x51a3f1,null));};exports[_0x66d2('0x29')]=function(_0xb6949b,_0xaddd04){return respondWithRpcPromise('OutboundChannels',_0xb6949b[_0x66d2('0x1e')])[_0x66d2('0xa')](respondWithResult(_0xaddd04,null))[_0x66d2('0xe')](handleError(_0xaddd04,null));};exports[_0x66d2('0x2a')]=function(_0x44af77,_0xeee88c){var _0x100cf8;return respondWithRpcPromise(_0x66d2('0x2b'),_0x44af77[_0x66d2('0x1e')])['then'](function(_0x4dc906){_0x100cf8=_0x4dc906;return respondWithRpcPromise(_0x66d2('0x2b'),_0x44af77[_0x66d2('0x1e')],routingClient);})['then'](function(_0x168dc2){return _[_0x66d2('0x1b')]({},_0x168dc2,_0x100cf8);})[_0x66d2('0xa')](respondWithResult(_0xeee88c,null))[_0x66d2('0xe')](handleError(_0xeee88c,null));};exports['agentCapacity']=function(_0x4d67aa,_0x4f1607){if(_0x4d67aa[_0x66d2('0x2c')]&&_0x4d67aa['body']['interaction']&&_0x4d67aa['user']&&_0x4d67aa['user'][_0x66d2('0x13')]){for(var _0xc1b28f in _0x4d67aa[_0x66d2('0x2c')][_0x66d2('0x2d')]){if(_0x4d67aa[_0x66d2('0x2c')][_0x66d2('0x2d')][_0x66d2('0x2e')](_0xc1b28f)){db[_0x66d2('0x2f')][_0x66d2('0x30')]({'where':{'channel':_0xc1b28f,'membername':_0x4d67aa[_0x66d2('0x31')][_0x66d2('0x13')],'type':_0x66d2('0x32'),'exitAt':null,'uniqueid':_0x4d67aa[_0x66d2('0x2c')][_0x66d2('0x2d')][_0xc1b28f]&&_0x4d67aa[_0x66d2('0x2c')][_0x66d2('0x2d')][_0xc1b28f][_0x66d2('0x33')]?{'$notIn':_0x4d67aa['body'][_0x66d2('0x2d')][_0xc1b28f]}:{'$ne':null}}})['then'](function(_0x54a22d){var _0x5445da=moment()[_0x66d2('0x34')](_0x66d2('0x35'));for(var _0x3456ea=0x0,_0xcff2b0=_0x54a22d[_0x66d2('0x33')];_0x3456ea<_0xcff2b0;_0x3456ea+=0x1){_0x54a22d[_0x3456ea][_0x66d2('0x36')]({'exitAt':_0x5445da});}});for(var _0x5b9da1=0x0;_0x5b9da1<_0x4d67aa[_0x66d2('0x2c')][_0x66d2('0x2d')][_0xc1b28f][_0x66d2('0x33')];_0x5b9da1+=0x1){db[_0x66d2('0x2f')]['findOrCreate']({'where':{'channel':_0xc1b28f,'membername':_0x4d67aa[_0x66d2('0x31')]['name'],'type':'INTERACTION','uniqueid':_0x4d67aa[_0x66d2('0x2c')][_0x66d2('0x2d')][_0xc1b28f][_0x5b9da1],'exitAt':null},'defaults':{'channel':_0xc1b28f,'membername':_0x4d67aa['user'][_0x66d2('0x13')],'interface':_[_0x66d2('0x15')](_0x4d67aa[_0x66d2('0x31')][_0x66d2('0x37')])?util['format'](_0x66d2('0x38'),_0x4d67aa['user'][_0x66d2('0x13')]):_0x4d67aa[_0x66d2('0x31')][_0x66d2('0x37')],'type':_0x66d2('0x32'),'enterAt':moment()['format'](_0x66d2('0x35')),'role':_0x66d2('0x39'),'internal':_0x4d67aa[_0x66d2('0x31')][_0x66d2('0x3a')],'uniqueid':_0x4d67aa['body']['interaction'][_0xc1b28f][_0x5b9da1]}});}}}}return respondWithRpcPromise('AgentCapacity',{'id':_0x4d67aa[_0x66d2('0x1c')]['id'],'capacity':_0x4d67aa[_0x66d2('0x2c')]['capacity']},routingClient)[_0x66d2('0xa')](respondWithResult(_0x4f1607,null))['catch'](handleError(_0x4f1607,null));};exports[_0x66d2('0x3b')]=function(_0x1dbec9,_0x34f508){return respondWithRpcPromise(_0x66d2('0x3c'),_0x1dbec9[_0x66d2('0x1e')])['then'](respondWithResult(_0x34f508,null))['catch'](handleError(_0x34f508,null));};exports['trunks']=function(_0x540ea6,_0x1498ac){return respondWithRpcPromise(_0x66d2('0x3d'),_0x540ea6[_0x66d2('0x1e')])[_0x66d2('0xa')](respondWithResult(_0x1498ac,null))[_0x66d2('0xe')](handleError(_0x1498ac,null));};exports[_0x66d2('0x3e')]=function(_0x1670d9,_0x3475b7){return respondWithRpcPromise(_0x66d2('0x3f'),_0x1670d9['query'])['then'](respondWithResult(_0x3475b7,null))[_0x66d2('0xe')](handleError(_0x3475b7,null));};exports[_0x66d2('0x40')]=function(_0x51b1ad,_0x43b1d0){return respondWithRpcPromise('ChatQueues',_0x51b1ad[_0x66d2('0x1e')],routingClient)[_0x66d2('0xa')](respondWithResult(_0x43b1d0,null))[_0x66d2('0xe')](handleError(_0x43b1d0,null));};exports[_0x66d2('0x41')]=function(_0x21a40f,_0x2be4f3){return respondWithRpcPromise(_0x66d2('0x42'),_0x21a40f['query'],routingClient)['then'](findById(_0x21a40f[_0x66d2('0x1c')]['id']))['then'](respondWithResult(_0x2be4f3,null))[_0x66d2('0xe')](handleError(_0x2be4f3,null));};exports[_0x66d2('0x43')]=function(_0x2175cc,_0x50f8d5){return respondWithRpcPromise('MailQueues',_0x2175cc[_0x66d2('0x1e')],routingClient)[_0x66d2('0xa')](respondWithResult(_0x50f8d5,null))[_0x66d2('0xe')](handleError(_0x50f8d5,null));};exports[_0x66d2('0x44')]=function(_0x4c9b9d,_0x739533){return respondWithRpcPromise(_0x66d2('0x45'),_0x4c9b9d[_0x66d2('0x1e')],routingClient)[_0x66d2('0xa')](findById(_0x4c9b9d[_0x66d2('0x1c')]['id']))[_0x66d2('0xa')](respondWithResult(_0x739533,null))[_0x66d2('0xe')](handleError(_0x739533,null));};exports['mailAccounts']=function(_0x4a3546,_0x47e289){return respondWithRpcPromise('MailAccounts',_0x4a3546['query'],mailClient)[_0x66d2('0xa')](respondWithResult(_0x47e289,null))['catch'](handleError(_0x47e289,null));};exports['openchannelQueues']=function(_0x56d912,_0x876d4a){return respondWithRpcPromise(_0x66d2('0x46'),_0x56d912[_0x66d2('0x1e')],routingClient)['then'](respondWithResult(_0x876d4a,null))[_0x66d2('0xe')](handleError(_0x876d4a,null));};exports[_0x66d2('0x47')]=function(_0x5f1ca5,_0x3f5866){return respondWithRpcPromise(_0x66d2('0x46'),_0x5f1ca5[_0x66d2('0x1e')],routingClient)['then'](findById(_0x5f1ca5[_0x66d2('0x1c')]['id']))['then'](respondWithResult(_0x3f5866,null))['catch'](handleError(_0x3f5866,null));};exports[_0x66d2('0x48')]=function(_0x955842,_0x387c7a){return respondWithRpcPromise(_0x66d2('0x49'),_0x955842['query'],routingClient)[_0x66d2('0xa')](respondWithResult(_0x387c7a,null))[_0x66d2('0xe')](handleError(_0x387c7a,null));};exports[_0x66d2('0x4a')]=function(_0x4622fb,_0x1665c4){return respondWithRpcPromise(_0x66d2('0x49'),_0x4622fb['query'],routingClient)[_0x66d2('0xa')](findById(_0x4622fb[_0x66d2('0x1c')]['id']))[_0x66d2('0xa')](respondWithResult(_0x1665c4,null))[_0x66d2('0xe')](handleError(_0x1665c4,null));};exports[_0x66d2('0x4b')]=function(_0x261fca,_0x150bed){return respondWithRpcPromise(_0x66d2('0x4c'),_0x261fca['query'],routingClient)['then'](respondWithResult(_0x150bed,null))['catch'](handleError(_0x150bed,null));};exports[_0x66d2('0x4d')]=function(_0x220c90,_0x45a6c1){return respondWithRpcPromise(_0x66d2('0x4c'),_0x220c90[_0x66d2('0x1e')],routingClient)[_0x66d2('0xa')](findById(_0x220c90[_0x66d2('0x1c')]['id']))['then'](respondWithResult(_0x45a6c1,null))[_0x66d2('0xe')](handleError(_0x45a6c1,null));};exports[_0x66d2('0x4e')]=function(_0x1d9020,_0x207a0c){return respondWithRpcPromise(_0x66d2('0x4f'),_0x1d9020['query'],routingClient)[_0x66d2('0xa')](respondWithResult(_0x207a0c,null))[_0x66d2('0xe')](handleError(_0x207a0c,null));};exports['showFaxQueues']=function(_0x1e4fc6,_0x46ce2f){return respondWithRpcPromise(_0x66d2('0x4f'),_0x1e4fc6[_0x66d2('0x1e')],routingClient)[_0x66d2('0xa')](findById(_0x1e4fc6[_0x66d2('0x1c')]['id']))[_0x66d2('0xa')](respondWithResult(_0x46ce2f,null))[_0x66d2('0xe')](handleError(_0x46ce2f,null));};exports[_0x66d2('0x50')]=function(_0xc67511,_0x552be9){return respondWithRpcPromise('FaxAccounts',_0xc67511[_0x66d2('0x1e')])[_0x66d2('0xa')](respondWithResult(_0x552be9,null))[_0x66d2('0xe')](handleError(_0x552be9,null));};exports[_0x66d2('0x51')]=function(_0xa67f04,_0x19dfe0){return respondWithRpcPromise(_0x66d2('0x52'),_0xa67f04[_0x66d2('0x1e')],routingClient)[_0x66d2('0xa')](respondWithResult(_0x19dfe0,null))[_0x66d2('0xe')](handleError(_0x19dfe0,null));};exports[_0x66d2('0x53')]=function(_0x4e9bdf,_0x844e8){return respondWithRpcPromise('MailQueuesWaitingInteractions',_0x4e9bdf[_0x66d2('0x1e')],routingClient)[_0x66d2('0xa')](respondWithResult(_0x844e8,null))[_0x66d2('0xe')](handleError(_0x844e8,null));};exports[_0x66d2('0x54')]=function(_0x445bd3,_0x53d1b6){return respondWithRpcPromise(_0x66d2('0x55'),_0x445bd3[_0x66d2('0x1e')],routingClient)[_0x66d2('0xa')](respondWithResult(_0x53d1b6,null))['catch'](handleError(_0x53d1b6,null));};exports[_0x66d2('0x56')]=function(_0x1e296a,_0x397679){return respondWithRpcPromise(_0x66d2('0x57'),_0x1e296a[_0x66d2('0x1e')],routingClient)[_0x66d2('0xa')](respondWithResult(_0x397679,null))[_0x66d2('0xe')](handleError(_0x397679,null));};exports[_0x66d2('0x58')]=function(_0x1ef044,_0x349842){return respondWithRpcPromise('WhatsappQueuesWaitingInteractions',_0x1ef044['query'],routingClient)[_0x66d2('0xa')](respondWithResult(_0x349842,null))['catch'](handleError(_0x349842,null));};exports[_0x66d2('0x59')]=function(_0x5e6bf2,_0x3ecdc1){return respondWithRpcPromise(_0x66d2('0x5a'),_0x5e6bf2[_0x66d2('0x1e')],routingClient)[_0x66d2('0xa')](respondWithResult(_0x3ecdc1,null))[_0x66d2('0xe')](handleError(_0x3ecdc1,null));};exports[_0x66d2('0x5b')]=function(_0x522e1e){return function(_0x2876d2,_0xb2e752){var _0x111911,_0x399775;var _0x1312fc=_[_0x66d2('0x5c')](_0x522e1e);var _0x5bbc11=_0x522e1e===_0x66d2('0x5d')?'Website':_0x66d2('0x5e');return db[_0x1312fc+_0x66d2('0x5f')][_0x66d2('0x60')]({'raw':!![],'where':{'id':_0x2876d2['params']['id']}})[_0x66d2('0xa')](function(_0x105bd9){if(_['isNil'](_0x105bd9)){throw new Error(_0x1312fc+_0x66d2('0x61'));}_0x111911=_0x105bd9;return db[_0x1312fc+_0x66d2('0x62')][_0x66d2('0x60')]({'where':{'id':_0x2876d2['body'][_0x66d2('0x63')]},'include':[{'model':db[_0x1312fc+_0x66d2('0x64')],'as':_0x66d2('0x64')},{'model':db[_0x1312fc+_0x5bbc11],'as':_0x66d2('0x5e')}]});})[_0x66d2('0xa')](function(_0xee6060){if(_[_0x66d2('0x15')](_0xee6060)){throw new Error(_0x1312fc+_0x66d2('0x65'));}_0x399775=_0xee6060;return _0xee6060['update']({'read':0x0,'readAt':null,'UserId':null});})[_0x66d2('0xa')](function(){var _0xbfeb06={'uniqueid':_0x522e1e+'.'+_0x399775['id']+'.'+_0x399775[_0x66d2('0x64')]['id'],'FromUserId':_0x2876d2[_0x66d2('0x31')]['id'],'type':_0x66d2('0x66')};_0xbfeb06[_0x1312fc+_0x66d2('0x67')]=_0x399775['id'];_0xbfeb06[_0x1312fc+_0x66d2('0x68')]=_0x399775[_0x66d2('0x64')]['id'];_0xbfeb06['From'+_0x1312fc+_0x5bbc11+'Id']=_0x399775[_0x66d2('0x5e')]['id'];_0xbfeb06['To'+_0x1312fc+'QueueId']=_0x111911['id'];return db[_0x1312fc+_0x66d2('0x69')]['create'](_0xbfeb06);})[_0x66d2('0xa')](function(){return respondWithRpcPromise(_0x66d2('0x6a'),{'channel':_0x522e1e,'interaction':_0x399775[_0x66d2('0x64')],'message':_0x399775,'account':_0x399775[_0x66d2('0x5e')],'applications':[{'id':0x0,'priority':0x1,'app':_0x66d2('0x66'),'appdata':_0x111911['name']+','+(_0x399775[_0x66d2('0x5e')]['queueTransferTimeout']||0x12c),'interval':_0x66d2('0x6b')}]},routingClient);})[_0x66d2('0xa')](respondWithResult(_0xb2e752,null))['catch'](handleError(_0xb2e752,null));};};exports[_0x66d2('0x6c')]=function(_0x3806e2,_0x119d35){var _0x20462c,_0x165344;if(_[_0x66d2('0x15')](_0x3806e2['body'][_0x66d2('0x6d')])){throw new Error('Channel\x20field\x20is\x20mandatory');}var _0xeb86fa=_0x3806e2[_0x66d2('0x2c')][_0x66d2('0x6d')];var _0x1552fa=_[_0x66d2('0x5c')](_0xeb86fa);var _0x3d839e=_0xeb86fa==='chat'?_0x66d2('0x6e'):_0x66d2('0x5e');return db[_0x66d2('0x6f')]['findOne']({'raw':!![],'where':{'id':_0x3806e2['params']['id'],'role':_0x66d2('0x39')}})['then'](function(_0x12d86d){if(_['isNil'](_0x12d86d)){throw new Error(_0x66d2('0x70'));}_0x20462c=_0x12d86d;return db[_0x1552fa+_0x66d2('0x62')][_0x66d2('0x60')]({'where':{'id':_0x3806e2[_0x66d2('0x2c')][_0x66d2('0x63')]},'include':[{'model':db[_0x1552fa+'Interaction'],'as':_0x66d2('0x64')},{'model':db[_0x1552fa+_0x3d839e],'as':_0x66d2('0x5e')}]});})[_0x66d2('0xa')](function(_0x5ab96b){if(_['isNil'](_0x5ab96b)){throw new Error(_0x1552fa+'\x20Message\x20not\x20found');}_0x165344=_0x5ab96b;return _0x5ab96b[_0x66d2('0x71')]({'read':0x0,'readAt':null,'UserId':null});})[_0x66d2('0xa')](function(){var _0x207941={'uniqueid':_0xeb86fa+'.'+_0x165344['id']+'.'+_0x165344['Interaction']['id'],'FromUserId':_0x3806e2[_0x66d2('0x31')]['id'],'type':_0x66d2('0x66'),'ToUserId':_0x20462c['id']};_0x207941[_0x1552fa+_0x66d2('0x67')]=_0x165344['id'];_0x207941[_0x1552fa+_0x66d2('0x68')]=_0x165344[_0x66d2('0x64')]['id'];_0x207941[_0x66d2('0x72')+_0x1552fa+_0x3d839e+'Id']=_0x165344[_0x66d2('0x5e')]['id'];return db[_0x1552fa+_0x66d2('0x69')][_0x66d2('0x73')](_0x207941);})[_0x66d2('0xa')](function(){return respondWithRpcPromise('Start',{'channel':_0xeb86fa,'interaction':_0x165344[_0x66d2('0x64')],'message':_0x165344,'account':_0x165344['Account'],'applications':[{'id':0x0,'priority':0x1,'app':_0x66d2('0x39'),'appdata':_0x20462c[_0x66d2('0x13')]+','+(_0x165344[_0x66d2('0x5e')][_0x66d2('0x74')]||0x12c),'interval':'*,*,*,*'}]},routingClient);})[_0x66d2('0xa')](respondWithResult(_0x119d35,null))['catch'](handleError(_0x119d35,null));};