fix: remove pinnedMessageService, fix port 3000→3001 in .env.example, annotate specs
This commit is contained in:
parent
9bb5849969
commit
b3178ef3f2
5 changed files with 13 additions and 67 deletions
10
.env.example
10
.env.example
|
|
@ -1,5 +1,13 @@
|
||||||
|
# ┌─────────────────────────────────────────────────────────┐
|
||||||
|
# │ POORT OVERZICHT (nextcloud server) │
|
||||||
|
# │ 3001 = wwebjs-api (Docker container, WhatsApp bridge) │
|
||||||
|
# │ 3002 = dienst-bot (systemd, deze service) │
|
||||||
|
# │ 3004 = telegram-bot (systemd, watchdog) │
|
||||||
|
# │ 3000 = Forgejo (NIET onze service!) │
|
||||||
|
# └─────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
# WhatsApp API Configuration
|
# WhatsApp API Configuration
|
||||||
WHATSAPP_API_ENDPOINT=http://localhost:3000
|
WHATSAPP_API_ENDPOINT=http://localhost:3001
|
||||||
WHATSAPP_SESSION=EdGpt
|
WHATSAPP_SESSION=EdGpt
|
||||||
|
|
||||||
# Webhook Configuration
|
# Webhook Configuration
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
# Dienst Bot - WhatsApp Dienstnummer Bot
|
# Dienst Bot - WhatsApp Dienstnummer Bot
|
||||||
|
|
||||||
|
> **⚠️ Poort-wijziging:** De wwebjs-api is verhuisd van poort 3000 naar **poort 3001** (juni 2026). Alle referenties naar `localhost:3000` in dit document zijn historisch en niet meer actueel. De correcte poort is `3001`. Zie `.env.example` voor de actuele configuratie.
|
||||||
|
|
||||||
## Samenvatting
|
## Samenvatting
|
||||||
|
|
||||||
Een Node.js webhook service die luistert naar berichten in een WhatsApp groep via de wwebjs-api. Wanneer een groepsllid EdGpt noemt (@EdGpt) met een 4-cijferig dienstnummer, zoekt de bot de bijbehorende PNG-afbeeldingen op en stuurt deze privé terug naar de afzender.
|
Een Node.js webhook service die luistert naar berichten in een WhatsApp groep via de wwebjs-api. Wanneer een groepsllid EdGpt noemt (@EdGpt) met een 4-cijferig dienstnummer, zoekt de bot de bijbehorende PNG-afbeeldingen op en stuurt deze privé terug naar de afzender.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
# Telegram Watchdog — Design Document
|
# Telegram Watchdog — Design Document
|
||||||
|
|
||||||
|
> **⚠️ Poort-wijziging:** De telegram-bot is tijdens implementatie verhuisd van poort 3003 naar **poort 3004** (juli 2026). Alle referenties naar `3003` in dit document zijn historisch en niet meer actueel. De correcte poort is `3004`. Zie `.env.example` voor de actuele configuratie.
|
||||||
|
|
||||||
## Doel
|
## Doel
|
||||||
|
|
||||||
Een apart Telegram bot proces dat de admin waarschuwt wanneer de WhatsApp API (wwebjs-api) of de dienst-bot zelf niet bereikbaar is. Dit is het enige communicatiekanaal dat overblijft als WhatsApp uitvalt.
|
Een apart Telegram bot proces dat de admin waarschuwt wanneer de WhatsApp API (wwebjs-api) of de dienst-bot zelf niet bereikbaar is. Dit is het enige communicatiekanaal dat overblijft als WhatsApp uitvalt.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ const { findDienst, getPngFilePaths } = require('./dienstService')
|
||||||
const { sendTextMessage, sendImageMessage, notifyAdmin, sendChatSeen } = require('./whatsappApi')
|
const { sendTextMessage, sendImageMessage, notifyAdmin, sendChatSeen } = require('./whatsappApi')
|
||||||
const { checkLimit, increment, MAX_REQUESTS_PER_DAY } = require('./rateLimiter')
|
const { checkLimit, increment, MAX_REQUESTS_PER_DAY } = require('./rateLimiter')
|
||||||
const { increment: incrementDaily } = require('./dailyStats')
|
const { increment: incrementDaily } = require('./dailyStats')
|
||||||
const { checkAndRepinPinnedMessage } = require('./pinnedMessageService')
|
|
||||||
|
|
||||||
const ALLOWED_GROUP = process.env.ALLOWED_GROUP
|
const ALLOWED_GROUP = process.env.ALLOWED_GROUP
|
||||||
|
|
||||||
|
|
@ -20,8 +19,6 @@ async function handleWebhook(payload) {
|
||||||
if (message.fromMe) return
|
if (message.fromMe) return
|
||||||
if (message.from !== ALLOWED_GROUP) return
|
if (message.from !== ALLOWED_GROUP) return
|
||||||
|
|
||||||
checkAndRepinPinnedMessage()
|
|
||||||
|
|
||||||
const dienstnummer = extractDienstnummer(message.body || '')
|
const dienstnummer = extractDienstnummer(message.body || '')
|
||||||
if (!dienstnummer) return
|
if (!dienstnummer) return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
const axios = require('axios')
|
|
||||||
|
|
||||||
const API_BASE = process.env.WHATSAPP_API_ENDPOINT
|
|
||||||
const SESSION = process.env.WHATSAPP_SESSION
|
|
||||||
const ALLOWED_GROUP = process.env.ALLOWED_GROUP
|
|
||||||
const PIN_DURATION = 30 * 24 * 60 * 60
|
|
||||||
const PINNED_TEXT = 'Welkom in Dienst opvragen EdGpt-EBS. Stuur hier je 4 cijferige dienstnummer en EdGpt zal het prive naar je toe sturen, alleen 4 cijfers meer niet.'
|
|
||||||
|
|
||||||
async function getPinnedMessages() {
|
|
||||||
try {
|
|
||||||
const url = `${API_BASE}/groupChat/runMethod/${SESSION}`
|
|
||||||
const response = await axios.post(url, {
|
|
||||||
chatId: ALLOWED_GROUP,
|
|
||||||
method: 'getPinnedMessages'
|
|
||||||
})
|
|
||||||
return response.data.data || []
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to get pinned messages:', err.message)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function sendPinnedMessage() {
|
|
||||||
const url = `${API_BASE}/client/sendMessage/${SESSION}`
|
|
||||||
const response = await axios.post(url, {
|
|
||||||
chatId: ALLOWED_GROUP,
|
|
||||||
contentType: 'string',
|
|
||||||
content: PINNED_TEXT
|
|
||||||
})
|
|
||||||
return response.data
|
|
||||||
}
|
|
||||||
|
|
||||||
async function pinMessage(messageId) {
|
|
||||||
const url = `${API_BASE}/message/runMethod/${SESSION}`
|
|
||||||
const response = await axios.post(url, {
|
|
||||||
chatId: ALLOWED_GROUP,
|
|
||||||
messageId,
|
|
||||||
method: 'pin',
|
|
||||||
options: PIN_DURATION
|
|
||||||
})
|
|
||||||
return response.data
|
|
||||||
}
|
|
||||||
|
|
||||||
async function checkAndRepinPinnedMessage() {
|
|
||||||
try {
|
|
||||||
const pinned = await getPinnedMessages()
|
|
||||||
if (pinned.length > 0) return
|
|
||||||
|
|
||||||
console.log('No pinned message found, sending and pinning...')
|
|
||||||
const sent = await sendPinnedMessage()
|
|
||||||
const messageId = sent?.message?.id?._serialized
|
|
||||||
if (!messageId) {
|
|
||||||
console.error('Failed to get messageId from sent message')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await pinMessage(messageId)
|
|
||||||
console.log(`Pinned message sent and pinned: ${messageId}`)
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to check/repin pinned message:', err.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { checkAndRepinPinnedMessage }
|
|
||||||
Loading…
Reference in a new issue