Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / whatsappMessage / whatsappMessage.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 _0x790f=['User','fullname','internal','interface','SIP/%s','channel','motionChannel','event','WhatsappInteraction','RejectMessage','rejectMessage','format','EventManager','rejectmessage','WhatsappAccount','WhatsappAccountId','WhatsppMessage,\x20%s,\x20%s,\x20%s','received\x20delivery\x20report\x20from','inspect','twilio','MessageSid','MessageStatus','read','WhatsappAccount,\x20%s,\x20%s,\x20%s','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','localhost','./whatsappMessage.socket','register','jayson/promise','client','http','request','then','info','request\x20sent','debug','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','WhatsappMessage,\x20%s,\x20%s','message','result','catch','sendStatus','status','json','offset','undefined','count','Content-Range','apply','reject','save','update','destroy','end','stack','name','send','index','map','WhatsappMessage','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','show','params','rawAttributes','options','find','create','body','describe','whatsapp-interactions','whatsapp','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','WhatsappInteractionId','isNil','interaction','get','role','null','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','Sequelize','SELECT','contact'];(function(_0x32f05c,_0x273aef){var _0x4307ed=function(_0x1be4da){while(--_0x1be4da){_0x32f05c['push'](_0x32f05c['shift']());}};_0x4307ed(++_0x273aef);}(_0x790f,0x1bf));var _0xf790=function(_0x48c615,_0x4cc757){_0x48c615=_0x48c615-0x0;var _0x3d9e22=_0x790f[_0x48c615];return _0x3d9e22;};'use strict';var emlformat=require(_0xf790('0x0'));var rimraf=require(_0xf790('0x1'));var zipdir=require(_0xf790('0x2'));var jsonpatch=require(_0xf790('0x3'));var rp=require(_0xf790('0x4'));var moment=require(_0xf790('0x5'));var BPromise=require(_0xf790('0x6'));var Mustache=require(_0xf790('0x7'));var util=require(_0xf790('0x8'));var path=require('path');var sox=require('sox');var csv=require(_0xf790('0x9'));var ejs=require(_0xf790('0xa'));var fs=require('fs');var fs_extra=require(_0xf790('0xb'));var _=require(_0xf790('0xc'));var squel=require(_0xf790('0xd'));var crypto=require(_0xf790('0xe'));var jsforce=require(_0xf790('0xf'));var deskjs=require(_0xf790('0x10'));var toCsv=require(_0xf790('0x9'));var querystring=require(_0xf790('0x11'));var Papa=require(_0xf790('0x12'));var Redis=require(_0xf790('0x13'));var authService=require(_0xf790('0x14'));var qs=require('../../components/parsers/qs');var as=require(_0xf790('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf790('0x16'))(_0xf790('0x17'));var utils=require(_0xf790('0x18'));var config=require(_0xf790('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0xf790('0x1a'))['db'];config[_0xf790('0x1b')]=_['defaults'](config[_0xf790('0x1b')],{'host':_0xf790('0x1c'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf790('0x1b')]));require(_0xf790('0x1d'))[_0xf790('0x1e')](socket);var jayson=require(_0xf790('0x1f'));var client=jayson[_0xf790('0x20')]['http']({'port':0x232c});var client9002=jayson[_0xf790('0x20')][_0xf790('0x21')]({'port':0x232a});function respondWithRpcPromise(_0x47ead1,_0x2a8719,_0x49ed6a,_0x247ef8){return new BPromise(function(_0x59b38a,_0x5d8686){var _0x3c4b14=_0x247ef8||client;return _0x3c4b14[_0xf790('0x22')](_0x47ead1,_0x49ed6a)[_0xf790('0x23')](function(_0x397994){logger[_0xf790('0x24')]('WhatsappMessage,\x20%s,\x20%s',_0x2a8719,_0xf790('0x25'));logger[_0xf790('0x26')](_0xf790('0x27'),_0x2a8719,_0xf790('0x25'),JSON[_0xf790('0x28')](_0x397994));if(_0x397994[_0xf790('0x29')]){if(_0x397994[_0xf790('0x29')][_0xf790('0x2a')]===0x1f4){logger['error'](_0xf790('0x2b'),_0x2a8719,_0x397994[_0xf790('0x29')][_0xf790('0x2c')]);return _0x5d8686(_0x397994[_0xf790('0x29')][_0xf790('0x2c')]);}logger['error'](_0xf790('0x2b'),_0x2a8719,_0x397994[_0xf790('0x29')]['message']);return _0x59b38a(_0x397994[_0xf790('0x29')][_0xf790('0x2c')]);}else{logger[_0xf790('0x24')](_0xf790('0x2b'),_0x2a8719,_0xf790('0x25'));_0x59b38a(_0x397994[_0xf790('0x2d')][_0xf790('0x2c')]);}})[_0xf790('0x2e')](function(_0x156c3b){logger['error'](_0xf790('0x2b'),_0x2a8719,_0x156c3b);_0x5d8686(_0x156c3b);});});}function respondWithStatusCode(_0x212298,_0x40edf2){_0x40edf2=_0x40edf2||0xcc;return function(_0x2a1983){if(_0x2a1983){return _0x212298[_0xf790('0x2f')](_0x40edf2);}return _0x212298[_0xf790('0x30')](_0x40edf2)['end']();};}function respondWithResult(_0x21d530,_0x35f2cb){_0x35f2cb=_0x35f2cb||0xc8;return function(_0x142f0c){if(_0x142f0c){return _0x21d530[_0xf790('0x30')](_0x35f2cb)[_0xf790('0x31')](_0x142f0c);}};}function respondWithFilteredResult(_0x3f825d,_0x5e989c){return function(_0x22b6f8){if(_0x22b6f8){var _0x1194c9=typeof _0x5e989c[_0xf790('0x32')]===_0xf790('0x33')&&typeof _0x5e989c['limit']===_0xf790('0x33');var _0x58ec32=_0x22b6f8['count'];var _0x46a914=_0x1194c9?0x0:_0x5e989c['offset'];var _0xcb1ff9=_0x1194c9?_0x22b6f8[_0xf790('0x34')]:_0x5e989c[_0xf790('0x32')]+_0x5e989c['limit'];var _0x55826b;if(_0xcb1ff9>=_0x58ec32){_0xcb1ff9=_0x58ec32;_0x55826b=0xc8;}else{_0x55826b=0xce;}_0x3f825d[_0xf790('0x30')](_0x55826b);return _0x3f825d['set'](_0xf790('0x35'),_0x46a914+'-'+_0xcb1ff9+'/'+_0x58ec32)[_0xf790('0x31')](_0x22b6f8);}return null;};}function patchUpdates(_0x24e1ad){return function(_0x53cd81){try{jsonpatch[_0xf790('0x36')](_0x53cd81,_0x24e1ad,!![]);}catch(_0x2aee3f){return BPromise[_0xf790('0x37')](_0x2aee3f);}return _0x53cd81[_0xf790('0x38')]();};}function saveUpdates(_0x64ce2c,_0x43f37c){return function(_0x3b3bee){if(_0x3b3bee){return _0x3b3bee[_0xf790('0x39')](_0x64ce2c)[_0xf790('0x23')](function(_0x1a9394){return _0x1a9394;});}return null;};}function removeEntity(_0x40074b,_0x3d4374){return function(_0x4d450c){if(_0x4d450c){return _0x4d450c[_0xf790('0x3a')]()['then'](function(){_0x40074b[_0xf790('0x30')](0xcc)[_0xf790('0x3b')]();});}};}function handleEntityNotFound(_0x1b74be,_0x5519ae){return function(_0x4e82a7){if(!_0x4e82a7){_0x1b74be[_0xf790('0x2f')](0x194);}return _0x4e82a7;};}function handleError(_0x3fe50c,_0x419e23){_0x419e23=_0x419e23||0x1f4;return function(_0x542cbc){logger[_0xf790('0x29')](_0x542cbc[_0xf790('0x3c')]);if(_0x542cbc[_0xf790('0x3d')]){delete _0x542cbc[_0xf790('0x3d')];}_0x3fe50c['status'](_0x419e23)[_0xf790('0x3e')](_0x542cbc);};}exports[_0xf790('0x3f')]=function(_0x14588e,_0x44cdf0){var _0x56e7d5={},_0x3e602d={},_0x50a1d1={'count':0x0,'rows':[]};var _0x193469=_[_0xf790('0x40')](db[_0xf790('0x41')]['rawAttributes'],function(_0x441369){return{'name':_0x441369[_0xf790('0x42')],'type':_0x441369[_0xf790('0x43')][_0xf790('0x44')]};});_0x3e602d[_0xf790('0x45')]=_[_0xf790('0x40')](_0x193469,_0xf790('0x3d'));_0x3e602d[_0xf790('0x46')]=_[_0xf790('0x47')](_0x14588e[_0xf790('0x46')]);_0x3e602d[_0xf790('0x48')]=_[_0xf790('0x49')](_0x3e602d['model'],_0x3e602d[_0xf790('0x46')]);_0x56e7d5[_0xf790('0x4a')]=_[_0xf790('0x49')](_0x3e602d[_0xf790('0x45')],qs['fields'](_0x14588e[_0xf790('0x46')][_0xf790('0x4b')]));_0x56e7d5[_0xf790('0x4a')]=_0x56e7d5[_0xf790('0x4a')][_0xf790('0x4c')]?_0x56e7d5['attributes']:_0x3e602d[_0xf790('0x45')];if(!_0x14588e[_0xf790('0x46')]['hasOwnProperty'](_0xf790('0x4d'))){_0x56e7d5[_0xf790('0x4e')]=qs['limit'](_0x14588e['query'][_0xf790('0x4e')]);_0x56e7d5[_0xf790('0x32')]=qs[_0xf790('0x32')](_0x14588e['query'][_0xf790('0x32')]);}_0x56e7d5[_0xf790('0x4f')]=qs['sort'](_0x14588e[_0xf790('0x46')][_0xf790('0x50')]);_0x56e7d5[_0xf790('0x51')]=qs[_0xf790('0x48')](_[_0xf790('0x52')](_0x14588e[_0xf790('0x46')],_0x3e602d[_0xf790('0x48')]),_0x193469);if(_0x14588e[_0xf790('0x46')][_0xf790('0x53')]){_0x56e7d5[_0xf790('0x51')]=_[_0xf790('0x54')](_0x56e7d5[_0xf790('0x51')],{'$or':_[_0xf790('0x40')](_0x193469,function(_0x11d341){if(_0x11d341[_0xf790('0x43')]!==_0xf790('0x55')){var _0x2618f4={};_0x2618f4[_0x11d341[_0xf790('0x3d')]]={'$like':'%'+_0x14588e['query'][_0xf790('0x53')]+'%'};return _0x2618f4;}})});}_0x56e7d5=_[_0xf790('0x54')]({},_0x56e7d5,_0x14588e['options']);var _0x569fde={'where':_0x56e7d5['where']};return db[_0xf790('0x41')][_0xf790('0x34')](_0x569fde)[_0xf790('0x23')](function(_0x38cdc2){_0x50a1d1[_0xf790('0x34')]=_0x38cdc2;if(_0x14588e[_0xf790('0x46')][_0xf790('0x56')]){_0x56e7d5[_0xf790('0x57')]=[{'all':!![]}];}return db[_0xf790('0x41')][_0xf790('0x58')](_0x56e7d5);})[_0xf790('0x23')](function(_0x2bb6a1){_0x50a1d1[_0xf790('0x59')]=_0x2bb6a1;return _0x50a1d1;})[_0xf790('0x23')](respondWithFilteredResult(_0x44cdf0,_0x56e7d5))['catch'](handleError(_0x44cdf0,null));};exports[_0xf790('0x5a')]=function(_0x13a1d4,_0x4ae3b2){var _0x54fa2b={'raw':!![],'where':{'id':_0x13a1d4[_0xf790('0x5b')]['id']}},_0x5823ae={};_0x5823ae[_0xf790('0x45')]=_['keys'](db[_0xf790('0x41')][_0xf790('0x5c')]);_0x5823ae[_0xf790('0x46')]=_[_0xf790('0x47')](_0x13a1d4[_0xf790('0x46')]);_0x5823ae[_0xf790('0x48')]=_[_0xf790('0x49')](_0x5823ae['model'],_0x5823ae['query']);_0x54fa2b[_0xf790('0x4a')]=_[_0xf790('0x49')](_0x5823ae['model'],qs[_0xf790('0x4b')](_0x13a1d4[_0xf790('0x46')][_0xf790('0x4b')]));_0x54fa2b[_0xf790('0x4a')]=_0x54fa2b[_0xf790('0x4a')][_0xf790('0x4c')]?_0x54fa2b[_0xf790('0x4a')]:_0x5823ae[_0xf790('0x45')];if(_0x13a1d4[_0xf790('0x46')][_0xf790('0x56')]){_0x54fa2b[_0xf790('0x57')]=[{'all':!![]}];}_0x54fa2b=_['merge']({},_0x54fa2b,_0x13a1d4[_0xf790('0x5d')]);return db[_0xf790('0x41')][_0xf790('0x5e')](_0x54fa2b)[_0xf790('0x23')](handleEntityNotFound(_0x4ae3b2,null))[_0xf790('0x23')](respondWithResult(_0x4ae3b2,null))[_0xf790('0x2e')](handleError(_0x4ae3b2,null));};exports['create']=function(_0x22b6b6,_0x282313){return db[_0xf790('0x41')][_0xf790('0x5f')](_0x22b6b6['body'],{})['then'](respondWithResult(_0x282313,0xc9))[_0xf790('0x2e')](handleError(_0x282313,null));};exports[_0xf790('0x39')]=function(_0x29c40c,_0x33cf1c){if(_0x29c40c[_0xf790('0x60')]['id']){delete _0x29c40c[_0xf790('0x60')]['id'];}return db[_0xf790('0x41')]['find']({'where':{'id':_0x29c40c[_0xf790('0x5b')]['id']}})[_0xf790('0x23')](handleEntityNotFound(_0x33cf1c,null))[_0xf790('0x23')](saveUpdates(_0x29c40c[_0xf790('0x60')],null))['then'](respondWithResult(_0x33cf1c,null))[_0xf790('0x2e')](handleError(_0x33cf1c,null));};exports[_0xf790('0x3a')]=function(_0xc07a26,_0x3ac93f){return db['WhatsappMessage']['find']({'where':{'id':_0xc07a26[_0xf790('0x5b')]['id']}})[_0xf790('0x23')](handleEntityNotFound(_0x3ac93f,null))[_0xf790('0x23')](removeEntity(_0x3ac93f,null))[_0xf790('0x2e')](handleError(_0x3ac93f,null));};exports[_0xf790('0x61')]=function(_0x375fd6,_0x10eb51){return db[_0xf790('0x41')][_0xf790('0x61')]()[_0xf790('0x23')](respondWithResult(_0x10eb51,null))[_0xf790('0x2e')](handleError(_0x10eb51,null));};var interaction_log=require(_0xf790('0x16'))(_0xf790('0x62'));exports['accept']=function(_0x5e1f9c,_0x24d0cc,_0x45c156){var _0x36b7b4={'agent':{},'channel':_0xf790('0x63')};if(_0x5e1f9c[_0xf790('0x60')]['id']){delete _0x5e1f9c[_0xf790('0x60')]['id'];}_0x5e1f9c['body']['read']=!![];_0x5e1f9c[_0xf790('0x60')][_0xf790('0x64')]=moment()['format'](_0xf790('0x65'));_0x5e1f9c['body'][_0xf790('0x66')]=_0x5e1f9c['body']['UserId']||_0x5e1f9c[_0xf790('0x67')]['id'];_0x36b7b4[_0xf790('0x68')]['id']=_0x5e1f9c[_0xf790('0x60')][_0xf790('0x66')];return db[_0xf790('0x41')][_0xf790('0x5e')]({'where':{'id':_0x5e1f9c[_0xf790('0x5b')]['id'],'UserId':null}})[_0xf790('0x23')](handleEntityNotFound(_0x24d0cc,null))[_0xf790('0x23')](saveUpdates(_0x5e1f9c[_0xf790('0x60')],null))[_0xf790('0x23')](function(_0xe3c26e){if(_0xe3c26e){_0x36b7b4[_0xf790('0x2c')]=_0xe3c26e['get']({'plain':!![]});return db['WhatsappInteraction'][_0xf790('0x5e')]({'where':{'id':_0xe3c26e[_0xf790('0x69')]}});}return null;})[_0xf790('0x23')](handleEntityNotFound(_0x24d0cc,null))[_0xf790('0x23')](function(_0x352388){if(_0x352388){return _0x352388['update']({'UserId':_0x5e1f9c[_0xf790('0x60')][_0xf790('0x66')],'read1stAt':_[_0xf790('0x6a')](_0x352388['read1stAt'])?moment()['format'](_0xf790('0x65')):undefined});}return null;})[_0xf790('0x23')](function(_0x3d3258){if(_0x3d3258){_0x36b7b4[_0xf790('0x6b')]=_0x3d3258[_0xf790('0x6c')]({'plain':!![]});interaction_log[_0xf790('0x24')]('[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x5e1f9c[_0xf790('0x67')]['id'],_0x5e1f9c[_0xf790('0x67')]['name'],_0x5e1f9c[_0xf790('0x67')][_0xf790('0x6d')],_0x36b7b4[_0xf790('0x6b')]['id'],_0x5e1f9c[_0xf790('0x60')]?JSON[_0xf790('0x28')](_0x5e1f9c['body']):_0xf790('0x6e'));return respondWithRpcPromise('AcceptMessage',_0xf790('0x6f'),_0x36b7b4);}return null;})[_0xf790('0x23')](function(_0x1678aa){var _0x3f1bc7=_0xf790('0x70')+_0x1678aa[_0xf790('0x2c')][_0xf790('0x71')];return db['sequelize']['query'](_0x3f1bc7,{'type':db[_0xf790('0x72')]['QueryTypes'][_0xf790('0x73')],'raw':!![]})['then'](function(_0x1ed9b2){return _0x1ed9b2;});})[_0xf790('0x23')](function(_0x2d14f6){if(_0x2d14f6){_0x36b7b4[_0xf790('0x2c')][_0xf790('0x74')]=_0x2d14f6[0x0];if(!_0x5e1f9c['body'][_0xf790('0x66')])return;return db[_0xf790('0x75')][_0xf790('0x5e')]({'where':{'id':_0x5e1f9c['body'][_0xf790('0x66')],'role':_0xf790('0x68')},'attributes':['id',_0xf790('0x3d'),_0xf790('0x76'),'email',_0xf790('0x77')],'raw':!![]});}return null;})['then'](function(_0x114058){if(!_0x114058)return null;_0x36b7b4[_0xf790('0x2c')]['agent']=_0x114058;return _0x36b7b4;})[_0xf790('0x23')](function(_0x3aad50){if(_0x3aad50){if(_0x5e1f9c['body']['manual']){_0x36b7b4[_0xf790('0x2c')][_0xf790('0x78')]=util['format'](_0xf790('0x79'),_0x5e1f9c['user'][_0xf790('0x3d')]);_0x36b7b4[_0xf790('0x2c')]['channel']=_0x36b7b4[_0xf790('0x7a')];_0x36b7b4[_0xf790('0x2c')][_0xf790('0x7b')]=_0x36b7b4['channel'];_0x36b7b4[_0xf790('0x2c')][_0xf790('0x7c')]='accept';return respondWithRpcPromise('EventManager','EventManager',{'event':'acceptmessage','message':_0x36b7b4[_0xf790('0x2c')]},client9002)[_0xf790('0x23')](function(){return _0x36b7b4;});}return _0x36b7b4;}return null;})[_0xf790('0x23')](respondWithResult(_0x24d0cc,null))[_0xf790('0x2e')](handleError(_0x24d0cc,null));};var interaction_log=require(_0xf790('0x16'))(_0xf790('0x62'));exports[_0xf790('0x37')]=function(_0x2aad10,_0x2f6975,_0xfcf7ab){var _0x851daa={'agent':{},'channel':_0xf790('0x63')};if(_0x2aad10['body']['id']){delete _0x2aad10['body']['id'];}_0x2aad10['body'][_0xf790('0x66')]=_0x2aad10[_0xf790('0x60')]['UserId']||_0x2aad10[_0xf790('0x67')]['id'];_0x851daa[_0xf790('0x68')]['id']=_0x2aad10[_0xf790('0x60')]['UserId'];return db['WhatsappMessage'][_0xf790('0x5e')]({'where':{'id':_0x2aad10['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x2f6975,null))[_0xf790('0x23')](function(_0x59f7b5){if(_0x59f7b5){_0x851daa['message']=_0x59f7b5[_0xf790('0x6c')]({'plain':!![]});return db[_0xf790('0x7d')][_0xf790('0x5e')]({'where':{'id':_0x59f7b5['WhatsappInteractionId']}});}return null;})[_0xf790('0x23')](handleEntityNotFound(_0x2f6975,null))['then'](function(_0x21588b){if(_0x21588b){_0x851daa['interaction']=_0x21588b['get']({'plain':!![]});interaction_log[_0xf790('0x24')]('[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x2aad10['user']['id'],_0x2aad10[_0xf790('0x67')][_0xf790('0x3d')],_0x2aad10[_0xf790('0x67')][_0xf790('0x6d')],_0x851daa['interaction']['id'],_0x2aad10[_0xf790('0x60')]?JSON[_0xf790('0x28')](_0x2aad10[_0xf790('0x60')]):_0xf790('0x6e'));return respondWithRpcPromise(_0xf790('0x7e'),_0xf790('0x7f'),_0x851daa);}return null;})[_0xf790('0x23')](function(_0x3000b4){var _0x4118bf=_0xf790('0x70')+_0x3000b4[_0xf790('0x2c')][_0xf790('0x71')];return db['sequelize'][_0xf790('0x46')](_0x4118bf,{'type':db['Sequelize']['QueryTypes'][_0xf790('0x73')],'raw':!![]})[_0xf790('0x23')](function(_0x5071fe){return _0x5071fe;});})[_0xf790('0x23')](function(_0x2f2ef2){if(_0x2f2ef2){_0x851daa['message']['contact']=_0x2f2ef2[0x0];if(!_0x2aad10[_0xf790('0x60')][_0xf790('0x66')])return;return db['User']['find']({'where':{'id':_0x2aad10[_0xf790('0x60')][_0xf790('0x66')],'role':_0xf790('0x68')},'attributes':['id','name',_0xf790('0x76'),'email',_0xf790('0x77')],'raw':!![]});}return null;})[_0xf790('0x23')](function(_0x34d77a){if(!_0x34d77a)return null;_0x851daa[_0xf790('0x2c')][_0xf790('0x68')]=_0x34d77a;return _0x851daa;})[_0xf790('0x23')](function(_0xadff39){if(_0xadff39){_0xadff39[_0xf790('0x2c')][_0xf790('0x78')]=util[_0xf790('0x80')](_0xf790('0x79'),_0x2aad10[_0xf790('0x67')]['name']);_0xadff39[_0xf790('0x2c')][_0xf790('0x7a')]=_0x851daa[_0xf790('0x7a')];_0xadff39[_0xf790('0x2c')][_0xf790('0x7b')]=_0x851daa[_0xf790('0x7a')];_0xadff39['message']['event']=_0xf790('0x37');respondWithRpcPromise(_0xf790('0x81'),_0xf790('0x81'),{'event':_0xf790('0x82'),'message':_0xadff39[_0xf790('0x2c')]},client9002);return _0x851daa;}return null;})[_0xf790('0x23')](respondWithResult(_0x2f6975,null))[_0xf790('0x2e')](handleError(_0x2f6975,null));};exports[_0xf790('0x30')]=function(_0x12ca47,_0x1be934,_0x11c11e){if(_0x12ca47[_0xf790('0x60')]['id']){delete _0x12ca47['body']['id'];}var _0x5e06af;return db[_0xf790('0x41')][_0xf790('0x5e')]({'where':{'id':_0x12ca47[_0xf790('0x5b')]['id']}})['then'](handleEntityNotFound(_0x1be934,null))[_0xf790('0x23')](function(_0x5dcdb9){if(_0x5dcdb9){_0x5e06af=_0x5dcdb9;return db[_0xf790('0x83')]['find']({'where':{'id':_0x5dcdb9[_0xf790('0x84')]}});}})[_0xf790('0x23')](handleEntityNotFound(_0x1be934,null))['then'](function(_0x253600){if(_0x253600){logger[_0xf790('0x26')](_0xf790('0x85'),'status',_0xf790('0x86'),_0x253600[_0xf790('0x43')],util[_0xf790('0x87')](_0x12ca47['body'],{'showHidden':![],'depth':null}));switch(_0x253600[_0xf790('0x43')]){case _0xf790('0x88'):if(_0x12ca47[_0xf790('0x60')][_0xf790('0x89')]&&_0x12ca47[_0xf790('0x60')][_0xf790('0x89')]===_0x5e06af['messageId']&&_0x12ca47['body']['MessageStatus']&&_0x12ca47[_0xf790('0x60')][_0xf790('0x8a')]===_0xf790('0x8b')){return _0x5e06af[_0xf790('0x39')]({'read':!![]});}else{logger['error'](_0xf790('0x8c'),'status',_0xf790('0x88'),util['inspect'](_0x12ca47[_0xf790('0x60')],{'showHidden':![],'depth':null}));}break;}return _0x5e06af;}})[_0xf790('0x23')](respondWithResult(_0x1be934,null))[_0xf790('0x2e')](handleError(_0x1be934,null));};