Alteraçã para o auto restore funcionar quando o status for PAIRING
parent
a59784d18e
commit
ccada53316
|
@ -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([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ async function searchWhatsappCache(id: string, status: string) {
|
||||||
const response: any = await redis.call('FT.SEARCH', 'idx_whatsapp', `(@status:*${status}*) (@number:*${number_cache.number}*)`, 'SORTBY', 'status', 'ASC')
|
const response: any = await redis.call('FT.SEARCH', 'idx_whatsapp', `(@status:*${status}*) (@number:*${number_cache.number}*)`, 'SORTBY', 'status', 'ASC')
|
||||||
|
|
||||||
|
|
||||||
await redis.quit()
|
await redis.quit()
|
||||||
|
|
||||||
|
|
||||||
if (response.length === 1) {
|
if (response.length === 1) {
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue