e59e9b6678d4fe4d250966bd2c095b89ee5d3698
[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 _0xc58b=['merge','filter','options','includeAll','findAll','rows','show','params','rawAttributes','include','create','body','update','find','describe','../../config/logger','whatsapp-interactions','accept','whatsapp','read','readAt','format','UserId','user','get','WhatsappInteraction','WhatsappInteractionId','isNil','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','acceptMessage','ContactId','QueryTypes','SELECT','contact','User','agent','fullname','email','manual','interface','SIP/%s','channel','motionChannel','event','EventManager','RejectMessage','rejectMessage','sequelize','internal','rejectmessage','WhatsappAccount','WhatsappAccountId','WhatsppMessage,\x20%s,\x20%s,\x20%s','twilio','MessageSid','MessageStatus','WhatsappAccount,\x20%s,\x20%s,\x20%s','inspect','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./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','end','json','offset','undefined','limit','count','apply','reject','save','destroy','name','send','index','map','WhatsappMessage','fieldName','type','key','model','keys','query','intersection','attributes','fields','hasOwnProperty','order','sort','filters','pick','where'];(function(_0x2da357,_0x1f9b2f){var _0x138fdd=function(_0xe3077d){while(--_0xe3077d){_0x2da357['push'](_0x2da357['shift']());}};_0x138fdd(++_0x1f9b2f);}(_0xc58b,0x1e9));var _0xbc58=function(_0x2edbad,_0x33e25b){_0x2edbad=_0x2edbad-0x0;var _0x149cd5=_0xc58b[_0x2edbad];return _0x149cd5;};'use strict';var emlformat=require(_0xbc58('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xbc58('0x1'));var jsonpatch=require(_0xbc58('0x2'));var rp=require(_0xbc58('0x3'));var moment=require(_0xbc58('0x4'));var BPromise=require(_0xbc58('0x5'));var Mustache=require(_0xbc58('0x6'));var util=require(_0xbc58('0x7'));var path=require(_0xbc58('0x8'));var sox=require(_0xbc58('0x9'));var csv=require(_0xbc58('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xbc58('0xb'));var squel=require(_0xbc58('0xc'));var crypto=require(_0xbc58('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xbc58('0xe'));var toCsv=require('to-csv');var querystring=require(_0xbc58('0xf'));var Papa=require(_0xbc58('0x10'));var Redis=require(_0xbc58('0x11'));var authService=require(_0xbc58('0x12'));var qs=require(_0xbc58('0x13'));var as=require(_0xbc58('0x14'));var hardwareService=require(_0xbc58('0x15'));var logger=require('../../config/logger')(_0xbc58('0x16'));var utils=require('../../config/utils');var config=require(_0xbc58('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xbc58('0x18'))['db'];config[_0xbc58('0x19')]=_[_0xbc58('0x1a')](config[_0xbc58('0x19')],{'host':_0xbc58('0x1b'),'port':0x18eb});var socket=require(_0xbc58('0x1c'))(new Redis(config[_0xbc58('0x19')]));require(_0xbc58('0x1d'))[_0xbc58('0x1e')](socket);var jayson=require(_0xbc58('0x1f'));var client=jayson[_0xbc58('0x20')][_0xbc58('0x21')]({'port':0x232c});var client9002=jayson[_0xbc58('0x20')]['http']({'port':0x232a});function respondWithRpcPromise(_0xd021f8,_0x5f498b,_0x153a0e,_0x44c0ee){return new BPromise(function(_0x225aa6,_0x6ed86e){var _0x44551b=_0x44c0ee||client;return _0x44551b[_0xbc58('0x22')](_0xd021f8,_0x153a0e)[_0xbc58('0x23')](function(_0x324e8a){logger[_0xbc58('0x24')]('WhatsappMessage,\x20%s,\x20%s',_0x5f498b,_0xbc58('0x25'));logger[_0xbc58('0x26')](_0xbc58('0x27'),_0x5f498b,'request\x20sent',JSON[_0xbc58('0x28')](_0x324e8a));if(_0x324e8a[_0xbc58('0x29')]){if(_0x324e8a['error'][_0xbc58('0x2a')]===0x1f4){logger['error'](_0xbc58('0x2b'),_0x5f498b,_0x324e8a[_0xbc58('0x29')][_0xbc58('0x2c')]);return _0x6ed86e(_0x324e8a[_0xbc58('0x29')][_0xbc58('0x2c')]);}logger[_0xbc58('0x29')](_0xbc58('0x2b'),_0x5f498b,_0x324e8a[_0xbc58('0x29')][_0xbc58('0x2c')]);return _0x225aa6(_0x324e8a['error']['message']);}else{logger[_0xbc58('0x24')](_0xbc58('0x2b'),_0x5f498b,_0xbc58('0x25'));_0x225aa6(_0x324e8a[_0xbc58('0x2d')][_0xbc58('0x2c')]);}})[_0xbc58('0x2e')](function(_0x38dc43){logger[_0xbc58('0x29')](_0xbc58('0x2b'),_0x5f498b,_0x38dc43);_0x6ed86e(_0x38dc43);});});}function respondWithStatusCode(_0x1646f3,_0x48b1b1){_0x48b1b1=_0x48b1b1||0xcc;return function(_0x455053){if(_0x455053){return _0x1646f3[_0xbc58('0x2f')](_0x48b1b1);}return _0x1646f3[_0xbc58('0x30')](_0x48b1b1)[_0xbc58('0x31')]();};}function respondWithResult(_0x4cc363,_0x31c84a){_0x31c84a=_0x31c84a||0xc8;return function(_0x1bd674){if(_0x1bd674){return _0x4cc363[_0xbc58('0x30')](_0x31c84a)[_0xbc58('0x32')](_0x1bd674);}};}function respondWithFilteredResult(_0x1c6c72,_0x4f1697){return function(_0x425a83){if(_0x425a83){var _0x275349=typeof _0x4f1697[_0xbc58('0x33')]===_0xbc58('0x34')&&typeof _0x4f1697[_0xbc58('0x35')]===_0xbc58('0x34');var _0x25e79b=_0x425a83['count'];var _0x229f52=_0x275349?0x0:_0x4f1697['offset'];var _0x4bb4c8=_0x275349?_0x425a83[_0xbc58('0x36')]:_0x4f1697[_0xbc58('0x33')]+_0x4f1697['limit'];var _0x2deed6;if(_0x4bb4c8>=_0x25e79b){_0x4bb4c8=_0x25e79b;_0x2deed6=0xc8;}else{_0x2deed6=0xce;}_0x1c6c72[_0xbc58('0x30')](_0x2deed6);return _0x1c6c72['set']('Content-Range',_0x229f52+'-'+_0x4bb4c8+'/'+_0x25e79b)[_0xbc58('0x32')](_0x425a83);}return null;};}function patchUpdates(_0x12b8db){return function(_0x1ed736){try{jsonpatch[_0xbc58('0x37')](_0x1ed736,_0x12b8db,!![]);}catch(_0x4ad79b){return BPromise[_0xbc58('0x38')](_0x4ad79b);}return _0x1ed736[_0xbc58('0x39')]();};}function saveUpdates(_0x24099d,_0x1c9b55){return function(_0x21dcca){if(_0x21dcca){return _0x21dcca['update'](_0x24099d)[_0xbc58('0x23')](function(_0x27d1fd){return _0x27d1fd;});}return null;};}function removeEntity(_0x512c9c,_0x4c1eae){return function(_0xf673d2){if(_0xf673d2){return _0xf673d2[_0xbc58('0x3a')]()[_0xbc58('0x23')](function(){_0x512c9c[_0xbc58('0x30')](0xcc)[_0xbc58('0x31')]();});}};}function handleEntityNotFound(_0x1bc450,_0x4b8368){return function(_0x4d6f06){if(!_0x4d6f06){_0x1bc450[_0xbc58('0x2f')](0x194);}return _0x4d6f06;};}function handleError(_0x35d835,_0x323fa1){_0x323fa1=_0x323fa1||0x1f4;return function(_0x1deb54){logger[_0xbc58('0x29')](_0x1deb54['stack']);if(_0x1deb54['name']){delete _0x1deb54[_0xbc58('0x3b')];}_0x35d835[_0xbc58('0x30')](_0x323fa1)[_0xbc58('0x3c')](_0x1deb54);};}exports[_0xbc58('0x3d')]=function(_0x127835,_0x5c6e9b){var _0x386dd1={},_0x5d86a5={},_0x5e2e16={'count':0x0,'rows':[]};var _0x174ca3=_[_0xbc58('0x3e')](db[_0xbc58('0x3f')]['rawAttributes'],function(_0x271470){return{'name':_0x271470[_0xbc58('0x40')],'type':_0x271470[_0xbc58('0x41')][_0xbc58('0x42')]};});_0x5d86a5[_0xbc58('0x43')]=_[_0xbc58('0x3e')](_0x174ca3,_0xbc58('0x3b'));_0x5d86a5['query']=_[_0xbc58('0x44')](_0x127835[_0xbc58('0x45')]);_0x5d86a5['filters']=_[_0xbc58('0x46')](_0x5d86a5['model'],_0x5d86a5['query']);_0x386dd1[_0xbc58('0x47')]=_[_0xbc58('0x46')](_0x5d86a5[_0xbc58('0x43')],qs[_0xbc58('0x48')](_0x127835[_0xbc58('0x45')][_0xbc58('0x48')]));_0x386dd1['attributes']=_0x386dd1[_0xbc58('0x47')]['length']?_0x386dd1[_0xbc58('0x47')]:_0x5d86a5[_0xbc58('0x43')];if(!_0x127835[_0xbc58('0x45')][_0xbc58('0x49')]('nolimit')){_0x386dd1[_0xbc58('0x35')]=qs[_0xbc58('0x35')](_0x127835[_0xbc58('0x45')]['limit']);_0x386dd1[_0xbc58('0x33')]=qs['offset'](_0x127835[_0xbc58('0x45')][_0xbc58('0x33')]);}_0x386dd1[_0xbc58('0x4a')]=qs[_0xbc58('0x4b')](_0x127835[_0xbc58('0x45')][_0xbc58('0x4b')]);_0x386dd1['where']=qs[_0xbc58('0x4c')](_[_0xbc58('0x4d')](_0x127835['query'],_0x5d86a5[_0xbc58('0x4c')]),_0x174ca3);if(_0x127835['query']['filter']){_0x386dd1[_0xbc58('0x4e')]=_[_0xbc58('0x4f')](_0x386dd1[_0xbc58('0x4e')],{'$or':_['map'](_0x174ca3,function(_0x2a4eeb){if(_0x2a4eeb[_0xbc58('0x41')]!=='VIRTUAL'){var _0x2c0db4={};_0x2c0db4[_0x2a4eeb[_0xbc58('0x3b')]]={'$like':'%'+_0x127835[_0xbc58('0x45')][_0xbc58('0x50')]+'%'};return _0x2c0db4;}})});}_0x386dd1=_[_0xbc58('0x4f')]({},_0x386dd1,_0x127835[_0xbc58('0x51')]);var _0x4095fd={'where':_0x386dd1['where']};return db[_0xbc58('0x3f')][_0xbc58('0x36')](_0x4095fd)[_0xbc58('0x23')](function(_0x2538b4){_0x5e2e16['count']=_0x2538b4;if(_0x127835[_0xbc58('0x45')][_0xbc58('0x52')]){_0x386dd1['include']=[{'all':!![]}];}return db['WhatsappMessage'][_0xbc58('0x53')](_0x386dd1);})[_0xbc58('0x23')](function(_0x3be311){_0x5e2e16[_0xbc58('0x54')]=_0x3be311;return _0x5e2e16;})[_0xbc58('0x23')](respondWithFilteredResult(_0x5c6e9b,_0x386dd1))[_0xbc58('0x2e')](handleError(_0x5c6e9b,null));};exports[_0xbc58('0x55')]=function(_0x12f97f,_0x22d39a){var _0x52a003={'raw':!![],'where':{'id':_0x12f97f[_0xbc58('0x56')]['id']}},_0x229f12={};_0x229f12['model']=_['keys'](db[_0xbc58('0x3f')][_0xbc58('0x57')]);_0x229f12['query']=_['keys'](_0x12f97f[_0xbc58('0x45')]);_0x229f12[_0xbc58('0x4c')]=_[_0xbc58('0x46')](_0x229f12[_0xbc58('0x43')],_0x229f12['query']);_0x52a003[_0xbc58('0x47')]=_[_0xbc58('0x46')](_0x229f12[_0xbc58('0x43')],qs[_0xbc58('0x48')](_0x12f97f[_0xbc58('0x45')][_0xbc58('0x48')]));_0x52a003[_0xbc58('0x47')]=_0x52a003[_0xbc58('0x47')]['length']?_0x52a003[_0xbc58('0x47')]:_0x229f12[_0xbc58('0x43')];if(_0x12f97f['query']['includeAll']){_0x52a003[_0xbc58('0x58')]=[{'all':!![]}];}_0x52a003=_[_0xbc58('0x4f')]({},_0x52a003,_0x12f97f[_0xbc58('0x51')]);return db[_0xbc58('0x3f')]['find'](_0x52a003)['then'](handleEntityNotFound(_0x22d39a,null))[_0xbc58('0x23')](respondWithResult(_0x22d39a,null))[_0xbc58('0x2e')](handleError(_0x22d39a,null));};exports[_0xbc58('0x59')]=function(_0x1b4e7b,_0x243276){return db[_0xbc58('0x3f')][_0xbc58('0x59')](_0x1b4e7b[_0xbc58('0x5a')],{})[_0xbc58('0x23')](respondWithResult(_0x243276,0xc9))[_0xbc58('0x2e')](handleError(_0x243276,null));};exports[_0xbc58('0x5b')]=function(_0x489210,_0x19c18f){if(_0x489210[_0xbc58('0x5a')]['id']){delete _0x489210[_0xbc58('0x5a')]['id'];}return db[_0xbc58('0x3f')][_0xbc58('0x5c')]({'where':{'id':_0x489210[_0xbc58('0x56')]['id']}})['then'](handleEntityNotFound(_0x19c18f,null))[_0xbc58('0x23')](saveUpdates(_0x489210[_0xbc58('0x5a')],null))[_0xbc58('0x23')](respondWithResult(_0x19c18f,null))[_0xbc58('0x2e')](handleError(_0x19c18f,null));};exports[_0xbc58('0x3a')]=function(_0x33769d,_0x53b61a){return db[_0xbc58('0x3f')][_0xbc58('0x5c')]({'where':{'id':_0x33769d[_0xbc58('0x56')]['id']}})[_0xbc58('0x23')](handleEntityNotFound(_0x53b61a,null))[_0xbc58('0x23')](removeEntity(_0x53b61a,null))[_0xbc58('0x2e')](handleError(_0x53b61a,null));};exports[_0xbc58('0x5d')]=function(_0x5ddace,_0x44c4a5){return db[_0xbc58('0x3f')][_0xbc58('0x5d')]()['then'](respondWithResult(_0x44c4a5,null))[_0xbc58('0x2e')](handleError(_0x44c4a5,null));};var interaction_log=require(_0xbc58('0x5e'))(_0xbc58('0x5f'));exports[_0xbc58('0x60')]=function(_0x71f113,_0x1338f1,_0x5e74bb){var _0xfd33ad={'agent':{},'channel':_0xbc58('0x61')};if(_0x71f113['body']['id']){delete _0x71f113[_0xbc58('0x5a')]['id'];}_0x71f113[_0xbc58('0x5a')][_0xbc58('0x62')]=!![];_0x71f113[_0xbc58('0x5a')][_0xbc58('0x63')]=moment()[_0xbc58('0x64')]('YYYY-MM-DD\x20HH:mm:ss');_0x71f113[_0xbc58('0x5a')][_0xbc58('0x65')]=_0x71f113[_0xbc58('0x5a')][_0xbc58('0x65')]||_0x71f113[_0xbc58('0x66')]['id'];_0xfd33ad['agent']['id']=_0x71f113[_0xbc58('0x5a')][_0xbc58('0x65')];return db[_0xbc58('0x3f')][_0xbc58('0x5c')]({'where':{'id':_0x71f113[_0xbc58('0x56')]['id'],'UserId':null}})[_0xbc58('0x23')](handleEntityNotFound(_0x1338f1,null))[_0xbc58('0x23')](saveUpdates(_0x71f113[_0xbc58('0x5a')],null))[_0xbc58('0x23')](function(_0x37f502){if(_0x37f502){_0xfd33ad[_0xbc58('0x2c')]=_0x37f502[_0xbc58('0x67')]({'plain':!![]});return db[_0xbc58('0x68')][_0xbc58('0x5c')]({'where':{'id':_0x37f502[_0xbc58('0x69')]}});}return null;})[_0xbc58('0x23')](handleEntityNotFound(_0x1338f1,null))[_0xbc58('0x23')](function(_0x554af0){if(_0x554af0){return _0x554af0[_0xbc58('0x5b')]({'UserId':_0x71f113['body'][_0xbc58('0x65')],'read1stAt':_[_0xbc58('0x6a')](_0x554af0[_0xbc58('0x6b')])?moment()[_0xbc58('0x64')](_0xbc58('0x6c')):undefined});}return null;})[_0xbc58('0x23')](function(_0x4b2588){if(_0x4b2588){_0xfd33ad[_0xbc58('0x6d')]=_0x4b2588[_0xbc58('0x67')]({'plain':!![]});interaction_log['info'](_0xbc58('0x6e'),_0x71f113[_0xbc58('0x66')]['id'],_0x71f113['user']['name'],_0x71f113[_0xbc58('0x66')][_0xbc58('0x6f')],_0xfd33ad[_0xbc58('0x6d')]['id'],_0x71f113[_0xbc58('0x5a')]?JSON['stringify'](_0x71f113[_0xbc58('0x5a')]):_0xbc58('0x70'));return respondWithRpcPromise('AcceptMessage',_0xbc58('0x71'),_0xfd33ad);}return null;})[_0xbc58('0x23')](function(_0x301bb4){var _0x496fa2='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x301bb4[_0xbc58('0x2c')][_0xbc58('0x72')];return db['sequelize'][_0xbc58('0x45')](_0x496fa2,{'type':db['Sequelize'][_0xbc58('0x73')][_0xbc58('0x74')],'raw':!![]})[_0xbc58('0x23')](function(_0x4f333e){return _0x4f333e;});})[_0xbc58('0x23')](function(_0x9f571a){if(_0x9f571a){_0xfd33ad[_0xbc58('0x2c')][_0xbc58('0x75')]=_0x9f571a[0x0];if(!_0x71f113[_0xbc58('0x5a')][_0xbc58('0x65')])return;return db[_0xbc58('0x76')]['find']({'where':{'id':_0x71f113[_0xbc58('0x5a')][_0xbc58('0x65')],'role':_0xbc58('0x77')},'attributes':['id',_0xbc58('0x3b'),_0xbc58('0x78'),_0xbc58('0x79'),'internal'],'raw':!![]});}return null;})[_0xbc58('0x23')](function(_0xebcc3b){if(!_0xebcc3b)return null;_0xfd33ad['message'][_0xbc58('0x77')]=_0xebcc3b;return _0xfd33ad;})[_0xbc58('0x23')](function(_0x2bccf3){if(_0x2bccf3){if(_0x71f113['body'][_0xbc58('0x7a')]){_0xfd33ad['message'][_0xbc58('0x7b')]=util['format'](_0xbc58('0x7c'),_0x71f113[_0xbc58('0x66')][_0xbc58('0x3b')]);_0xfd33ad['message'][_0xbc58('0x7d')]=_0xfd33ad['channel'];_0xfd33ad[_0xbc58('0x2c')][_0xbc58('0x7e')]=_0xfd33ad['channel'];_0xfd33ad[_0xbc58('0x2c')][_0xbc58('0x7f')]=_0xbc58('0x60');return respondWithRpcPromise(_0xbc58('0x80'),_0xbc58('0x80'),{'event':'acceptmessage','message':_0xfd33ad[_0xbc58('0x2c')]},client9002)[_0xbc58('0x23')](function(){return _0xfd33ad;});}return _0xfd33ad;}return null;})[_0xbc58('0x23')](respondWithResult(_0x1338f1,null))[_0xbc58('0x2e')](handleError(_0x1338f1,null));};var interaction_log=require(_0xbc58('0x5e'))('whatsapp-interactions');exports[_0xbc58('0x38')]=function(_0x14e086,_0x123e33,_0x55cb04){var _0x1e0986={'agent':{},'channel':_0xbc58('0x61')};if(_0x14e086[_0xbc58('0x5a')]['id']){delete _0x14e086['body']['id'];}_0x14e086[_0xbc58('0x5a')][_0xbc58('0x65')]=_0x14e086[_0xbc58('0x5a')][_0xbc58('0x65')]||_0x14e086['user']['id'];_0x1e0986[_0xbc58('0x77')]['id']=_0x14e086[_0xbc58('0x5a')][_0xbc58('0x65')];return db['WhatsappMessage'][_0xbc58('0x5c')]({'where':{'id':_0x14e086[_0xbc58('0x56')]['id'],'UserId':null}})[_0xbc58('0x23')](handleEntityNotFound(_0x123e33,null))[_0xbc58('0x23')](function(_0x5cee7f){if(_0x5cee7f){_0x1e0986['message']=_0x5cee7f[_0xbc58('0x67')]({'plain':!![]});return db[_0xbc58('0x68')][_0xbc58('0x5c')]({'where':{'id':_0x5cee7f[_0xbc58('0x69')]}});}return null;})[_0xbc58('0x23')](handleEntityNotFound(_0x123e33,null))[_0xbc58('0x23')](function(_0x53900a){if(_0x53900a){_0x1e0986['interaction']=_0x53900a['get']({'plain':!![]});interaction_log[_0xbc58('0x24')]('[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x14e086['user']['id'],_0x14e086[_0xbc58('0x66')][_0xbc58('0x3b')],_0x14e086[_0xbc58('0x66')][_0xbc58('0x6f')],_0x1e0986[_0xbc58('0x6d')]['id'],_0x14e086[_0xbc58('0x5a')]?JSON['stringify'](_0x14e086['body']):_0xbc58('0x70'));return respondWithRpcPromise(_0xbc58('0x81'),_0xbc58('0x82'),_0x1e0986);}return null;})['then'](function(_0x11d4d7){var _0x34ee12='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x11d4d7['message']['ContactId'];return db[_0xbc58('0x83')][_0xbc58('0x45')](_0x34ee12,{'type':db['Sequelize'][_0xbc58('0x73')][_0xbc58('0x74')],'raw':!![]})[_0xbc58('0x23')](function(_0x3f4e1d){return _0x3f4e1d;});})[_0xbc58('0x23')](function(_0x13b6c8){if(_0x13b6c8){_0x1e0986[_0xbc58('0x2c')]['contact']=_0x13b6c8[0x0];if(!_0x14e086[_0xbc58('0x5a')]['UserId'])return;return db[_0xbc58('0x76')][_0xbc58('0x5c')]({'where':{'id':_0x14e086[_0xbc58('0x5a')][_0xbc58('0x65')],'role':_0xbc58('0x77')},'attributes':['id',_0xbc58('0x3b'),_0xbc58('0x78'),_0xbc58('0x79'),_0xbc58('0x84')],'raw':!![]});}return null;})[_0xbc58('0x23')](function(_0x122a5b){if(!_0x122a5b)return null;_0x1e0986[_0xbc58('0x2c')][_0xbc58('0x77')]=_0x122a5b;return _0x1e0986;})[_0xbc58('0x23')](function(_0x4cdd0b){if(_0x4cdd0b){_0x4cdd0b[_0xbc58('0x2c')][_0xbc58('0x7b')]=util['format'](_0xbc58('0x7c'),_0x14e086[_0xbc58('0x66')]['name']);_0x4cdd0b[_0xbc58('0x2c')][_0xbc58('0x7d')]=_0x1e0986['channel'];_0x4cdd0b[_0xbc58('0x2c')][_0xbc58('0x7e')]=_0x1e0986[_0xbc58('0x7d')];_0x4cdd0b['message'][_0xbc58('0x7f')]=_0xbc58('0x38');respondWithRpcPromise('EventManager',_0xbc58('0x80'),{'event':_0xbc58('0x85'),'message':_0x4cdd0b['message']},client9002);return _0x1e0986;}return null;})[_0xbc58('0x23')](respondWithResult(_0x123e33,null))[_0xbc58('0x2e')](handleError(_0x123e33,null));};exports['status']=function(_0x43322e,_0x4482b4,_0x564b79){if(_0x43322e[_0xbc58('0x5a')]['id']){delete _0x43322e[_0xbc58('0x5a')]['id'];}var _0x3708c6;return db['WhatsappMessage'][_0xbc58('0x5c')]({'where':{'id':_0x43322e['params']['id']}})['then'](handleEntityNotFound(_0x4482b4,null))[_0xbc58('0x23')](function(_0x52f350){if(_0x52f350){_0x3708c6=_0x52f350;return db[_0xbc58('0x86')][_0xbc58('0x5c')]({'where':{'id':_0x52f350[_0xbc58('0x87')]}});}})[_0xbc58('0x23')](handleEntityNotFound(_0x4482b4,null))[_0xbc58('0x23')](function(_0x371e90){if(_0x371e90){logger['debug'](_0xbc58('0x88'),'status','received\x20delivery\x20report\x20from',_0x371e90[_0xbc58('0x41')],util['inspect'](_0x43322e[_0xbc58('0x5a')],{'showHidden':![],'depth':null}));switch(_0x371e90[_0xbc58('0x41')]){case _0xbc58('0x89'):if(_0x43322e[_0xbc58('0x5a')][_0xbc58('0x8a')]&&_0x43322e[_0xbc58('0x5a')][_0xbc58('0x8a')]===_0x3708c6['messageId']&&_0x43322e['body'][_0xbc58('0x8b')]&&_0x43322e[_0xbc58('0x5a')][_0xbc58('0x8b')]===_0xbc58('0x62')){return _0x3708c6[_0xbc58('0x5b')]({'read':!![]});}else{logger['error'](_0xbc58('0x8c'),_0xbc58('0x30'),_0xbc58('0x89'),util[_0xbc58('0x8d')](_0x43322e['body'],{'showHidden':![],'depth':null}));}break;}return _0x3708c6;}})['then'](respondWithResult(_0x4482b4,null))['catch'](handleError(_0x4482b4,null));};