refactor: switch to dedicated group, remove @mention requirement, add pinned message service
- Change ALLOWED_GROUP to Dienst opvragen EdGPT-EBS (120363407613652082@g.us) - Remove isBotMentioned check (no @mention needed) - Match only exact 4-digit messages (regex /^\s*(\d{4})\s*$/) - Add pinnedMessageService.js: auto-repins welcome message when expired - Move incrementDaily() to count all 4-digit messages, not just successful ones - Update daily summary with emoji - Update docs and .env.example
This commit is contained in:
parent
5b83076b33
commit
e4d817ff80
5 changed files with 96 additions and 35 deletions
|
|
@ -2,28 +2,15 @@ const { findDienst, getPngFilePaths } = require('./dienstService')
|
|||
const { sendTextMessage, sendImageMessage, notifyAdmin } = require('./whatsappApi')
|
||||
const { checkLimit, increment, MAX_REQUESTS_PER_DAY } = require('./rateLimiter')
|
||||
const { increment: incrementDaily } = require('./dailyStats')
|
||||
const { checkAndRepinPinnedMessage } = require('./pinnedMessageService')
|
||||
|
||||
const BOT_NAME = (process.env.BOT_NAME || 'EdGpt').toLowerCase()
|
||||
const ALLOWED_GROUP = process.env.ALLOWED_GROUP
|
||||
|
||||
function extractDienstnummer(body) {
|
||||
const match = body.match(/\b(\d{4})\b/)
|
||||
const match = body.match(/^\s*(\d{4})\s*$/)
|
||||
return match ? match[1] : null
|
||||
}
|
||||
|
||||
function isBotMentioned(message) {
|
||||
if (message._data?.mentionedJidList?.length > 0) {
|
||||
return true
|
||||
}
|
||||
if (message.body) {
|
||||
const normalized = message.body.toLowerCase().replace(/\s+/g, '')
|
||||
if (normalized.includes(`@${BOT_NAME.replace(/\s+/g, '')}`)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
async function handleWebhook(payload) {
|
||||
if (payload.dataType !== 'message') return
|
||||
if (payload.sessionId !== process.env.WHATSAPP_SESSION) return
|
||||
|
|
@ -32,11 +19,14 @@ async function handleWebhook(payload) {
|
|||
if (!message) return
|
||||
if (message.fromMe) return
|
||||
if (message.from !== ALLOWED_GROUP) return
|
||||
if (!isBotMentioned(message)) return
|
||||
|
||||
checkAndRepinPinnedMessage()
|
||||
|
||||
const dienstnummer = extractDienstnummer(message.body || '')
|
||||
if (!dienstnummer) return
|
||||
|
||||
incrementDaily()
|
||||
|
||||
console.log(`Processing dienst ${dienstnummer} for ${message.author}`)
|
||||
|
||||
const author = message.author
|
||||
|
|
@ -50,7 +40,6 @@ async function handleWebhook(payload) {
|
|||
}
|
||||
|
||||
increment(author)
|
||||
incrementDaily()
|
||||
|
||||
const dienst = findDienst(dienstnummer)
|
||||
if (!dienst) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue