Implementação de cache para whatsapp
parent
d86a7efe12
commit
bc406cb1d0
|
@ -69,8 +69,6 @@ const updateContactCacheById = async (id: string | number, update_fields: object
|
||||||
try {
|
try {
|
||||||
if (contact_cache && Object.keys(contact_cache).length > 0) {
|
if (contact_cache && Object.keys(contact_cache).length > 0) {
|
||||||
|
|
||||||
// await redis.del(`contact:${id}`)
|
|
||||||
|
|
||||||
update_fields.escaped_name = escapeCharCache(update_fields.name)
|
update_fields.escaped_name = escapeCharCache(update_fields.name)
|
||||||
|
|
||||||
await updateContactCache(`contact:${id}`, update_fields)
|
await updateContactCache(`contact:${id}`, update_fields)
|
||||||
|
|
|
@ -0,0 +1,240 @@
|
||||||
|
|
||||||
|
import Redis from 'ioredis'
|
||||||
|
import { type } from 'os'
|
||||||
|
const unflatten = require('flat').unflatten
|
||||||
|
var flatten = require('flat')
|
||||||
|
import ListWhatsAppsNumber from "../services/WhatsappService/ListWhatsAppsNumber"
|
||||||
|
import { redisConn } from './TicketCache'
|
||||||
|
import Whatsapp from "../models/Whatsapp";
|
||||||
|
|
||||||
|
const deleteWhatsappCache = async (hash:any) => {
|
||||||
|
|
||||||
|
const redis: any = await redisConn();
|
||||||
|
|
||||||
|
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) {
|
||||||
|
|
||||||
|
await redis.del(hash)
|
||||||
|
|
||||||
|
console.log(`Whatsapp cache number ${whatsapp_cache['number']} deleted!`)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('WHATSAPP CACHE NOT FOUND!')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`There was an error on deleteWhatsappCache: ${error}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
redis.quit()
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateWhatsappCache = async (hash: any, json_object: any) => {
|
||||||
|
|
||||||
|
const redis: any = await redisConn();
|
||||||
|
|
||||||
|
if(!redis) return
|
||||||
|
|
||||||
|
if (redis.status !== 'connect') return
|
||||||
|
|
||||||
|
const pipeline = redis.pipeline()
|
||||||
|
|
||||||
|
let entries = Object.entries(json_object)
|
||||||
|
|
||||||
|
entries.forEach((e: any) => {
|
||||||
|
pipeline.hset(hash, e[0], e[1])
|
||||||
|
})
|
||||||
|
|
||||||
|
await pipeline.exec(() => { console.log("whatsapp Key/value inserted/updated") });
|
||||||
|
|
||||||
|
redis.quit()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateWhatsappCacheById = async (hash:any, update_fields: object | any) => {
|
||||||
|
|
||||||
|
const redis: any = await redisConn();
|
||||||
|
|
||||||
|
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) {
|
||||||
|
|
||||||
|
// update_fields.escaped_name = escapeCharCache(update_fields.name)
|
||||||
|
|
||||||
|
await updateWhatsappCache(hash, update_fields)
|
||||||
|
|
||||||
|
console.log(`WHATSAPP ${whatsapp_cache['number']} CACHE WAS UPDATED!`)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('WHATSAPP CACHE NOT FOUND!')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`There was an error on updateWhatsappCacheById: ${error}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
redis.quit()
|
||||||
|
}
|
||||||
|
|
||||||
|
// const createOrUpdateContactCache = async (hash: any, contact: any) => {
|
||||||
|
|
||||||
|
// const redis: any = await redisConn();
|
||||||
|
|
||||||
|
// if(!redis) return
|
||||||
|
|
||||||
|
// if (redis.status !== 'connect') return
|
||||||
|
|
||||||
|
// if (contact.name) {
|
||||||
|
// contact.escaped_name = escapeCharCache(contact.name)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// await redis.hmset(hash, contact);
|
||||||
|
|
||||||
|
// redis.quit()
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
async function searchWhatsappCache(search: string) {
|
||||||
|
|
||||||
|
const redis: any = await redisConn();
|
||||||
|
|
||||||
|
if(!redis) return
|
||||||
|
|
||||||
|
if (redis.status !== 'connect') return null
|
||||||
|
|
||||||
|
const response: any = await redis.call('FT.SEARCH', 'idx_whatsapp', `(@status:*${search}*)|(@number:*${search}*)`, 'SORTBY', 'status', 'ASC')
|
||||||
|
redis.quit()
|
||||||
|
|
||||||
|
|
||||||
|
if (response.length === 1) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const results: any = []
|
||||||
|
|
||||||
|
for (let n = 2; n < response.length; n += 2) {
|
||||||
|
const result: any = {}
|
||||||
|
const fieldNamesAndValues = response[n]
|
||||||
|
|
||||||
|
for (let m = 0; m < fieldNamesAndValues.length; m += 2) {
|
||||||
|
const k = fieldNamesAndValues[m]
|
||||||
|
const v = fieldNamesAndValues[m + 1]
|
||||||
|
result[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
results.push(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const insertOrUpeateWhatsCache = async (hash:any, whatsapp: any) => {
|
||||||
|
|
||||||
|
const redis: any = await redisConn();
|
||||||
|
|
||||||
|
if(!redis) return
|
||||||
|
|
||||||
|
if (redis.status !== 'connect') return
|
||||||
|
|
||||||
|
if(Array.isArray(whatsapp)){
|
||||||
|
|
||||||
|
const pipeline = redis.pipeline()
|
||||||
|
|
||||||
|
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)));
|
||||||
|
|
||||||
|
console.log(`${whatsapp.length} WHATSAPP INSERTED OR UPADTED IN CACHE!`)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
redis.quit()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const loadWhatsappCache = async () => {
|
||||||
|
|
||||||
|
await createWhatsappIndexCache('idx_whatsapp')
|
||||||
|
|
||||||
|
const redis: any = await redisConn();
|
||||||
|
|
||||||
|
if(!redis) return
|
||||||
|
|
||||||
|
if (redis.status !== 'connect') return
|
||||||
|
|
||||||
|
let whatsapps:any = await Whatsapp.findAll({raw: true})
|
||||||
|
|
||||||
|
const pipeline = redis.pipeline()
|
||||||
|
|
||||||
|
for (let i = 0; i < whatsapps.length; i++) {
|
||||||
|
|
||||||
|
whatsapps[i].createdAt = new Date(whatsapps[i].createdAt).toISOString()
|
||||||
|
whatsapps[i].updatedAt = new Date(whatsapps[i].updatedAt).toISOString()
|
||||||
|
|
||||||
|
// whatsapps[i].escaped_name = escapeCharCache(whatsapps[i].name)
|
||||||
|
|
||||||
|
pipeline.hmset(`whatsapp:${whatsapps[i].id}`, whatsapps[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
await pipeline.exec(() => { console.log(`${whatsapps.length} WHATSAPPS INSERTED IN CACHE!`) });
|
||||||
|
|
||||||
|
redis.quit()
|
||||||
|
}
|
||||||
|
|
||||||
|
const createWhatsappIndexCache = async (hashIndex: string) => {
|
||||||
|
|
||||||
|
const redis: any = await redisConn();
|
||||||
|
|
||||||
|
if(!redis) return
|
||||||
|
|
||||||
|
if (redis.status !== 'connect') return
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const lst_index_redis: any = await redis.call('FT._LIST')
|
||||||
|
|
||||||
|
if (lst_index_redis.includes(hashIndex)) {
|
||||||
|
console.log('entrou...')
|
||||||
|
await redis.call('FT.DROPINDEX', hashIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await redis.call('FT.CREATE', hashIndex, 'ON', 'HASH', 'PREFIX', '1', 'whatsapp:', 'SCHEMA', 'status', 'TEXT', 'SORTABLE', 'number', 'TEXT', 'SORTABLE')
|
||||||
|
|
||||||
|
console.log('Whatsapp index created: ', response)
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log('There was an error on createWhatsappIndexCache: ', error)
|
||||||
|
}
|
||||||
|
|
||||||
|
redis.quit()
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
loadWhatsappCache,
|
||||||
|
searchWhatsappCache,
|
||||||
|
updateWhatsappCacheById,
|
||||||
|
insertOrUpeateWhatsCache,
|
||||||
|
deleteWhatsappCache
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ const sessions: Session[] = [];
|
||||||
|
|
||||||
let backupSession: any[] = []
|
let backupSession: any[] = []
|
||||||
|
|
||||||
|
import { insertOrUpeateWhatsCache } from "../helpers/WhatsCache";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,6 +88,7 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
|
||||||
logger.info("Session:", sessionName);
|
logger.info("Session:", sessionName);
|
||||||
qrCode.generate(qr, { small: true });
|
qrCode.generate(qr, { small: true });
|
||||||
await whatsapp.update({ qrcode: qr, status: "qrcode", retries: 0 });
|
await whatsapp.update({ qrcode: qr, status: "qrcode", retries: 0 });
|
||||||
|
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, { qrcode: qr, status: "qrcode", retries: 0 })
|
||||||
|
|
||||||
const sessionIndex = sessions.findIndex(s => s.id === whatsapp.id);
|
const sessionIndex = sessions.findIndex(s => s.id === whatsapp.id);
|
||||||
if (sessionIndex === -1) {
|
if (sessionIndex === -1) {
|
||||||
|
@ -112,6 +114,7 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
|
||||||
|
|
||||||
if (whatsapp.retries > 1) {
|
if (whatsapp.retries > 1) {
|
||||||
await whatsapp.update({ session: "", retries: 0 });
|
await whatsapp.update({ session: "", retries: 0 });
|
||||||
|
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, { session: "", retries: 0 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const retry = whatsapp.retries;
|
const retry = whatsapp.retries;
|
||||||
|
@ -119,6 +122,10 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
|
||||||
status: "DISCONNECTED",
|
status: "DISCONNECTED",
|
||||||
retries: retry + 1
|
retries: retry + 1
|
||||||
});
|
});
|
||||||
|
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, {
|
||||||
|
status: "DISCONNECTED",
|
||||||
|
retries: retry + 1
|
||||||
|
})
|
||||||
|
|
||||||
io.emit("whatsappSession", {
|
io.emit("whatsappSession", {
|
||||||
action: "update",
|
action: "update",
|
||||||
|
@ -133,12 +140,14 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
|
||||||
|
|
||||||
console.log('>>>>>>>>>>>>>> ready wbot.ts MOBILE NUMBER: ', wbot.info["wid"]["user"])
|
console.log('>>>>>>>>>>>>>> ready wbot.ts MOBILE NUMBER: ', wbot.info["wid"]["user"])
|
||||||
|
|
||||||
|
|
||||||
await whatsapp.update({
|
await whatsapp.update({
|
||||||
status: "CONNECTED",
|
status: "CONNECTED",
|
||||||
qrcode: "",
|
qrcode: "",
|
||||||
retries: 0,
|
retries: 0,
|
||||||
number: wbot.info["wid"]["user"]
|
number: wbot.info["wid"]["user"]
|
||||||
});
|
});
|
||||||
|
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`,whatsapp)
|
||||||
|
|
||||||
io.emit("whatsappSession", {
|
io.emit("whatsappSession", {
|
||||||
action: "update",
|
action: "update",
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { startWhoIsOnlineMonitor } from "./helpers/WhoIsOnlineMonitor"
|
||||||
|
|
||||||
import { loadTicketsCache, flushCache, cacheSize } from './helpers/TicketCache'
|
import { loadTicketsCache, flushCache, cacheSize } from './helpers/TicketCache'
|
||||||
import { loadContactsCache } from './helpers/ContactsCache'
|
import { loadContactsCache } from './helpers/ContactsCache'
|
||||||
|
import { loadWhatsappCache } from './helpers/WhatsCache'
|
||||||
|
|
||||||
const server = app.listen(process.env.PORT, () => {
|
const server = app.listen(process.env.PORT, () => {
|
||||||
logger.info(`Server started on port: ${process.env.PORT}`);
|
logger.info(`Server started on port: ${process.env.PORT}`);
|
||||||
|
@ -29,6 +30,7 @@ gracefulShutdown(server);
|
||||||
await flushCache()
|
await flushCache()
|
||||||
await loadContactsCache()
|
await loadContactsCache()
|
||||||
await loadTicketsCache()
|
await loadTicketsCache()
|
||||||
|
await loadWhatsappCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
})()
|
})()
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { json } from "sequelize/types";
|
||||||
|
|
||||||
import sendMessageMultiSession from "../../helpers/TrySendMessageMultiSession";
|
import sendMessageMultiSession from "../../helpers/TrySendMessageMultiSession";
|
||||||
import { restartWhatsSession } from "../../helpers/RestartWhatsSession";
|
import { restartWhatsSession } from "../../helpers/RestartWhatsSession";
|
||||||
|
import { insertOrUpeateWhatsCache, searchWhatsappCache } from "../../helpers/WhatsCache";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,6 +35,13 @@ const SendWhatsAppMessage = async ({
|
||||||
ticket,
|
ticket,
|
||||||
quotedMsg
|
quotedMsg
|
||||||
}: Request): Promise<WbotMessage> => {
|
}: Request): Promise<WbotMessage> => {
|
||||||
|
|
||||||
|
var timetaken = "Time taken to send message";
|
||||||
|
|
||||||
|
|
||||||
|
console.time(timetaken)
|
||||||
|
|
||||||
|
|
||||||
let quotedMsgSerializedId: string | undefined;
|
let quotedMsgSerializedId: string | undefined;
|
||||||
if (quotedMsg) {
|
if (quotedMsg) {
|
||||||
await GetWbotMessage(ticket, quotedMsg.id);
|
await GetWbotMessage(ticket, quotedMsg.id);
|
||||||
|
@ -42,14 +50,10 @@ const SendWhatsAppMessage = async ({
|
||||||
|
|
||||||
//TEST DEL
|
//TEST DEL
|
||||||
|
|
||||||
// const whatsapp = await ShowWhatsAppService(33);
|
let whats_number = await searchWhatsappCache(`${ticket.whatsappId}`)
|
||||||
|
console.log('---')
|
||||||
// const wbot2 = getWbot(whatsapp.id);
|
console.log('whats_number search: ', whats_number)
|
||||||
|
console.log('---')
|
||||||
// await wbot2.logout();
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
let whatsapps: any
|
let whatsapps: any
|
||||||
|
|
||||||
|
@ -104,12 +108,16 @@ const SendWhatsAppMessage = async ({
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.time
|
||||||
|
|
||||||
const sentMessage = await wbot.sendMessage(`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`, body, { quotedMessageId: quotedMsgSerializedId, linkPreview: false });
|
const sentMessage = await wbot.sendMessage(`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`, body, { quotedMessageId: quotedMsgSerializedId, linkPreview: false });
|
||||||
|
|
||||||
await ticket.update({ lastMessage: body });
|
await ticket.update({ lastMessage: body });
|
||||||
|
|
||||||
await updateTicketCacheByTicketId(ticket.id, { lastMessage: body, updatedAt: new Date(ticket.updatedAt).toISOString() })
|
await updateTicketCacheByTicketId(ticket.id, { lastMessage: body, updatedAt: new Date(ticket.updatedAt).toISOString() })
|
||||||
|
|
||||||
|
console.timeEnd(timetaken)
|
||||||
|
|
||||||
return sentMessage;
|
return sentMessage;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
||||||
|
@ -122,6 +130,11 @@ const SendWhatsAppMessage = async ({
|
||||||
await whatsapp.update({
|
await whatsapp.update({
|
||||||
status: "RESTORING",
|
status: "RESTORING",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, {
|
||||||
|
status: "RESTORING",
|
||||||
|
})
|
||||||
|
|
||||||
setTimeout(() => restartWhatsSession(whatsapp, true), 90000);
|
setTimeout(() => restartWhatsSession(whatsapp, true), 90000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,15 @@ import { wbotMessageListener } from "./wbotMessageListener";
|
||||||
import { getIO } from "../../libs/socket";
|
import { getIO } from "../../libs/socket";
|
||||||
import wbotMonitor from "./wbotMonitor";
|
import wbotMonitor from "./wbotMonitor";
|
||||||
import { logger } from "../../utils/logger";
|
import { logger } from "../../utils/logger";
|
||||||
|
import { insertOrUpeateWhatsCache } from "../../helpers/WhatsCache";
|
||||||
|
|
||||||
export const StartWhatsAppSession = async (whatsapp: Whatsapp, backupSession: boolean = false): Promise<void> => {
|
export const StartWhatsAppSession = async (whatsapp: Whatsapp, backupSession: boolean = false): Promise<void> => {
|
||||||
await whatsapp.update({ status: "OPENING" });
|
await whatsapp.update({ status: "OPENING" });
|
||||||
|
|
||||||
|
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, {
|
||||||
|
status: "OPENING",
|
||||||
|
})
|
||||||
|
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
io.emit("whatsappSession", {
|
io.emit("whatsappSession", {
|
||||||
action: "update",
|
action: "update",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as Sentry from "@sentry/node";
|
import * as Sentry from "@sentry/node";
|
||||||
import { Client } from "whatsapp-web.js";
|
import { Client } from "whatsapp-web.js";
|
||||||
|
import { insertOrUpeateWhatsCache } from "../../helpers/WhatsCache";
|
||||||
|
|
||||||
import { getIO } from "../../libs/socket";
|
import { getIO } from "../../libs/socket";
|
||||||
import Whatsapp from "../../models/Whatsapp";
|
import Whatsapp from "../../models/Whatsapp";
|
||||||
|
@ -25,6 +26,7 @@ const wbotMonitor = async (
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await whatsapp.update({ status: newState });
|
await whatsapp.update({ status: newState });
|
||||||
|
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, { status: newState })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Sentry.captureException(err);
|
Sentry.captureException(err);
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
|
@ -59,6 +61,7 @@ const wbotMonitor = async (
|
||||||
logger.info(`Disconnected session: ${sessionName}, reason: ${reason}`);
|
logger.info(`Disconnected session: ${sessionName}, reason: ${reason}`);
|
||||||
try {
|
try {
|
||||||
await whatsapp.update({ status: "OPENING", session: "" });
|
await whatsapp.update({ status: "OPENING", session: "" });
|
||||||
|
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, { status: "OPENING", session: "" })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Sentry.captureException(err);
|
Sentry.captureException(err);
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
|
|
|
@ -62,6 +62,7 @@ const CreateWhatsAppService = async ({
|
||||||
});
|
});
|
||||||
if (oldDefaultWhatsapp) {
|
if (oldDefaultWhatsapp) {
|
||||||
await oldDefaultWhatsapp.update({ isDefault: false });
|
await oldDefaultWhatsapp.update({ isDefault: false });
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ const ListWhatsAppsNumber = async (whatsappId: string | number, status: string):
|
||||||
const whatsapps = await Whatsapp.findAll({
|
const whatsapps = await Whatsapp.findAll({
|
||||||
raw: true,
|
raw: true,
|
||||||
where: { number: whatsapp.number, status: status },
|
where: { number: whatsapp.number, status: status },
|
||||||
attributes:['id', 'number']
|
attributes: ['id', 'number', 'status', 'isDefault']
|
||||||
});
|
});
|
||||||
|
|
||||||
return whatsapps;
|
return whatsapps;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import AppError from "../../errors/AppError";
|
||||||
import Whatsapp from "../../models/Whatsapp";
|
import Whatsapp from "../../models/Whatsapp";
|
||||||
import ShowWhatsAppService from "./ShowWhatsAppService";
|
import ShowWhatsAppService from "./ShowWhatsAppService";
|
||||||
import AssociateWhatsappQueue from "./AssociateWhatsappQueue";
|
import AssociateWhatsappQueue from "./AssociateWhatsappQueue";
|
||||||
|
import { insertOrUpeateWhatsCache } from "../../helpers/WhatsCache";
|
||||||
|
|
||||||
interface WhatsappData {
|
interface WhatsappData {
|
||||||
name?: string;
|
name?: string;
|
||||||
|
@ -78,6 +79,15 @@ const UpdateWhatsAppService = async ({
|
||||||
isDefault
|
isDefault
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await insertOrUpeateWhatsCache(`whatsapp:${whatsapp.id}`, {
|
||||||
|
name,
|
||||||
|
status,
|
||||||
|
session,
|
||||||
|
greetingMessage,
|
||||||
|
farewellMessage,
|
||||||
|
isDefault
|
||||||
|
})
|
||||||
|
|
||||||
await AssociateWhatsappQueue(whatsapp, queueIds);
|
await AssociateWhatsappQueue(whatsapp, queueIds);
|
||||||
|
|
||||||
return { whatsapp, oldDefaultWhatsapp };
|
return { whatsapp, oldDefaultWhatsapp };
|
||||||
|
|
Loading…
Reference in New Issue