Alteraçã para o auto restore funcionar quando o status for PAIRING

pull/21/head
adriano 2022-12-26 09:05:35 -03:00
parent a59784d18e
commit ccada53316
3 changed files with 34 additions and 33 deletions

View File

@ -53,7 +53,7 @@ const redisConn = async () => {
return await conn(); return await conn();
} catch (e) { } catch (e) {
console.error(e); console.error(`There whas an error on redis connection: ${e}`);
return Promise.resolve([]); return Promise.resolve([]);
} }

View File

@ -8,11 +8,11 @@ import { redisConn } from './TicketCache'
import Whatsapp from "../models/Whatsapp"; import Whatsapp from "../models/Whatsapp";
import { response } from 'express' import { response } from 'express'
const deleteWhatsappCache = async (hash:any) => { const deleteWhatsappCache = async (hash: any) => {
const redis: any = await redisConn(); const redis: any = await redisConn();
if(!redis) return if (!redis) return
if (redis.status !== 'connect') return if (redis.status !== 'connect') return
@ -39,7 +39,7 @@ const updateWhatsappCache = async (hash: any, json_object: any) => {
const redis: any = await redisConn(); const redis: any = await redisConn();
if(!redis) return if (!redis) return
if (redis.status !== 'connect') return if (redis.status !== 'connect') return
@ -57,11 +57,11 @@ const updateWhatsappCache = async (hash: any, json_object: any) => {
} }
const updateWhatsappCacheById = async (hash:any, update_fields: object | any) => { const updateWhatsappCacheById = async (hash: any, update_fields: object | any) => {
const redis: any = await redisConn(); const redis: any = await redisConn();
if(!redis) return if (!redis) return
if (redis.status !== 'connect') return if (redis.status !== 'connect') return
@ -109,15 +109,15 @@ async function searchWhatsappCache(id: string, status: string) {
const redis: any = await redisConn(); const redis: any = await redisConn();
if(!redis) return if (!redis) return
if (redis.status !== 'connect') return null if (redis.status !== 'connect') return null
const number_cache: any = await redis.hgetall(`whatsapp:${id}`) const number_cache: any = await redis.hgetall(`whatsapp:${id}`)
if(Object.entries(number_cache).length == 0){ if (Object.entries(number_cache).length == 0) {
redis.quit() await redis.quit()
return [] return []
} }
@ -155,15 +155,15 @@ async function searchWhatsappCache(id: string, status: string) {
const insertOrUpeateWhatsCache = async (hash:any, whatsapp: any) => { const insertOrUpeateWhatsCache = async (hash: any, whatsapp: any) => {
const redis: any = await redisConn(); const redis: any = await redisConn();
if(!redis) return if (!redis) return
if (redis.status !== 'connect') return if (redis.status !== 'connect') return
if(Array.isArray(whatsapp)){ if (Array.isArray(whatsapp)) {
const pipeline = redis.pipeline() const pipeline = redis.pipeline()
@ -174,9 +174,9 @@ const insertOrUpeateWhatsCache = async (hash:any, whatsapp: any) => {
await pipeline.exec(() => { console.log(`${whatsapp.length} WHATSAPP INSERTED IN CACHE!`) }); await pipeline.exec(() => { console.log(`${whatsapp.length} WHATSAPP INSERTED IN CACHE!`) });
} }
else{ else {
await redis.hmset(hash,JSON.parse(JSON.stringify(whatsapp))); await redis.hmset(hash, JSON.parse(JSON.stringify(whatsapp)));
console.log(`WHATSAPP ID ${whatsapp.id} INSERTED OR UPADTED IN CACHE!`) console.log(`WHATSAPP ID ${whatsapp.id} INSERTED OR UPADTED IN CACHE!`)
@ -195,11 +195,11 @@ const loadWhatsappCache = async () => {
const redis: any = await redisConn(); const redis: any = await redisConn();
if(!redis) return if (!redis) return
if (redis.status !== 'connect') return if (redis.status !== 'connect') return
let whatsapps:any = await Whatsapp.findAll({raw: true}) let whatsapps: any = await Whatsapp.findAll({ raw: true })
const pipeline = redis.pipeline() const pipeline = redis.pipeline()
@ -222,7 +222,7 @@ const createWhatsappIndexCache = async (hashIndex: string) => {
const redis: any = await redisConn(); const redis: any = await redisConn();
if(!redis) return if (!redis) return
if (redis.status !== 'connect') return if (redis.status !== 'connect') return
@ -235,7 +235,7 @@ const createWhatsappIndexCache = async (hashIndex: string) => {
await redis.call('FT.DROPINDEX', hashIndex) await redis.call('FT.DROPINDEX', hashIndex)
} }
const response = await redis.call('FT.CREATE', hashIndex, 'ON', 'HASH', 'PREFIX', '1', 'whatsapp:', 'SCHEMA','id', 'NUMERIC', 'status', 'TEXT', 'SORTABLE', 'number', 'TEXT', 'SORTABLE') const response = await redis.call('FT.CREATE', hashIndex, 'ON', 'HASH', 'PREFIX', '1', 'whatsapp:', 'SCHEMA', 'id', 'NUMERIC', 'status', 'TEXT', 'SORTABLE', 'number', 'TEXT', 'SORTABLE')
console.log('Whatsapp index created: ', response) console.log('Whatsapp index created: ', response)

View File

@ -69,6 +69,7 @@ export const StartWhatsAppSession = async (whatsapp: Whatsapp, backupSession: bo
let whatsappStatus = ["CONFLICT", let whatsappStatus = ["CONFLICT",
"DEPRECATED_VERSION", "DEPRECATED_VERSION",
"OPENING", "OPENING",
"PAIRING",
"PROXYBLOCK", "PROXYBLOCK",
"SMB_TOS_BLOCK", "SMB_TOS_BLOCK",
"TIMEOUT", "TIMEOUT",