feat: 增加获取群名字并缓存

dev/supplier-email-drawer
LiaoYijun 6 months ago
parent b2aa2440b3
commit d418e5c860

@ -7,7 +7,7 @@ const {
makeInMemoryStore,
useMultiFileAuthState,
downloadMediaMessage,
isJidUser
isJidUser, isJidGroup
} = require('@whiskeysockets/baileys');
const fs = require('fs');
const path = require('path');
@ -28,6 +28,8 @@ const createWhatsApp = async phone => {
const whatsAppNo = phone;
// 缓存 msgId-externalId过期时间为 5 分钟
const externalIdCache = new NodeCache({ stdTTL: 60*5 });
// 缓存群信息,过期时间为 5 分钟
const groupSubjectCache = new NodeCache({ stdTTL: 60*60*24 });
const logger = P({ timestamp: () => `,"time":"${new Date().toJSON()}"` }, P.destination('./logs/wa-logs-' + phone + '_' + channelId + '.txt'));
logger.level = 'trace';
const msgRetryCounterCache = new NodeCache();
@ -83,6 +85,13 @@ const createWhatsApp = async phone => {
const messageType = Object.keys(msg.message)[0];
const remoteNo = decodeJid(msg.key.remoteJid);
const externalId = externalIdCache.get(msg.key.id);
const isGroup = isJidGroup(msg.key.remoteJid);
let groupSubject = groupSubjectCache.get(msg.key.remoteJid)
if (isGroup && groupSubject === undefined) {
const groupMetadata = await waSocket.groupMetadata(msg.key.remoteJid);
groupSubject = groupMetadata.subject;
groupSubjectCache.set(msg.key.remoteJid, groupMetadata.subject)
}
if (msg.message?.conversation || msg.message?.extendedTextMessage?.text) {
@ -102,6 +111,7 @@ const createWhatsApp = async phone => {
},
conversation: {
type: isJidUser(msg.key.remoteJid) ? 'individual' : 'group',
name: groupSubject,
},
customerProfile: {
id: decodeJid(msg.key.participant),
@ -126,6 +136,7 @@ const createWhatsApp = async phone => {
},
conversation: {
type: isJidUser(msg.key.remoteJid) ? 'individual' : 'group',
name: groupSubject,
},
customerProfile: {
id: decodeJid(msg.key.participant),

Loading…
Cancel
Save