Built motion from commit 9b156c94.|2.6.22
[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 _0xff43=['get','WhatsappInteraction','WhatsappInteractionId','read1stAt','interaction','[WHATSAPPMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','contact','User','fullname','internal','channel','motionChannel','event','EventManager','acceptmessage','[WHATSAPPMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','email','interface','format','reject','rejectmessage','WhatsappAccountId','received\x20delivery\x20report\x20from','twilio','MessageSid','MessageStatus','read','inspect','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/utils','../../config/environment','../../mysqldb','redis','localhost','socket.io-emitter','./whatsappMessage.socket','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','catch','sendStatus','status','end','offset','undefined','count','Content-Range','json','apply','save','update','destroy','name','send','index','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','WhatsappMessage','includeAll','findAll','rows','show','params','fields','length','include','options','find','create','body','describe','whatsapp-interactions','accept','whatsapp','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent'];(function(_0x252805,_0x1d1e8e){var _0x3e74b9=function(_0x16d7a0){while(--_0x16d7a0){_0x252805['push'](_0x252805['shift']());}};_0x3e74b9(++_0x1d1e8e);}(_0xff43,0x137));var _0x3ff4=function(_0x290b9f,_0x3141ad){_0x290b9f=_0x290b9f-0x0;var _0x32605f=_0xff43[_0x290b9f];return _0x32605f;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x3ff4('0x0'));var zipdir=require(_0x3ff4('0x1'));var jsonpatch=require(_0x3ff4('0x2'));var rp=require(_0x3ff4('0x3'));var moment=require(_0x3ff4('0x4'));var BPromise=require(_0x3ff4('0x5'));var Mustache=require(_0x3ff4('0x6'));var util=require(_0x3ff4('0x7'));var path=require(_0x3ff4('0x8'));var sox=require(_0x3ff4('0x9'));var csv=require(_0x3ff4('0xa'));var ejs=require(_0x3ff4('0xb'));var fs=require('fs');var fs_extra=require(_0x3ff4('0xc'));var _=require(_0x3ff4('0xd'));var squel=require(_0x3ff4('0xe'));var crypto=require(_0x3ff4('0xf'));var jsforce=require('jsforce');var deskjs=require(_0x3ff4('0x10'));var toCsv=require(_0x3ff4('0xa'));var querystring=require(_0x3ff4('0x11'));var Papa=require(_0x3ff4('0x12'));var Redis=require(_0x3ff4('0x13'));var authService=require(_0x3ff4('0x14'));var qs=require(_0x3ff4('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x3ff4('0x16'));var logger=require('../../config/logger')('api');var utils=require(_0x3ff4('0x17'));var config=require(_0x3ff4('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0x3ff4('0x19'))['db'];config['redis']=_['defaults'](config[_0x3ff4('0x1a')],{'host':_0x3ff4('0x1b'),'port':0x18eb});var socket=require(_0x3ff4('0x1c'))(new Redis(config['redis']));require(_0x3ff4('0x1d'))['register'](socket);var jayson=require(_0x3ff4('0x1e'));var client=jayson[_0x3ff4('0x1f')][_0x3ff4('0x20')]({'port':0x232c});var client9002=jayson['client'][_0x3ff4('0x20')]({'port':0x232a});function respondWithRpcPromise(_0x4027f8,_0x34074e,_0x3e28f5,_0x568219){return new BPromise(function(_0x7046b9,_0x6cc8e8){var _0x27fb67=_0x568219||client;return _0x27fb67[_0x3ff4('0x21')](_0x4027f8,_0x3e28f5)[_0x3ff4('0x22')](function(_0x688940){logger[_0x3ff4('0x23')]('WhatsappMessage,\x20%s,\x20%s',_0x34074e,_0x3ff4('0x24'));logger[_0x3ff4('0x25')](_0x3ff4('0x26'),_0x34074e,_0x3ff4('0x24'),JSON[_0x3ff4('0x27')](_0x688940));if(_0x688940[_0x3ff4('0x28')]){if(_0x688940[_0x3ff4('0x28')][_0x3ff4('0x29')]===0x1f4){logger[_0x3ff4('0x28')](_0x3ff4('0x2a'),_0x34074e,_0x688940['error'][_0x3ff4('0x2b')]);return _0x6cc8e8(_0x688940['error'][_0x3ff4('0x2b')]);}logger[_0x3ff4('0x28')](_0x3ff4('0x2a'),_0x34074e,_0x688940[_0x3ff4('0x28')][_0x3ff4('0x2b')]);return _0x7046b9(_0x688940[_0x3ff4('0x28')][_0x3ff4('0x2b')]);}else{logger[_0x3ff4('0x23')]('WhatsappMessage,\x20%s,\x20%s',_0x34074e,'request\x20sent');_0x7046b9(_0x688940['result'][_0x3ff4('0x2b')]);}})[_0x3ff4('0x2c')](function(_0x17ed4a){logger['error'](_0x3ff4('0x2a'),_0x34074e,_0x17ed4a);_0x6cc8e8(_0x17ed4a);});});}function respondWithStatusCode(_0x45e40e,_0x1bc1da){_0x1bc1da=_0x1bc1da||0xcc;return function(_0x25b1c5){if(_0x25b1c5){return _0x45e40e[_0x3ff4('0x2d')](_0x1bc1da);}return _0x45e40e[_0x3ff4('0x2e')](_0x1bc1da)[_0x3ff4('0x2f')]();};}function respondWithResult(_0x1208ab,_0x471a1e){_0x471a1e=_0x471a1e||0xc8;return function(_0xc8fb37){if(_0xc8fb37){return _0x1208ab['status'](_0x471a1e)['json'](_0xc8fb37);}};}function respondWithFilteredResult(_0xbd782d,_0x3183b3){return function(_0xba29e7){if(_0xba29e7){var _0x20ad89=typeof _0x3183b3[_0x3ff4('0x30')]==='undefined'&&typeof _0x3183b3['limit']===_0x3ff4('0x31');var _0x19fdb7=_0xba29e7[_0x3ff4('0x32')];var _0x4fc936=_0x20ad89?0x0:_0x3183b3[_0x3ff4('0x30')];var _0x4a1848=_0x20ad89?_0xba29e7[_0x3ff4('0x32')]:_0x3183b3['offset']+_0x3183b3['limit'];var _0x2ab7e5;if(_0x4a1848>=_0x19fdb7){_0x4a1848=_0x19fdb7;_0x2ab7e5=0xc8;}else{_0x2ab7e5=0xce;}_0xbd782d[_0x3ff4('0x2e')](_0x2ab7e5);return _0xbd782d['set'](_0x3ff4('0x33'),_0x4fc936+'-'+_0x4a1848+'/'+_0x19fdb7)[_0x3ff4('0x34')](_0xba29e7);}return null;};}function patchUpdates(_0x23c525){return function(_0x40ad8f){try{jsonpatch[_0x3ff4('0x35')](_0x40ad8f,_0x23c525,!![]);}catch(_0x100a9c){return BPromise['reject'](_0x100a9c);}return _0x40ad8f[_0x3ff4('0x36')]();};}function saveUpdates(_0x2d9677,_0x5dc2d6){return function(_0x5530e3){if(_0x5530e3){return _0x5530e3[_0x3ff4('0x37')](_0x2d9677)[_0x3ff4('0x22')](function(_0xa09051){return _0xa09051;});}return null;};}function removeEntity(_0x5a1778,_0x1fd53e){return function(_0x4634ac){if(_0x4634ac){return _0x4634ac[_0x3ff4('0x38')]()[_0x3ff4('0x22')](function(){_0x5a1778['status'](0xcc)[_0x3ff4('0x2f')]();});}};}function handleEntityNotFound(_0x3ce440,_0x319833){return function(_0x18d78b){if(!_0x18d78b){_0x3ce440[_0x3ff4('0x2d')](0x194);}return _0x18d78b;};}function handleError(_0x2f4649,_0x5b3715){_0x5b3715=_0x5b3715||0x1f4;return function(_0x2e5cc0){logger['error'](_0x2e5cc0['stack']);if(_0x2e5cc0['name']){delete _0x2e5cc0[_0x3ff4('0x39')];}_0x2f4649['status'](_0x5b3715)[_0x3ff4('0x3a')](_0x2e5cc0);};}exports[_0x3ff4('0x3b')]=function(_0x5e7c6b,_0x28eb9e){var _0x470b7a={},_0x41a0a8={},_0x152719={'count':0x0,'rows':[]};var _0x6ab56b=_['map'](db['WhatsappMessage'][_0x3ff4('0x3c')],function(_0x50d946){return{'name':_0x50d946[_0x3ff4('0x3d')],'type':_0x50d946[_0x3ff4('0x3e')]['key']};});_0x41a0a8[_0x3ff4('0x3f')]=_['map'](_0x6ab56b,_0x3ff4('0x39'));_0x41a0a8[_0x3ff4('0x40')]=_[_0x3ff4('0x41')](_0x5e7c6b[_0x3ff4('0x40')]);_0x41a0a8[_0x3ff4('0x42')]=_['intersection'](_0x41a0a8['model'],_0x41a0a8[_0x3ff4('0x40')]);_0x470b7a['attributes']=_[_0x3ff4('0x43')](_0x41a0a8[_0x3ff4('0x3f')],qs['fields'](_0x5e7c6b[_0x3ff4('0x40')]['fields']));_0x470b7a[_0x3ff4('0x44')]=_0x470b7a[_0x3ff4('0x44')]['length']?_0x470b7a[_0x3ff4('0x44')]:_0x41a0a8['model'];if(!_0x5e7c6b[_0x3ff4('0x40')][_0x3ff4('0x45')](_0x3ff4('0x46'))){_0x470b7a[_0x3ff4('0x47')]=qs[_0x3ff4('0x47')](_0x5e7c6b[_0x3ff4('0x40')][_0x3ff4('0x47')]);_0x470b7a[_0x3ff4('0x30')]=qs[_0x3ff4('0x30')](_0x5e7c6b[_0x3ff4('0x40')][_0x3ff4('0x30')]);}_0x470b7a[_0x3ff4('0x48')]=qs[_0x3ff4('0x49')](_0x5e7c6b[_0x3ff4('0x40')][_0x3ff4('0x49')]);_0x470b7a[_0x3ff4('0x4a')]=qs['filters'](_[_0x3ff4('0x4b')](_0x5e7c6b[_0x3ff4('0x40')],_0x41a0a8[_0x3ff4('0x42')]),_0x6ab56b);if(_0x5e7c6b['query'][_0x3ff4('0x4c')]){_0x470b7a[_0x3ff4('0x4a')]=_[_0x3ff4('0x4d')](_0x470b7a['where'],{'$or':_['map'](_0x6ab56b,function(_0x56e864){if(_0x56e864[_0x3ff4('0x3e')]!=='VIRTUAL'){var _0x599d72={};_0x599d72[_0x56e864[_0x3ff4('0x39')]]={'$like':'%'+_0x5e7c6b[_0x3ff4('0x40')][_0x3ff4('0x4c')]+'%'};return _0x599d72;}})});}_0x470b7a=_['merge']({},_0x470b7a,_0x5e7c6b['options']);var _0x43b878={'where':_0x470b7a['where']};return db[_0x3ff4('0x4e')][_0x3ff4('0x32')](_0x43b878)[_0x3ff4('0x22')](function(_0x48361b){_0x152719[_0x3ff4('0x32')]=_0x48361b;if(_0x5e7c6b[_0x3ff4('0x40')][_0x3ff4('0x4f')]){_0x470b7a['include']=[{'all':!![]}];}return db[_0x3ff4('0x4e')][_0x3ff4('0x50')](_0x470b7a);})[_0x3ff4('0x22')](function(_0x4d7a36){_0x152719[_0x3ff4('0x51')]=_0x4d7a36;return _0x152719;})['then'](respondWithFilteredResult(_0x28eb9e,_0x470b7a))[_0x3ff4('0x2c')](handleError(_0x28eb9e,null));};exports[_0x3ff4('0x52')]=function(_0x36a3e7,_0x5f1e23){var _0x534f09={'raw':!![],'where':{'id':_0x36a3e7[_0x3ff4('0x53')]['id']}},_0x44cdae={};_0x44cdae[_0x3ff4('0x3f')]=_['keys'](db[_0x3ff4('0x4e')][_0x3ff4('0x3c')]);_0x44cdae[_0x3ff4('0x40')]=_[_0x3ff4('0x41')](_0x36a3e7[_0x3ff4('0x40')]);_0x44cdae[_0x3ff4('0x42')]=_[_0x3ff4('0x43')](_0x44cdae[_0x3ff4('0x3f')],_0x44cdae[_0x3ff4('0x40')]);_0x534f09[_0x3ff4('0x44')]=_[_0x3ff4('0x43')](_0x44cdae['model'],qs[_0x3ff4('0x54')](_0x36a3e7[_0x3ff4('0x40')][_0x3ff4('0x54')]));_0x534f09['attributes']=_0x534f09['attributes'][_0x3ff4('0x55')]?_0x534f09[_0x3ff4('0x44')]:_0x44cdae[_0x3ff4('0x3f')];if(_0x36a3e7[_0x3ff4('0x40')]['includeAll']){_0x534f09[_0x3ff4('0x56')]=[{'all':!![]}];}_0x534f09=_[_0x3ff4('0x4d')]({},_0x534f09,_0x36a3e7[_0x3ff4('0x57')]);return db[_0x3ff4('0x4e')][_0x3ff4('0x58')](_0x534f09)[_0x3ff4('0x22')](handleEntityNotFound(_0x5f1e23,null))[_0x3ff4('0x22')](respondWithResult(_0x5f1e23,null))[_0x3ff4('0x2c')](handleError(_0x5f1e23,null));};exports[_0x3ff4('0x59')]=function(_0x3b231c,_0x323742){return db[_0x3ff4('0x4e')][_0x3ff4('0x59')](_0x3b231c[_0x3ff4('0x5a')],{})[_0x3ff4('0x22')](respondWithResult(_0x323742,0xc9))[_0x3ff4('0x2c')](handleError(_0x323742,null));};exports[_0x3ff4('0x37')]=function(_0x53e6a4,_0xe7ba95){if(_0x53e6a4[_0x3ff4('0x5a')]['id']){delete _0x53e6a4[_0x3ff4('0x5a')]['id'];}return db['WhatsappMessage']['find']({'where':{'id':_0x53e6a4[_0x3ff4('0x53')]['id']}})['then'](handleEntityNotFound(_0xe7ba95,null))[_0x3ff4('0x22')](saveUpdates(_0x53e6a4[_0x3ff4('0x5a')],null))[_0x3ff4('0x22')](respondWithResult(_0xe7ba95,null))['catch'](handleError(_0xe7ba95,null));};exports[_0x3ff4('0x38')]=function(_0x57f31c,_0x32c561){return db['WhatsappMessage']['find']({'where':{'id':_0x57f31c['params']['id']}})['then'](handleEntityNotFound(_0x32c561,null))[_0x3ff4('0x22')](removeEntity(_0x32c561,null))['catch'](handleError(_0x32c561,null));};exports[_0x3ff4('0x5b')]=function(_0x40497d,_0x33ce8e){return db[_0x3ff4('0x4e')][_0x3ff4('0x5b')]()[_0x3ff4('0x22')](respondWithResult(_0x33ce8e,null))[_0x3ff4('0x2c')](handleError(_0x33ce8e,null));};var interaction_log=require('../../config/logger')(_0x3ff4('0x5c'));exports[_0x3ff4('0x5d')]=function(_0x4d6c12,_0x2f6745,_0x26754f){var _0x2ccfb6={'agent':{},'channel':_0x3ff4('0x5e')};if(_0x4d6c12[_0x3ff4('0x5a')]['id']){delete _0x4d6c12[_0x3ff4('0x5a')]['id'];}_0x4d6c12[_0x3ff4('0x5a')]['read']=!![];_0x4d6c12['body'][_0x3ff4('0x5f')]=moment()['format'](_0x3ff4('0x60'));_0x4d6c12[_0x3ff4('0x5a')]['UserId']=_0x4d6c12[_0x3ff4('0x5a')][_0x3ff4('0x61')]||_0x4d6c12[_0x3ff4('0x62')]['id'];_0x2ccfb6[_0x3ff4('0x63')]['id']=_0x4d6c12[_0x3ff4('0x5a')][_0x3ff4('0x61')];return db[_0x3ff4('0x4e')][_0x3ff4('0x58')]({'where':{'id':_0x4d6c12[_0x3ff4('0x53')]['id'],'UserId':null}})[_0x3ff4('0x22')](handleEntityNotFound(_0x2f6745,null))[_0x3ff4('0x22')](saveUpdates(_0x4d6c12[_0x3ff4('0x5a')],null))[_0x3ff4('0x22')](function(_0x2e800a){if(_0x2e800a){_0x2ccfb6['message']=_0x2e800a[_0x3ff4('0x64')]({'plain':!![]});return db[_0x3ff4('0x65')][_0x3ff4('0x58')]({'where':{'id':_0x2e800a[_0x3ff4('0x66')]}});}return null;})[_0x3ff4('0x22')](handleEntityNotFound(_0x2f6745,null))[_0x3ff4('0x22')](function(_0x56b5c8){if(_0x56b5c8){return _0x56b5c8[_0x3ff4('0x37')]({'UserId':_0x4d6c12[_0x3ff4('0x5a')][_0x3ff4('0x61')],'read1stAt':_['isNil'](_0x56b5c8[_0x3ff4('0x67')])?moment()['format']('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0x3ff4('0x22')](function(_0x2990ed){if(_0x2990ed){_0x2ccfb6[_0x3ff4('0x68')]=_0x2990ed['get']({'plain':!![]});interaction_log[_0x3ff4('0x23')](_0x3ff4('0x69'),_0x4d6c12[_0x3ff4('0x62')]['id'],_0x4d6c12[_0x3ff4('0x62')][_0x3ff4('0x39')],_0x4d6c12[_0x3ff4('0x62')][_0x3ff4('0x6a')],_0x2ccfb6[_0x3ff4('0x68')]['id'],_0x4d6c12[_0x3ff4('0x5a')]?JSON['stringify'](_0x4d6c12['body']):_0x3ff4('0x6b'));return respondWithRpcPromise(_0x3ff4('0x6c'),'acceptMessage',_0x2ccfb6);}return null;})[_0x3ff4('0x22')](function(_0x603d3e){var _0x395611=_0x3ff4('0x6d')+_0x603d3e[_0x3ff4('0x2b')][_0x3ff4('0x6e')];return db[_0x3ff4('0x6f')][_0x3ff4('0x40')](_0x395611,{'type':db[_0x3ff4('0x70')]['QueryTypes']['SELECT'],'raw':!![]})[_0x3ff4('0x22')](function(_0xebba1c){return _0xebba1c;});})[_0x3ff4('0x22')](function(_0x18a7f0){if(_0x18a7f0){_0x2ccfb6[_0x3ff4('0x2b')][_0x3ff4('0x71')]=_0x18a7f0[0x0];if(!_0x4d6c12[_0x3ff4('0x5a')]['UserId'])return;return db[_0x3ff4('0x72')]['find']({'where':{'id':_0x4d6c12[_0x3ff4('0x5a')]['UserId'],'role':_0x3ff4('0x63')},'attributes':['id',_0x3ff4('0x39'),_0x3ff4('0x73'),'email',_0x3ff4('0x74')],'raw':!![]});}return null;})[_0x3ff4('0x22')](function(_0x1742e8){if(!_0x1742e8)return null;_0x2ccfb6[_0x3ff4('0x2b')][_0x3ff4('0x63')]=_0x1742e8;return _0x2ccfb6;})[_0x3ff4('0x22')](function(_0x7dc63b){if(_0x7dc63b){if(_0x4d6c12['body']['manual']){_0x2ccfb6[_0x3ff4('0x2b')]['interface']=util['format']('SIP/%s',_0x4d6c12[_0x3ff4('0x62')]['name']);_0x2ccfb6['message']['channel']=_0x2ccfb6[_0x3ff4('0x75')];_0x2ccfb6[_0x3ff4('0x2b')][_0x3ff4('0x76')]=_0x2ccfb6[_0x3ff4('0x75')];_0x2ccfb6[_0x3ff4('0x2b')][_0x3ff4('0x77')]=_0x3ff4('0x5d');return respondWithRpcPromise(_0x3ff4('0x78'),_0x3ff4('0x78'),{'event':_0x3ff4('0x79'),'message':_0x2ccfb6[_0x3ff4('0x2b')]},client9002)[_0x3ff4('0x22')](function(){return _0x2ccfb6;});}return _0x2ccfb6;}return null;})[_0x3ff4('0x22')](respondWithResult(_0x2f6745,null))[_0x3ff4('0x2c')](handleError(_0x2f6745,null));};var interaction_log=require('../../config/logger')(_0x3ff4('0x5c'));exports['reject']=function(_0x1a1271,_0x448f07,_0x2550ee){var _0x46ff35={'agent':{},'channel':_0x3ff4('0x5e')};if(_0x1a1271[_0x3ff4('0x5a')]['id']){delete _0x1a1271[_0x3ff4('0x5a')]['id'];}_0x1a1271[_0x3ff4('0x5a')][_0x3ff4('0x61')]=_0x1a1271[_0x3ff4('0x5a')][_0x3ff4('0x61')]||_0x1a1271[_0x3ff4('0x62')]['id'];_0x46ff35[_0x3ff4('0x63')]['id']=_0x1a1271[_0x3ff4('0x5a')][_0x3ff4('0x61')];return db['WhatsappMessage'][_0x3ff4('0x58')]({'where':{'id':_0x1a1271[_0x3ff4('0x53')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x448f07,null))[_0x3ff4('0x22')](function(_0x487d6b){if(_0x487d6b){_0x46ff35['message']=_0x487d6b[_0x3ff4('0x64')]({'plain':!![]});return db[_0x3ff4('0x65')][_0x3ff4('0x58')]({'where':{'id':_0x487d6b['WhatsappInteractionId']}});}return null;})[_0x3ff4('0x22')](handleEntityNotFound(_0x448f07,null))['then'](function(_0xda957f){if(_0xda957f){_0x46ff35['interaction']=_0xda957f[_0x3ff4('0x64')]({'plain':!![]});interaction_log[_0x3ff4('0x23')](_0x3ff4('0x7a'),_0x1a1271[_0x3ff4('0x62')]['id'],_0x1a1271['user'][_0x3ff4('0x39')],_0x1a1271[_0x3ff4('0x62')][_0x3ff4('0x6a')],_0x46ff35[_0x3ff4('0x68')]['id'],_0x1a1271[_0x3ff4('0x5a')]?JSON[_0x3ff4('0x27')](_0x1a1271[_0x3ff4('0x5a')]):_0x3ff4('0x6b'));return respondWithRpcPromise(_0x3ff4('0x7b'),_0x3ff4('0x7c'),_0x46ff35);}return null;})[_0x3ff4('0x22')](function(_0x28cf88){var _0x3da318=_0x3ff4('0x6d')+_0x28cf88[_0x3ff4('0x2b')][_0x3ff4('0x6e')];return db['sequelize'][_0x3ff4('0x40')](_0x3da318,{'type':db[_0x3ff4('0x70')]['QueryTypes']['SELECT'],'raw':!![]})[_0x3ff4('0x22')](function(_0x438069){return _0x438069;});})[_0x3ff4('0x22')](function(_0x332bda){if(_0x332bda){_0x46ff35[_0x3ff4('0x2b')][_0x3ff4('0x71')]=_0x332bda[0x0];if(!_0x1a1271[_0x3ff4('0x5a')]['UserId'])return;return db['User'][_0x3ff4('0x58')]({'where':{'id':_0x1a1271[_0x3ff4('0x5a')][_0x3ff4('0x61')],'role':'agent'},'attributes':['id',_0x3ff4('0x39'),'fullname',_0x3ff4('0x7d'),_0x3ff4('0x74')],'raw':!![]});}return null;})[_0x3ff4('0x22')](function(_0x73d9be){if(!_0x73d9be)return null;_0x46ff35[_0x3ff4('0x2b')][_0x3ff4('0x63')]=_0x73d9be;return _0x46ff35;})[_0x3ff4('0x22')](function(_0x2677ee){if(_0x2677ee){_0x2677ee[_0x3ff4('0x2b')][_0x3ff4('0x7e')]=util[_0x3ff4('0x7f')]('SIP/%s',_0x1a1271[_0x3ff4('0x62')][_0x3ff4('0x39')]);_0x2677ee[_0x3ff4('0x2b')][_0x3ff4('0x75')]=_0x46ff35['channel'];_0x2677ee[_0x3ff4('0x2b')][_0x3ff4('0x76')]=_0x46ff35[_0x3ff4('0x75')];_0x2677ee[_0x3ff4('0x2b')][_0x3ff4('0x77')]=_0x3ff4('0x80');respondWithRpcPromise(_0x3ff4('0x78'),_0x3ff4('0x78'),{'event':_0x3ff4('0x81'),'message':_0x2677ee[_0x3ff4('0x2b')]},client9002);return _0x46ff35;}return null;})[_0x3ff4('0x22')](respondWithResult(_0x448f07,null))[_0x3ff4('0x2c')](handleError(_0x448f07,null));};exports['status']=function(_0x52d6a4,_0x46053f,_0x5ab63e){if(_0x52d6a4[_0x3ff4('0x5a')]['id']){delete _0x52d6a4[_0x3ff4('0x5a')]['id'];}var _0x3ce730;return db['WhatsappMessage'][_0x3ff4('0x58')]({'where':{'id':_0x52d6a4[_0x3ff4('0x53')]['id']}})[_0x3ff4('0x22')](handleEntityNotFound(_0x46053f,null))['then'](function(_0x56494c){if(_0x56494c){_0x3ce730=_0x56494c;return db['WhatsappAccount']['find']({'where':{'id':_0x56494c[_0x3ff4('0x82')]}});}})[_0x3ff4('0x22')](handleEntityNotFound(_0x46053f,null))[_0x3ff4('0x22')](function(_0x1abf0e){if(_0x1abf0e){logger['debug']('WhatsppMessage,\x20%s,\x20%s,\x20%s',_0x3ff4('0x2e'),_0x3ff4('0x83'),_0x1abf0e[_0x3ff4('0x3e')],util['inspect'](_0x52d6a4[_0x3ff4('0x5a')],{'showHidden':![],'depth':null}));switch(_0x1abf0e[_0x3ff4('0x3e')]){case _0x3ff4('0x84'):if(_0x52d6a4['body']['MessageSid']&&_0x52d6a4[_0x3ff4('0x5a')][_0x3ff4('0x85')]===_0x3ce730['messageId']&&_0x52d6a4[_0x3ff4('0x5a')][_0x3ff4('0x86')]&&_0x52d6a4[_0x3ff4('0x5a')]['MessageStatus']===_0x3ff4('0x87')){return _0x3ce730[_0x3ff4('0x37')]({'read':!![]});}else{logger[_0x3ff4('0x28')]('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0x3ff4('0x2e'),_0x3ff4('0x84'),util[_0x3ff4('0x88')](_0x52d6a4[_0x3ff4('0x5a')],{'showHidden':![],'depth':null}));}break;}return _0x3ce730;}})['then'](respondWithResult(_0x46053f,null))['catch'](handleError(_0x46053f,null));};