feat: integrate rate limiter into message handler

This commit is contained in:
Eddy 2026-05-11 20:07:07 +02:00
commit 3d933c96a6

View file

@ -1,5 +1,6 @@
const { findDienst, getPngFilePaths } = require('./dienstService')
const { sendTextMessage, sendImageMessage, notifyAdmin } = require('./whatsappApi')
const { checkLimit, increment, MAX_REQUESTS_PER_DAY } = require('./rateLimiter')
const BOT_NAME = (process.env.BOT_NAME || 'EdGpt').toLowerCase()
const ALLOWED_GROUP = process.env.ALLOWED_GROUP
@ -40,6 +41,15 @@ async function handleWebhook(payload) {
const author = message.author
if (!author) return
const limit = checkLimit(author)
if (!limit.allowed) {
await sendTextMessage(author, `Je hebt vandaag het maximum van ${limit.max} diensten bereikt. Probeer het morgen opnieuw.`)
console.log(`Rate limit reached for ${author} (${limit.count}/${limit.max})`)
return
}
increment(author)
const dienst = findDienst(dienstnummer)
if (!dienst) {
await sendTextMessage(author, `Dienstnummer ${dienstnummer} niet gevonden.`)