Built motion from commit a61a4a20.|2.5.46
[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 _0xfb5c=['EventManager','WhatsappInteraction','WhatsappInteractionId','null','RejectMessage','rejectMessage','User','email','rejectmessage','twilio','MessageSid','messageId','MessageStatus','WhatsappAccount,\x20%s,\x20%s,\x20%s','inspect','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','redis','defaults','./whatsappMessage.socket','register','jayson/promise','http','client','request','then','info','WhatsappMessage,\x20%s,\x20%s','request\x20sent','debug','stringify','error','message','result','catch','sendStatus','end','status','json','undefined','limit','count','offset','apply','reject','name','send','index','map','WhatsappMessage','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','include','rows','show','options','find','create','body','params','describe','whatsapp-interactions','whatsapp','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','update','isNil','read1stAt','get','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','Sequelize','QueryTypes','SELECT','contact','fullname','internal','manual','interface','SIP/%s','channel','motionChannel','accept'];(function(_0x4b4f24,_0x5654a8){var _0x1c13d4=function(_0x4940bf){while(--_0x4940bf){_0x4b4f24['push'](_0x4b4f24['shift']());}};_0x1c13d4(++_0x5654a8);}(_0xfb5c,0x11d));var _0xcfb5=function(_0x238671,_0x34aea0){_0x238671=_0x238671-0x0;var _0x474844=_0xfb5c[_0x238671];return _0x474844;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xcfb5('0x0'));var zipdir=require(_0xcfb5('0x1'));var jsonpatch=require(_0xcfb5('0x2'));var rp=require(_0xcfb5('0x3'));var moment=require(_0xcfb5('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xcfb5('0x5'));var util=require(_0xcfb5('0x6'));var path=require(_0xcfb5('0x7'));var sox=require(_0xcfb5('0x8'));var csv=require('to-csv');var ejs=require(_0xcfb5('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xcfb5('0xa'));var squel=require(_0xcfb5('0xb'));var crypto=require(_0xcfb5('0xc'));var jsforce=require(_0xcfb5('0xd'));var deskjs=require(_0xcfb5('0xe'));var toCsv=require(_0xcfb5('0xf'));var querystring=require(_0xcfb5('0x10'));var Papa=require(_0xcfb5('0x11'));var Redis=require('ioredis');var authService=require(_0xcfb5('0x12'));var qs=require(_0xcfb5('0x13'));var as=require(_0xcfb5('0x14'));var hardwareService=require(_0xcfb5('0x15'));var logger=require(_0xcfb5('0x16'))('api');var utils=require(_0xcfb5('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0xcfb5('0x18'));var db=require('../../mysqldb')['db'];config[_0xcfb5('0x19')]=_[_0xcfb5('0x1a')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0xcfb5('0x1b'))[_0xcfb5('0x1c')](socket);var jayson=require(_0xcfb5('0x1d'));var client=jayson['client'][_0xcfb5('0x1e')]({'port':0x232c});var client9002=jayson[_0xcfb5('0x1f')][_0xcfb5('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x3768de,_0x2fab97,_0x20496c,_0x59b018){return new BPromise(function(_0x63db41,_0x411d00){var _0x4f97db=_0x59b018||client;return _0x4f97db[_0xcfb5('0x20')](_0x3768de,_0x20496c)[_0xcfb5('0x21')](function(_0x398877){logger[_0xcfb5('0x22')](_0xcfb5('0x23'),_0x2fab97,_0xcfb5('0x24'));logger[_0xcfb5('0x25')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x2fab97,_0xcfb5('0x24'),JSON[_0xcfb5('0x26')](_0x398877));if(_0x398877['error']){if(_0x398877[_0xcfb5('0x27')]['code']===0x1f4){logger[_0xcfb5('0x27')]('WhatsappMessage,\x20%s,\x20%s',_0x2fab97,_0x398877['error']['message']);return _0x411d00(_0x398877[_0xcfb5('0x27')][_0xcfb5('0x28')]);}logger[_0xcfb5('0x27')](_0xcfb5('0x23'),_0x2fab97,_0x398877[_0xcfb5('0x27')]['message']);return _0x63db41(_0x398877[_0xcfb5('0x27')][_0xcfb5('0x28')]);}else{logger[_0xcfb5('0x22')]('WhatsappMessage,\x20%s,\x20%s',_0x2fab97,_0xcfb5('0x24'));_0x63db41(_0x398877[_0xcfb5('0x29')][_0xcfb5('0x28')]);}})[_0xcfb5('0x2a')](function(_0x29f676){logger['error']('WhatsappMessage,\x20%s,\x20%s',_0x2fab97,_0x29f676);_0x411d00(_0x29f676);});});}function respondWithStatusCode(_0x7b162e,_0x3c09d8){_0x3c09d8=_0x3c09d8||0xcc;return function(_0x3500b6){if(_0x3500b6){return _0x7b162e[_0xcfb5('0x2b')](_0x3c09d8);}return _0x7b162e['status'](_0x3c09d8)[_0xcfb5('0x2c')]();};}function respondWithResult(_0x54a57f,_0x195477){_0x195477=_0x195477||0xc8;return function(_0x31ff09){if(_0x31ff09){return _0x54a57f[_0xcfb5('0x2d')](_0x195477)[_0xcfb5('0x2e')](_0x31ff09);}};}function respondWithFilteredResult(_0x1141c8,_0x3564e0){return function(_0x4273ac){if(_0x4273ac){var _0x1ac1a1=typeof _0x3564e0['offset']===_0xcfb5('0x2f')&&typeof _0x3564e0[_0xcfb5('0x30')]===_0xcfb5('0x2f');var _0x5f4fb1=_0x4273ac[_0xcfb5('0x31')];var _0x10786b=_0x1ac1a1?0x0:_0x3564e0[_0xcfb5('0x32')];var _0x4421ac=_0x1ac1a1?_0x4273ac['count']:_0x3564e0[_0xcfb5('0x32')]+_0x3564e0[_0xcfb5('0x30')];var _0x42a8b3;if(_0x4421ac>=_0x5f4fb1){_0x4421ac=_0x5f4fb1;_0x42a8b3=0xc8;}else{_0x42a8b3=0xce;}_0x1141c8[_0xcfb5('0x2d')](_0x42a8b3);return _0x1141c8['set']('Content-Range',_0x10786b+'-'+_0x4421ac+'/'+_0x5f4fb1)[_0xcfb5('0x2e')](_0x4273ac);}return null;};}function patchUpdates(_0x544635){return function(_0xfd222b){try{jsonpatch[_0xcfb5('0x33')](_0xfd222b,_0x544635,!![]);}catch(_0x1c00a3){return BPromise[_0xcfb5('0x34')](_0x1c00a3);}return _0xfd222b['save']();};}function saveUpdates(_0x48046b,_0x3af002){return function(_0x4d5dd8){if(_0x4d5dd8){return _0x4d5dd8['update'](_0x48046b)[_0xcfb5('0x21')](function(_0x45a345){return _0x45a345;});}return null;};}function removeEntity(_0x1800f9,_0x103110){return function(_0x498e16){if(_0x498e16){return _0x498e16['destroy']()[_0xcfb5('0x21')](function(){_0x1800f9['status'](0xcc)[_0xcfb5('0x2c')]();});}};}function handleEntityNotFound(_0x2a1176,_0x57416e){return function(_0x4bfd4b){if(!_0x4bfd4b){_0x2a1176[_0xcfb5('0x2b')](0x194);}return _0x4bfd4b;};}function handleError(_0x8e0828,_0x3024a2){_0x3024a2=_0x3024a2||0x1f4;return function(_0x378a5b){logger[_0xcfb5('0x27')](_0x378a5b['stack']);if(_0x378a5b[_0xcfb5('0x35')]){delete _0x378a5b['name'];}_0x8e0828[_0xcfb5('0x2d')](_0x3024a2)[_0xcfb5('0x36')](_0x378a5b);};}exports[_0xcfb5('0x37')]=function(_0x40e331,_0x4731fb){var _0x14fdca={},_0x5caf31={},_0x2b9940={'count':0x0,'rows':[]};var _0x5ad667=_[_0xcfb5('0x38')](db[_0xcfb5('0x39')][_0xcfb5('0x3a')],function(_0x5f100d){return{'name':_0x5f100d[_0xcfb5('0x3b')],'type':_0x5f100d[_0xcfb5('0x3c')][_0xcfb5('0x3d')]};});_0x5caf31[_0xcfb5('0x3e')]=_[_0xcfb5('0x38')](_0x5ad667,_0xcfb5('0x35'));_0x5caf31[_0xcfb5('0x3f')]=_[_0xcfb5('0x40')](_0x40e331[_0xcfb5('0x3f')]);_0x5caf31[_0xcfb5('0x41')]=_['intersection'](_0x5caf31[_0xcfb5('0x3e')],_0x5caf31[_0xcfb5('0x3f')]);_0x14fdca[_0xcfb5('0x42')]=_[_0xcfb5('0x43')](_0x5caf31[_0xcfb5('0x3e')],qs[_0xcfb5('0x44')](_0x40e331[_0xcfb5('0x3f')][_0xcfb5('0x44')]));_0x14fdca[_0xcfb5('0x42')]=_0x14fdca[_0xcfb5('0x42')][_0xcfb5('0x45')]?_0x14fdca[_0xcfb5('0x42')]:_0x5caf31[_0xcfb5('0x3e')];if(!_0x40e331[_0xcfb5('0x3f')][_0xcfb5('0x46')](_0xcfb5('0x47'))){_0x14fdca['limit']=qs[_0xcfb5('0x30')](_0x40e331['query'][_0xcfb5('0x30')]);_0x14fdca[_0xcfb5('0x32')]=qs[_0xcfb5('0x32')](_0x40e331[_0xcfb5('0x3f')][_0xcfb5('0x32')]);}_0x14fdca[_0xcfb5('0x48')]=qs['sort'](_0x40e331[_0xcfb5('0x3f')][_0xcfb5('0x49')]);_0x14fdca[_0xcfb5('0x4a')]=qs[_0xcfb5('0x41')](_[_0xcfb5('0x4b')](_0x40e331[_0xcfb5('0x3f')],_0x5caf31[_0xcfb5('0x41')]),_0x5ad667);if(_0x40e331['query']['filter']){_0x14fdca['where']=_[_0xcfb5('0x4c')](_0x14fdca[_0xcfb5('0x4a')],{'$or':_[_0xcfb5('0x38')](_0x5ad667,function(_0xcb8fe8){if(_0xcb8fe8[_0xcfb5('0x3c')]!==_0xcfb5('0x4d')){var _0xcb9b68={};_0xcb9b68[_0xcb8fe8[_0xcfb5('0x35')]]={'$like':'%'+_0x40e331['query'][_0xcfb5('0x4e')]+'%'};return _0xcb9b68;}})});}_0x14fdca=_[_0xcfb5('0x4c')]({},_0x14fdca,_0x40e331['options']);var _0x14ce0d={'where':_0x14fdca[_0xcfb5('0x4a')]};return db[_0xcfb5('0x39')][_0xcfb5('0x31')](_0x14ce0d)[_0xcfb5('0x21')](function(_0xba0c7a){_0x2b9940[_0xcfb5('0x31')]=_0xba0c7a;if(_0x40e331[_0xcfb5('0x3f')]['includeAll']){_0x14fdca[_0xcfb5('0x4f')]=[{'all':!![]}];}return db[_0xcfb5('0x39')]['findAll'](_0x14fdca);})[_0xcfb5('0x21')](function(_0x2c57e3){_0x2b9940[_0xcfb5('0x50')]=_0x2c57e3;return _0x2b9940;})[_0xcfb5('0x21')](respondWithFilteredResult(_0x4731fb,_0x14fdca))[_0xcfb5('0x2a')](handleError(_0x4731fb,null));};exports[_0xcfb5('0x51')]=function(_0x32d97a,_0x51c143){var _0x213b95={'raw':!![],'where':{'id':_0x32d97a['params']['id']}},_0x28ad34={};_0x28ad34[_0xcfb5('0x3e')]=_[_0xcfb5('0x40')](db['WhatsappMessage'][_0xcfb5('0x3a')]);_0x28ad34['query']=_[_0xcfb5('0x40')](_0x32d97a[_0xcfb5('0x3f')]);_0x28ad34['filters']=_[_0xcfb5('0x43')](_0x28ad34[_0xcfb5('0x3e')],_0x28ad34['query']);_0x213b95[_0xcfb5('0x42')]=_['intersection'](_0x28ad34['model'],qs['fields'](_0x32d97a['query'][_0xcfb5('0x44')]));_0x213b95[_0xcfb5('0x42')]=_0x213b95[_0xcfb5('0x42')][_0xcfb5('0x45')]?_0x213b95[_0xcfb5('0x42')]:_0x28ad34[_0xcfb5('0x3e')];if(_0x32d97a[_0xcfb5('0x3f')]['includeAll']){_0x213b95[_0xcfb5('0x4f')]=[{'all':!![]}];}_0x213b95=_[_0xcfb5('0x4c')]({},_0x213b95,_0x32d97a[_0xcfb5('0x52')]);return db[_0xcfb5('0x39')][_0xcfb5('0x53')](_0x213b95)[_0xcfb5('0x21')](handleEntityNotFound(_0x51c143,null))[_0xcfb5('0x21')](respondWithResult(_0x51c143,null))[_0xcfb5('0x2a')](handleError(_0x51c143,null));};exports[_0xcfb5('0x54')]=function(_0x5a0898,_0x3934d9){return db[_0xcfb5('0x39')][_0xcfb5('0x54')](_0x5a0898['body'],{})['then'](respondWithResult(_0x3934d9,0xc9))['catch'](handleError(_0x3934d9,null));};exports['update']=function(_0x528620,_0x3aff63){if(_0x528620[_0xcfb5('0x55')]['id']){delete _0x528620[_0xcfb5('0x55')]['id'];}return db['WhatsappMessage'][_0xcfb5('0x53')]({'where':{'id':_0x528620[_0xcfb5('0x56')]['id']}})['then'](handleEntityNotFound(_0x3aff63,null))['then'](saveUpdates(_0x528620[_0xcfb5('0x55')],null))['then'](respondWithResult(_0x3aff63,null))['catch'](handleError(_0x3aff63,null));};exports['destroy']=function(_0x43b546,_0x25d55b){return db[_0xcfb5('0x39')][_0xcfb5('0x53')]({'where':{'id':_0x43b546['params']['id']}})[_0xcfb5('0x21')](handleEntityNotFound(_0x25d55b,null))['then'](removeEntity(_0x25d55b,null))['catch'](handleError(_0x25d55b,null));};exports[_0xcfb5('0x57')]=function(_0x92180a,_0x4c3a78){return db[_0xcfb5('0x39')]['describe']()[_0xcfb5('0x21')](respondWithResult(_0x4c3a78,null))[_0xcfb5('0x2a')](handleError(_0x4c3a78,null));};var interaction_log=require(_0xcfb5('0x16'))(_0xcfb5('0x58'));exports['accept']=function(_0x2f60b8,_0x6bf0f1,_0x20b213){var _0x51cc5b={'agent':{},'channel':_0xcfb5('0x59')};if(_0x2f60b8[_0xcfb5('0x55')]['id']){delete _0x2f60b8['body']['id'];}_0x2f60b8[_0xcfb5('0x55')][_0xcfb5('0x5a')]=!![];_0x2f60b8['body'][_0xcfb5('0x5b')]=moment()[_0xcfb5('0x5c')](_0xcfb5('0x5d'));_0x2f60b8[_0xcfb5('0x55')]['UserId']=_0x2f60b8[_0xcfb5('0x55')][_0xcfb5('0x5e')]||_0x2f60b8[_0xcfb5('0x5f')]['id'];_0x51cc5b[_0xcfb5('0x60')]['id']=_0x2f60b8[_0xcfb5('0x55')]['UserId'];return db[_0xcfb5('0x39')]['find']({'where':{'id':_0x2f60b8['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x6bf0f1,null))[_0xcfb5('0x21')](saveUpdates(_0x2f60b8['body'],null))[_0xcfb5('0x21')](function(_0x4352aa){if(_0x4352aa){_0x51cc5b[_0xcfb5('0x28')]=_0x4352aa['get']({'plain':!![]});return db['WhatsappInteraction'][_0xcfb5('0x53')]({'where':{'id':_0x4352aa['WhatsappInteractionId']}});}return null;})['then'](handleEntityNotFound(_0x6bf0f1,null))[_0xcfb5('0x21')](function(_0x4757a5){if(_0x4757a5){return _0x4757a5[_0xcfb5('0x61')]({'UserId':_0x2f60b8['body']['UserId'],'read1stAt':_[_0xcfb5('0x62')](_0x4757a5[_0xcfb5('0x63')])?moment()[_0xcfb5('0x5c')](_0xcfb5('0x5d')):undefined});}return null;})[_0xcfb5('0x21')](function(_0x431e59){if(_0x431e59){_0x51cc5b['interaction']=_0x431e59[_0xcfb5('0x64')]({'plain':!![]});interaction_log[_0xcfb5('0x22')](_0xcfb5('0x65'),_0x2f60b8[_0xcfb5('0x5f')]['id'],_0x2f60b8[_0xcfb5('0x5f')][_0xcfb5('0x35')],_0x2f60b8['user'][_0xcfb5('0x66')],_0x51cc5b[_0xcfb5('0x67')]['id'],_0x2f60b8[_0xcfb5('0x55')]?JSON[_0xcfb5('0x26')](_0x2f60b8[_0xcfb5('0x55')]):'null');return respondWithRpcPromise(_0xcfb5('0x68'),_0xcfb5('0x69'),_0x51cc5b);}return null;})['then'](function(_0x1710a7){var _0x38c56a=_0xcfb5('0x6a')+_0x1710a7[_0xcfb5('0x28')][_0xcfb5('0x6b')];return db['sequelize']['query'](_0x38c56a,{'type':db[_0xcfb5('0x6c')][_0xcfb5('0x6d')][_0xcfb5('0x6e')],'raw':!![]})[_0xcfb5('0x21')](function(_0x403b6b){return _0x403b6b;});})[_0xcfb5('0x21')](function(_0x55de08){if(_0x55de08){_0x51cc5b[_0xcfb5('0x28')][_0xcfb5('0x6f')]=_0x55de08[0x0];if(!_0x2f60b8[_0xcfb5('0x55')]['UserId'])return;return db['User']['find']({'where':{'id':_0x2f60b8['body']['UserId'],'role':_0xcfb5('0x60')},'attributes':['id',_0xcfb5('0x35'),_0xcfb5('0x70'),'email',_0xcfb5('0x71')],'raw':!![]});}return null;})['then'](function(_0x7e1a40){if(!_0x7e1a40)return null;_0x51cc5b[_0xcfb5('0x28')]['agent']=_0x7e1a40;return _0x51cc5b;})[_0xcfb5('0x21')](function(_0x5f0619){if(_0x5f0619){if(_0x2f60b8[_0xcfb5('0x55')][_0xcfb5('0x72')]){_0x51cc5b[_0xcfb5('0x28')][_0xcfb5('0x73')]=util['format'](_0xcfb5('0x74'),_0x2f60b8[_0xcfb5('0x5f')]['name']);_0x51cc5b['message'][_0xcfb5('0x75')]=_0x51cc5b[_0xcfb5('0x75')];_0x51cc5b[_0xcfb5('0x28')][_0xcfb5('0x76')]=_0x51cc5b[_0xcfb5('0x75')];_0x51cc5b[_0xcfb5('0x28')]['event']=_0xcfb5('0x77');return respondWithRpcPromise(_0xcfb5('0x78'),_0xcfb5('0x78'),{'event':'acceptmessage','message':_0x51cc5b[_0xcfb5('0x28')]},client9002)[_0xcfb5('0x21')](function(){return _0x51cc5b;});}return _0x51cc5b;}return null;})['then'](respondWithResult(_0x6bf0f1,null))['catch'](handleError(_0x6bf0f1,null));};var interaction_log=require(_0xcfb5('0x16'))('whatsapp-interactions');exports['reject']=function(_0x5be558,_0x276e3a,_0x57e0bf){var _0x40b684={'agent':{},'channel':'whatsapp'};if(_0x5be558[_0xcfb5('0x55')]['id']){delete _0x5be558['body']['id'];}_0x5be558[_0xcfb5('0x55')][_0xcfb5('0x5e')]=_0x5be558[_0xcfb5('0x55')][_0xcfb5('0x5e')]||_0x5be558[_0xcfb5('0x5f')]['id'];_0x40b684['agent']['id']=_0x5be558[_0xcfb5('0x55')][_0xcfb5('0x5e')];return db['WhatsappMessage'][_0xcfb5('0x53')]({'where':{'id':_0x5be558['params']['id'],'UserId':null}})[_0xcfb5('0x21')](handleEntityNotFound(_0x276e3a,null))['then'](function(_0x1ee66b){if(_0x1ee66b){_0x40b684[_0xcfb5('0x28')]=_0x1ee66b[_0xcfb5('0x64')]({'plain':!![]});return db[_0xcfb5('0x79')][_0xcfb5('0x53')]({'where':{'id':_0x1ee66b[_0xcfb5('0x7a')]}});}return null;})[_0xcfb5('0x21')](handleEntityNotFound(_0x276e3a,null))['then'](function(_0x5b6109){if(_0x5b6109){_0x40b684['interaction']=_0x5b6109[_0xcfb5('0x64')]({'plain':!![]});interaction_log[_0xcfb5('0x22')]('[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x5be558['user']['id'],_0x5be558[_0xcfb5('0x5f')][_0xcfb5('0x35')],_0x5be558[_0xcfb5('0x5f')][_0xcfb5('0x66')],_0x40b684[_0xcfb5('0x67')]['id'],_0x5be558[_0xcfb5('0x55')]?JSON[_0xcfb5('0x26')](_0x5be558[_0xcfb5('0x55')]):_0xcfb5('0x7b'));return respondWithRpcPromise(_0xcfb5('0x7c'),_0xcfb5('0x7d'),_0x40b684);}return null;})[_0xcfb5('0x21')](function(_0x400bd5){var _0x37b58e=_0xcfb5('0x6a')+_0x400bd5[_0xcfb5('0x28')][_0xcfb5('0x6b')];return db['sequelize']['query'](_0x37b58e,{'type':db[_0xcfb5('0x6c')]['QueryTypes'][_0xcfb5('0x6e')],'raw':!![]})[_0xcfb5('0x21')](function(_0x3dcf44){return _0x3dcf44;});})[_0xcfb5('0x21')](function(_0x2d9ae2){if(_0x2d9ae2){_0x40b684[_0xcfb5('0x28')][_0xcfb5('0x6f')]=_0x2d9ae2[0x0];if(!_0x5be558[_0xcfb5('0x55')][_0xcfb5('0x5e')])return;return db[_0xcfb5('0x7e')][_0xcfb5('0x53')]({'where':{'id':_0x5be558[_0xcfb5('0x55')][_0xcfb5('0x5e')],'role':_0xcfb5('0x60')},'attributes':['id',_0xcfb5('0x35'),_0xcfb5('0x70'),_0xcfb5('0x7f'),_0xcfb5('0x71')],'raw':!![]});}return null;})[_0xcfb5('0x21')](function(_0x448996){if(!_0x448996)return null;_0x40b684[_0xcfb5('0x28')][_0xcfb5('0x60')]=_0x448996;return _0x40b684;})[_0xcfb5('0x21')](function(_0x2e5397){if(_0x2e5397){_0x2e5397['message'][_0xcfb5('0x73')]=util['format']('SIP/%s',_0x5be558['user']['name']);_0x2e5397['message'][_0xcfb5('0x75')]=_0x40b684['channel'];_0x2e5397['message'][_0xcfb5('0x76')]=_0x40b684[_0xcfb5('0x75')];_0x2e5397[_0xcfb5('0x28')]['event']=_0xcfb5('0x34');respondWithRpcPromise(_0xcfb5('0x78'),_0xcfb5('0x78'),{'event':_0xcfb5('0x80'),'message':_0x2e5397[_0xcfb5('0x28')]},client9002);return _0x40b684;}return null;})[_0xcfb5('0x21')](respondWithResult(_0x276e3a,null))['catch'](handleError(_0x276e3a,null));};exports[_0xcfb5('0x2d')]=function(_0x2ee59a,_0x41d735,_0x3be299){if(_0x2ee59a[_0xcfb5('0x55')]['id']){delete _0x2ee59a['body']['id'];}var _0x41b6b1;return db[_0xcfb5('0x39')]['find']({'where':{'id':_0x2ee59a[_0xcfb5('0x56')]['id']}})['then'](handleEntityNotFound(_0x41d735,null))['then'](function(_0x35bd87){if(_0x35bd87){_0x41b6b1=_0x35bd87;return db['WhatsappAccount'][_0xcfb5('0x53')]({'where':{'id':_0x35bd87['WhatsappAccountId']}});}})[_0xcfb5('0x21')](handleEntityNotFound(_0x41d735,null))[_0xcfb5('0x21')](function(_0x275210){if(_0x275210){logger[_0xcfb5('0x25')]('WhatsppMessage,\x20%s,\x20%s,\x20%s','status','received\x20delivery\x20report\x20from',_0x275210[_0xcfb5('0x3c')],util['inspect'](_0x2ee59a[_0xcfb5('0x55')],{'showHidden':![],'depth':null}));switch(_0x275210[_0xcfb5('0x3c')]){case _0xcfb5('0x81'):if(_0x2ee59a[_0xcfb5('0x55')][_0xcfb5('0x82')]&&_0x2ee59a[_0xcfb5('0x55')][_0xcfb5('0x82')]===_0x41b6b1[_0xcfb5('0x83')]&&_0x2ee59a[_0xcfb5('0x55')]['MessageStatus']&&_0x2ee59a['body'][_0xcfb5('0x84')]===_0xcfb5('0x5a')){return _0x41b6b1[_0xcfb5('0x61')]({'read':!![]});}else{logger[_0xcfb5('0x27')](_0xcfb5('0x85'),'status',_0xcfb5('0x81'),util[_0xcfb5('0x86')](_0x2ee59a[_0xcfb5('0x55')],{'showHidden':![],'depth':null}));}break;}return _0x41b6b1;}})['then'](respondWithResult(_0x41d735,null))[_0xcfb5('0x2a')](handleError(_0x41d735,null));};