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();
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
console.error(`There whas an error on redis connection: ${e}`);
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@ import { redisConn } from './TicketCache'
|
|||
import Whatsapp from "../models/Whatsapp";
|
||||
import { response } from 'express'
|
||||
|
||||
const deleteWhatsappCache = async (hash:any) => {
|
||||
const deleteWhatsappCache = async (hash: any) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
if (!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
|
@ -39,7 +39,7 @@ const updateWhatsappCache = async (hash: any, json_object: any) => {
|
|||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
if (!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
|
@ -57,18 +57,18 @@ 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();
|
||||
|
||||
if(!redis) return
|
||||
if (!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
const whatsapp_cache: any = await redis.hgetall(hash)
|
||||
|
||||
try {
|
||||
if (whatsapp_cache && Object.keys(whatsapp_cache).length > 0) {
|
||||
if (whatsapp_cache && Object.keys(whatsapp_cache).length > 0) {
|
||||
|
||||
// update_fields.escaped_name = escapeCharCache(update_fields.name)
|
||||
|
||||
|
@ -109,15 +109,15 @@ async function searchWhatsappCache(id: string, status: string) {
|
|||
|
||||
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){
|
||||
redis.quit()
|
||||
if (Object.entries(number_cache).length == 0) {
|
||||
await redis.quit()
|
||||
return []
|
||||
}
|
||||
|
||||
|
@ -126,9 +126,9 @@ async function searchWhatsappCache(id: string, status: string) {
|
|||
// @x:foo @y:bar
|
||||
|
||||
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) {
|
||||
|
@ -153,30 +153,30 @@ async function searchWhatsappCache(id: string, status: string) {
|
|||
return results
|
||||
}
|
||||
|
||||
|
||||
|
||||
const insertOrUpeateWhatsCache = async (hash:any, whatsapp: any) => {
|
||||
|
||||
const insertOrUpeateWhatsCache = async (hash: any, whatsapp: any) => {
|
||||
|
||||
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()
|
||||
|
||||
for (let i = 0; i < whatsapp.length; i++) {
|
||||
|
||||
for (let i = 0; i < whatsapp.length; i++) {
|
||||
|
||||
pipeline.hmset(hash, whatsapp[i]);
|
||||
}
|
||||
|
||||
|
||||
await pipeline.exec(() => { console.log(`${whatsapp.length} WHATSAPP INSERTED IN CACHE!`) });
|
||||
}
|
||||
else{
|
||||
|
||||
await redis.hmset(hash,JSON.parse(JSON.stringify(whatsapp)));
|
||||
else {
|
||||
|
||||
await redis.hmset(hash, JSON.parse(JSON.stringify(whatsapp)));
|
||||
|
||||
console.log(`WHATSAPP ID ${whatsapp.id} INSERTED OR UPADTED IN CACHE!`)
|
||||
|
||||
|
@ -195,11 +195,11 @@ const loadWhatsappCache = async () => {
|
|||
|
||||
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()
|
||||
|
||||
|
@ -222,7 +222,7 @@ const createWhatsappIndexCache = async (hashIndex: string) => {
|
|||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
if (!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
|
@ -235,7 +235,7 @@ const createWhatsappIndexCache = async (hashIndex: string) => {
|
|||
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)
|
||||
|
||||
|
@ -248,8 +248,8 @@ const createWhatsappIndexCache = async (hashIndex: string) => {
|
|||
|
||||
export {
|
||||
loadWhatsappCache,
|
||||
searchWhatsappCache,
|
||||
updateWhatsappCacheById,
|
||||
searchWhatsappCache,
|
||||
updateWhatsappCacheById,
|
||||
insertOrUpeateWhatsCache,
|
||||
deleteWhatsappCache
|
||||
}
|
|
@ -69,6 +69,7 @@ export const StartWhatsAppSession = async (whatsapp: Whatsapp, backupSession: bo
|
|||
let whatsappStatus = ["CONFLICT",
|
||||
"DEPRECATED_VERSION",
|
||||
"OPENING",
|
||||
"PAIRING",
|
||||
"PROXYBLOCK",
|
||||
"SMB_TOS_BLOCK",
|
||||
"TIMEOUT",
|
||||
|
|
Loading…
Reference in New Issue