7f8f8f522f9491a1e8656fc327441c763909319a
[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 _0x36f6=['update','destroy','stack','name','send','index','rawAttributes','type','model','map','query','keys','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','includeAll','include','WhatsappMessage','findAll','show','params','length','options','find','create','body','describe','whatsapp-interactions','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','get','WhatsappInteractionId','isNil','read1stAt','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','interaction','null','AcceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','contact','User','fullname','email','internal','manual','interface','SIP/%s','channel','motionChannel','event','EventManager','acceptmessage','reject','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','RejectMessage','rejectMessage','rejectmessage','WhatsappAccount','received\x20delivery\x20report\x20from','twilio','MessageSid','MessageStatus','WhatsappAccount,\x20%s,\x20%s,\x20%s','inspect','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','defaults','localhost','socket.io-emitter','register','jayson/promise','client','http','then','WhatsappMessage,\x20%s,\x20%s','request\x20sent','WhatsappMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','save'];(function(_0x3e6f74,_0xd6cbbd){var _0x1e255a=function(_0x2851ce){while(--_0x2851ce){_0x3e6f74['push'](_0x3e6f74['shift']());}};_0x1e255a(++_0xd6cbbd);}(_0x36f6,0x171));var _0x636f=function(_0x2cfb48,_0x24b83b){_0x2cfb48=_0x2cfb48-0x0;var _0xc4594f=_0x36f6[_0x2cfb48];return _0xc4594f;};'use strict';var emlformat=require(_0x636f('0x0'));var rimraf=require(_0x636f('0x1'));var zipdir=require(_0x636f('0x2'));var jsonpatch=require(_0x636f('0x3'));var rp=require(_0x636f('0x4'));var moment=require('moment');var BPromise=require(_0x636f('0x5'));var Mustache=require(_0x636f('0x6'));var util=require(_0x636f('0x7'));var path=require(_0x636f('0x8'));var sox=require(_0x636f('0x9'));var csv=require(_0x636f('0xa'));var ejs=require(_0x636f('0xb'));var fs=require('fs');var fs_extra=require(_0x636f('0xc'));var _=require(_0x636f('0xd'));var squel=require(_0x636f('0xe'));var crypto=require(_0x636f('0xf'));var jsforce=require(_0x636f('0x10'));var deskjs=require(_0x636f('0x11'));var toCsv=require(_0x636f('0xa'));var querystring=require(_0x636f('0x12'));var Papa=require(_0x636f('0x13'));var Redis=require(_0x636f('0x14'));var authService=require(_0x636f('0x15'));var qs=require(_0x636f('0x16'));var as=require(_0x636f('0x17'));var hardwareService=require(_0x636f('0x18'));var logger=require(_0x636f('0x19'))(_0x636f('0x1a'));var utils=require(_0x636f('0x1b'));var config=require('../../config/environment');var licenseUtil=require(_0x636f('0x1c'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x636f('0x1d')](config['redis'],{'host':_0x636f('0x1e'),'port':0x18eb});var socket=require(_0x636f('0x1f'))(new Redis(config['redis']));require('./whatsappMessage.socket')[_0x636f('0x20')](socket);var jayson=require(_0x636f('0x21'));var client=jayson[_0x636f('0x22')][_0x636f('0x23')]({'port':0x232c});var client9002=jayson[_0x636f('0x22')]['http']({'port':0x232a});function respondWithRpcPromise(_0xe0c03,_0x5a7551,_0x3c0eca,_0x25096e){return new BPromise(function(_0x16a739,_0x23c78b){var _0x2c9056=_0x25096e||client;return _0x2c9056['request'](_0xe0c03,_0x3c0eca)[_0x636f('0x24')](function(_0x85a27c){logger['info'](_0x636f('0x25'),_0x5a7551,_0x636f('0x26'));logger['debug'](_0x636f('0x27'),_0x5a7551,_0x636f('0x26'),JSON[_0x636f('0x28')](_0x85a27c));if(_0x85a27c[_0x636f('0x29')]){if(_0x85a27c['error'][_0x636f('0x2a')]===0x1f4){logger['error'](_0x636f('0x25'),_0x5a7551,_0x85a27c[_0x636f('0x29')][_0x636f('0x2b')]);return _0x23c78b(_0x85a27c['error']['message']);}logger[_0x636f('0x29')](_0x636f('0x25'),_0x5a7551,_0x85a27c[_0x636f('0x29')]['message']);return _0x16a739(_0x85a27c[_0x636f('0x29')]['message']);}else{logger[_0x636f('0x2c')]('WhatsappMessage,\x20%s,\x20%s',_0x5a7551,_0x636f('0x26'));_0x16a739(_0x85a27c[_0x636f('0x2d')][_0x636f('0x2b')]);}})[_0x636f('0x2e')](function(_0x45ed7b){logger[_0x636f('0x29')](_0x636f('0x25'),_0x5a7551,_0x45ed7b);_0x23c78b(_0x45ed7b);});});}function respondWithStatusCode(_0x4d934b,_0x1a9952){_0x1a9952=_0x1a9952||0xcc;return function(_0x13a597){if(_0x13a597){return _0x4d934b[_0x636f('0x2f')](_0x1a9952);}return _0x4d934b[_0x636f('0x30')](_0x1a9952)[_0x636f('0x31')]();};}function respondWithResult(_0x13d8f5,_0x4cf852){_0x4cf852=_0x4cf852||0xc8;return function(_0x27447e){if(_0x27447e){return _0x13d8f5[_0x636f('0x30')](_0x4cf852)[_0x636f('0x32')](_0x27447e);}};}function respondWithFilteredResult(_0x5366ac,_0x40217f){return function(_0x223005){if(_0x223005){var _0x16070a=typeof _0x40217f[_0x636f('0x33')]===_0x636f('0x34')&&typeof _0x40217f[_0x636f('0x35')]===_0x636f('0x34');var _0x9cd4d=_0x223005[_0x636f('0x36')];var _0x576293=_0x16070a?0x0:_0x40217f[_0x636f('0x33')];var _0x552be3=_0x16070a?_0x223005[_0x636f('0x36')]:_0x40217f[_0x636f('0x33')]+_0x40217f[_0x636f('0x35')];var _0xe022ad;if(_0x552be3>=_0x9cd4d){_0x552be3=_0x9cd4d;_0xe022ad=0xc8;}else{_0xe022ad=0xce;}_0x5366ac[_0x636f('0x30')](_0xe022ad);return _0x5366ac['set'](_0x636f('0x37'),_0x576293+'-'+_0x552be3+'/'+_0x9cd4d)[_0x636f('0x32')](_0x223005);}return null;};}function patchUpdates(_0x2b886b){return function(_0x256662){try{jsonpatch['apply'](_0x256662,_0x2b886b,!![]);}catch(_0xb548a8){return BPromise['reject'](_0xb548a8);}return _0x256662[_0x636f('0x38')]();};}function saveUpdates(_0x11fd0e,_0x26364f){return function(_0x26f04c){if(_0x26f04c){return _0x26f04c[_0x636f('0x39')](_0x11fd0e)['then'](function(_0xa6000c){return _0xa6000c;});}return null;};}function removeEntity(_0x24333e,_0x2efe29){return function(_0x1f0c0e){if(_0x1f0c0e){return _0x1f0c0e[_0x636f('0x3a')]()['then'](function(){_0x24333e[_0x636f('0x30')](0xcc)[_0x636f('0x31')]();});}};}function handleEntityNotFound(_0x2f5ef2,_0x1e6c73){return function(_0x58d37a){if(!_0x58d37a){_0x2f5ef2[_0x636f('0x2f')](0x194);}return _0x58d37a;};}function handleError(_0x173c91,_0x2ce8e6){_0x2ce8e6=_0x2ce8e6||0x1f4;return function(_0x31171a){logger[_0x636f('0x29')](_0x31171a[_0x636f('0x3b')]);if(_0x31171a[_0x636f('0x3c')]){delete _0x31171a[_0x636f('0x3c')];}_0x173c91['status'](_0x2ce8e6)[_0x636f('0x3d')](_0x31171a);};}exports[_0x636f('0x3e')]=function(_0x32bc03,_0x383d0e){var _0x3a6148={},_0x1bddb6={},_0x1a9378={'count':0x0,'rows':[]};var _0x54a200=_['map'](db['WhatsappMessage'][_0x636f('0x3f')],function(_0x3b6aea){return{'name':_0x3b6aea['fieldName'],'type':_0x3b6aea[_0x636f('0x40')]['key']};});_0x1bddb6[_0x636f('0x41')]=_[_0x636f('0x42')](_0x54a200,_0x636f('0x3c'));_0x1bddb6[_0x636f('0x43')]=_[_0x636f('0x44')](_0x32bc03[_0x636f('0x43')]);_0x1bddb6['filters']=_[_0x636f('0x45')](_0x1bddb6[_0x636f('0x41')],_0x1bddb6['query']);_0x3a6148['attributes']=_[_0x636f('0x45')](_0x1bddb6['model'],qs['fields'](_0x32bc03[_0x636f('0x43')][_0x636f('0x46')]));_0x3a6148['attributes']=_0x3a6148['attributes']['length']?_0x3a6148[_0x636f('0x47')]:_0x1bddb6['model'];if(!_0x32bc03['query'][_0x636f('0x48')](_0x636f('0x49'))){_0x3a6148[_0x636f('0x35')]=qs['limit'](_0x32bc03[_0x636f('0x43')][_0x636f('0x35')]);_0x3a6148[_0x636f('0x33')]=qs[_0x636f('0x33')](_0x32bc03['query'][_0x636f('0x33')]);}_0x3a6148[_0x636f('0x4a')]=qs[_0x636f('0x4b')](_0x32bc03[_0x636f('0x43')][_0x636f('0x4b')]);_0x3a6148[_0x636f('0x4c')]=qs[_0x636f('0x4d')](_[_0x636f('0x4e')](_0x32bc03[_0x636f('0x43')],_0x1bddb6[_0x636f('0x4d')]),_0x54a200);if(_0x32bc03[_0x636f('0x43')][_0x636f('0x4f')]){_0x3a6148[_0x636f('0x4c')]=_[_0x636f('0x50')](_0x3a6148[_0x636f('0x4c')],{'$or':_['map'](_0x54a200,function(_0x12906c){if(_0x12906c[_0x636f('0x40')]!==_0x636f('0x51')){var _0x113950={};_0x113950[_0x12906c['name']]={'$like':'%'+_0x32bc03[_0x636f('0x43')][_0x636f('0x4f')]+'%'};return _0x113950;}})});}_0x3a6148=_[_0x636f('0x50')]({},_0x3a6148,_0x32bc03['options']);var _0x46d830={'where':_0x3a6148[_0x636f('0x4c')]};return db['WhatsappMessage']['count'](_0x46d830)[_0x636f('0x24')](function(_0x512c97){_0x1a9378[_0x636f('0x36')]=_0x512c97;if(_0x32bc03[_0x636f('0x43')][_0x636f('0x52')]){_0x3a6148[_0x636f('0x53')]=[{'all':!![]}];}return db[_0x636f('0x54')][_0x636f('0x55')](_0x3a6148);})[_0x636f('0x24')](function(_0x3fe823){_0x1a9378['rows']=_0x3fe823;return _0x1a9378;})[_0x636f('0x24')](respondWithFilteredResult(_0x383d0e,_0x3a6148))[_0x636f('0x2e')](handleError(_0x383d0e,null));};exports[_0x636f('0x56')]=function(_0x16e291,_0xb56c64){var _0x22990e={'raw':!![],'where':{'id':_0x16e291[_0x636f('0x57')]['id']}},_0x1bcbd7={};_0x1bcbd7['model']=_[_0x636f('0x44')](db[_0x636f('0x54')][_0x636f('0x3f')]);_0x1bcbd7[_0x636f('0x43')]=_['keys'](_0x16e291[_0x636f('0x43')]);_0x1bcbd7[_0x636f('0x4d')]=_[_0x636f('0x45')](_0x1bcbd7[_0x636f('0x41')],_0x1bcbd7[_0x636f('0x43')]);_0x22990e[_0x636f('0x47')]=_[_0x636f('0x45')](_0x1bcbd7[_0x636f('0x41')],qs[_0x636f('0x46')](_0x16e291[_0x636f('0x43')][_0x636f('0x46')]));_0x22990e[_0x636f('0x47')]=_0x22990e[_0x636f('0x47')][_0x636f('0x58')]?_0x22990e[_0x636f('0x47')]:_0x1bcbd7[_0x636f('0x41')];if(_0x16e291[_0x636f('0x43')][_0x636f('0x52')]){_0x22990e['include']=[{'all':!![]}];}_0x22990e=_['merge']({},_0x22990e,_0x16e291[_0x636f('0x59')]);return db[_0x636f('0x54')][_0x636f('0x5a')](_0x22990e)[_0x636f('0x24')](handleEntityNotFound(_0xb56c64,null))[_0x636f('0x24')](respondWithResult(_0xb56c64,null))[_0x636f('0x2e')](handleError(_0xb56c64,null));};exports[_0x636f('0x5b')]=function(_0x262ece,_0x41ac36){return db['WhatsappMessage'][_0x636f('0x5b')](_0x262ece[_0x636f('0x5c')],{})[_0x636f('0x24')](respondWithResult(_0x41ac36,0xc9))[_0x636f('0x2e')](handleError(_0x41ac36,null));};exports[_0x636f('0x39')]=function(_0x251ea8,_0x5cb370){if(_0x251ea8[_0x636f('0x5c')]['id']){delete _0x251ea8[_0x636f('0x5c')]['id'];}return db[_0x636f('0x54')][_0x636f('0x5a')]({'where':{'id':_0x251ea8[_0x636f('0x57')]['id']}})['then'](handleEntityNotFound(_0x5cb370,null))[_0x636f('0x24')](saveUpdates(_0x251ea8[_0x636f('0x5c')],null))[_0x636f('0x24')](respondWithResult(_0x5cb370,null))['catch'](handleError(_0x5cb370,null));};exports[_0x636f('0x3a')]=function(_0x5aaeb5,_0x2e7b4c){return db[_0x636f('0x54')][_0x636f('0x5a')]({'where':{'id':_0x5aaeb5[_0x636f('0x57')]['id']}})['then'](handleEntityNotFound(_0x2e7b4c,null))[_0x636f('0x24')](removeEntity(_0x2e7b4c,null))[_0x636f('0x2e')](handleError(_0x2e7b4c,null));};exports[_0x636f('0x5d')]=function(_0x288622,_0x15c7ef){return db[_0x636f('0x54')][_0x636f('0x5d')]()[_0x636f('0x24')](respondWithResult(_0x15c7ef,null))[_0x636f('0x2e')](handleError(_0x15c7ef,null));};var interaction_log=require(_0x636f('0x19'))(_0x636f('0x5e'));exports['accept']=function(_0x29fbd9,_0x224bd3,_0x986e08){var _0xe33a88={'agent':{},'channel':'whatsapp'};if(_0x29fbd9[_0x636f('0x5c')]['id']){delete _0x29fbd9['body']['id'];}_0x29fbd9['body'][_0x636f('0x5f')]=!![];_0x29fbd9[_0x636f('0x5c')][_0x636f('0x60')]=moment()[_0x636f('0x61')](_0x636f('0x62'));_0x29fbd9[_0x636f('0x5c')][_0x636f('0x63')]=_0x29fbd9[_0x636f('0x5c')]['UserId']||_0x29fbd9[_0x636f('0x64')]['id'];_0xe33a88[_0x636f('0x65')]['id']=_0x29fbd9['body'][_0x636f('0x63')];return db[_0x636f('0x54')][_0x636f('0x5a')]({'where':{'id':_0x29fbd9[_0x636f('0x57')]['id'],'UserId':null}})[_0x636f('0x24')](handleEntityNotFound(_0x224bd3,null))['then'](saveUpdates(_0x29fbd9[_0x636f('0x5c')],null))['then'](function(_0x4b069f){if(_0x4b069f){_0xe33a88['message']=_0x4b069f[_0x636f('0x66')]({'plain':!![]});return db['WhatsappInteraction'][_0x636f('0x5a')]({'where':{'id':_0x4b069f[_0x636f('0x67')]}});}return null;})['then'](handleEntityNotFound(_0x224bd3,null))[_0x636f('0x24')](function(_0x422251){if(_0x422251){return _0x422251['update']({'UserId':_0x29fbd9['body'][_0x636f('0x63')],'read1stAt':_[_0x636f('0x68')](_0x422251[_0x636f('0x69')])?moment()[_0x636f('0x61')](_0x636f('0x62')):undefined});}return null;})[_0x636f('0x24')](function(_0x59b576){if(_0x59b576){_0xe33a88['interaction']=_0x59b576[_0x636f('0x66')]({'plain':!![]});interaction_log[_0x636f('0x2c')](_0x636f('0x6a'),_0x29fbd9['user']['id'],_0x29fbd9[_0x636f('0x64')][_0x636f('0x3c')],_0x29fbd9['user']['role'],_0xe33a88[_0x636f('0x6b')]['id'],_0x29fbd9['body']?JSON[_0x636f('0x28')](_0x29fbd9[_0x636f('0x5c')]):_0x636f('0x6c'));return respondWithRpcPromise(_0x636f('0x6d'),'acceptMessage',_0xe33a88);}return null;})[_0x636f('0x24')](function(_0x4c01ed){var _0x1ccdd5=_0x636f('0x6e')+_0x4c01ed['message'][_0x636f('0x6f')];return db[_0x636f('0x70')][_0x636f('0x43')](_0x1ccdd5,{'type':db[_0x636f('0x71')][_0x636f('0x72')][_0x636f('0x73')],'raw':!![]})['then'](function(_0x5a4933){return _0x5a4933;});})[_0x636f('0x24')](function(_0xba2cab){if(_0xba2cab){_0xe33a88[_0x636f('0x2b')][_0x636f('0x74')]=_0xba2cab[0x0];if(!_0x29fbd9[_0x636f('0x5c')][_0x636f('0x63')])return;return db[_0x636f('0x75')]['find']({'where':{'id':_0x29fbd9[_0x636f('0x5c')]['UserId'],'role':_0x636f('0x65')},'attributes':['id',_0x636f('0x3c'),_0x636f('0x76'),_0x636f('0x77'),_0x636f('0x78')],'raw':!![]});}return null;})[_0x636f('0x24')](function(_0x1020cf){if(!_0x1020cf)return null;_0xe33a88[_0x636f('0x2b')][_0x636f('0x65')]=_0x1020cf;return _0xe33a88;})[_0x636f('0x24')](function(_0x7fcf4b){if(_0x7fcf4b){if(_0x29fbd9[_0x636f('0x5c')][_0x636f('0x79')]){_0xe33a88['message'][_0x636f('0x7a')]=util['format'](_0x636f('0x7b'),_0x29fbd9[_0x636f('0x64')]['name']);_0xe33a88[_0x636f('0x2b')][_0x636f('0x7c')]=_0xe33a88[_0x636f('0x7c')];_0xe33a88[_0x636f('0x2b')][_0x636f('0x7d')]=_0xe33a88[_0x636f('0x7c')];_0xe33a88[_0x636f('0x2b')][_0x636f('0x7e')]='accept';return respondWithRpcPromise(_0x636f('0x7f'),_0x636f('0x7f'),{'event':_0x636f('0x80'),'message':_0xe33a88[_0x636f('0x2b')]},client9002)[_0x636f('0x24')](function(){return _0xe33a88;});}return _0xe33a88;}return null;})[_0x636f('0x24')](respondWithResult(_0x224bd3,null))[_0x636f('0x2e')](handleError(_0x224bd3,null));};var interaction_log=require(_0x636f('0x19'))('whatsapp-interactions');exports[_0x636f('0x81')]=function(_0x5996e8,_0x5fa4ce,_0x2ed65b){var _0x2fa8a8={'agent':{},'channel':'whatsapp'};if(_0x5996e8[_0x636f('0x5c')]['id']){delete _0x5996e8['body']['id'];}_0x5996e8[_0x636f('0x5c')][_0x636f('0x63')]=_0x5996e8[_0x636f('0x5c')][_0x636f('0x63')]||_0x5996e8[_0x636f('0x64')]['id'];_0x2fa8a8['agent']['id']=_0x5996e8[_0x636f('0x5c')][_0x636f('0x63')];return db[_0x636f('0x54')][_0x636f('0x5a')]({'where':{'id':_0x5996e8['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x5fa4ce,null))['then'](function(_0x1c3258){if(_0x1c3258){_0x2fa8a8[_0x636f('0x2b')]=_0x1c3258['get']({'plain':!![]});return db['WhatsappInteraction'][_0x636f('0x5a')]({'where':{'id':_0x1c3258['WhatsappInteractionId']}});}return null;})[_0x636f('0x24')](handleEntityNotFound(_0x5fa4ce,null))[_0x636f('0x24')](function(_0x518ea2){if(_0x518ea2){_0x2fa8a8[_0x636f('0x6b')]=_0x518ea2[_0x636f('0x66')]({'plain':!![]});interaction_log[_0x636f('0x2c')](_0x636f('0x82'),_0x5996e8[_0x636f('0x64')]['id'],_0x5996e8[_0x636f('0x64')][_0x636f('0x3c')],_0x5996e8[_0x636f('0x64')][_0x636f('0x83')],_0x2fa8a8[_0x636f('0x6b')]['id'],_0x5996e8[_0x636f('0x5c')]?JSON['stringify'](_0x5996e8['body']):_0x636f('0x6c'));return respondWithRpcPromise(_0x636f('0x84'),_0x636f('0x85'),_0x2fa8a8);}return null;})[_0x636f('0x24')](function(_0x3a9226){var _0x1974ec=_0x636f('0x6e')+_0x3a9226[_0x636f('0x2b')][_0x636f('0x6f')];return db[_0x636f('0x70')][_0x636f('0x43')](_0x1974ec,{'type':db[_0x636f('0x71')][_0x636f('0x72')]['SELECT'],'raw':!![]})[_0x636f('0x24')](function(_0x44c4c1){return _0x44c4c1;});})[_0x636f('0x24')](function(_0x31d4d6){if(_0x31d4d6){_0x2fa8a8['message'][_0x636f('0x74')]=_0x31d4d6[0x0];if(!_0x5996e8[_0x636f('0x5c')][_0x636f('0x63')])return;return db[_0x636f('0x75')][_0x636f('0x5a')]({'where':{'id':_0x5996e8[_0x636f('0x5c')][_0x636f('0x63')],'role':_0x636f('0x65')},'attributes':['id',_0x636f('0x3c'),'fullname',_0x636f('0x77'),_0x636f('0x78')],'raw':!![]});}return null;})[_0x636f('0x24')](function(_0x4ed8c6){if(!_0x4ed8c6)return null;_0x2fa8a8[_0x636f('0x2b')][_0x636f('0x65')]=_0x4ed8c6;return _0x2fa8a8;})[_0x636f('0x24')](function(_0x33ad08){if(_0x33ad08){_0x33ad08[_0x636f('0x2b')][_0x636f('0x7a')]=util[_0x636f('0x61')]('SIP/%s',_0x5996e8[_0x636f('0x64')][_0x636f('0x3c')]);_0x33ad08[_0x636f('0x2b')][_0x636f('0x7c')]=_0x2fa8a8['channel'];_0x33ad08[_0x636f('0x2b')][_0x636f('0x7d')]=_0x2fa8a8[_0x636f('0x7c')];_0x33ad08[_0x636f('0x2b')][_0x636f('0x7e')]=_0x636f('0x81');respondWithRpcPromise(_0x636f('0x7f'),_0x636f('0x7f'),{'event':_0x636f('0x86'),'message':_0x33ad08[_0x636f('0x2b')]},client9002);return _0x2fa8a8;}return null;})[_0x636f('0x24')](respondWithResult(_0x5fa4ce,null))['catch'](handleError(_0x5fa4ce,null));};exports[_0x636f('0x30')]=function(_0x274033,_0x48e69e,_0x1f8b5f){if(_0x274033['body']['id']){delete _0x274033[_0x636f('0x5c')]['id'];}var _0x17b519;return db['WhatsappMessage']['find']({'where':{'id':_0x274033[_0x636f('0x57')]['id']}})[_0x636f('0x24')](handleEntityNotFound(_0x48e69e,null))['then'](function(_0x10218d){if(_0x10218d){_0x17b519=_0x10218d;return db[_0x636f('0x87')]['find']({'where':{'id':_0x10218d['WhatsappAccountId']}});}})['then'](handleEntityNotFound(_0x48e69e,null))[_0x636f('0x24')](function(_0x2f8b42){if(_0x2f8b42){logger['debug']('WhatsppMessage,\x20%s,\x20%s,\x20%s',_0x636f('0x30'),_0x636f('0x88'),_0x2f8b42[_0x636f('0x40')],util['inspect'](_0x274033[_0x636f('0x5c')],{'showHidden':![],'depth':null}));switch(_0x2f8b42[_0x636f('0x40')]){case _0x636f('0x89'):if(_0x274033[_0x636f('0x5c')][_0x636f('0x8a')]&&_0x274033['body']['MessageSid']===_0x17b519['messageId']&&_0x274033['body'][_0x636f('0x8b')]&&_0x274033[_0x636f('0x5c')]['MessageStatus']===_0x636f('0x5f')){return _0x17b519[_0x636f('0x39')]({'read':!![]});}else{logger[_0x636f('0x29')](_0x636f('0x8c'),_0x636f('0x30'),_0x636f('0x89'),util[_0x636f('0x8d')](_0x274033[_0x636f('0x5c')],{'showHidden':![],'depth':null}));}break;}return _0x17b519;}})[_0x636f('0x24')](respondWithResult(_0x48e69e,null))[_0x636f('0x2e')](handleError(_0x48e69e,null));};