feat: add README, .env.example, fix mention detection with spaces, add diensten to .gitignore
This commit is contained in:
parent
0e7272dadd
commit
a9459a16be
4 changed files with 150 additions and 2 deletions
15
.env.example
Normal file
15
.env.example
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
# WhatsApp API Configuration
|
||||||
|
WHATSAPP_API_ENDPOINT=http://localhost:3000
|
||||||
|
WHATSAPP_SESSION=EdGpt
|
||||||
|
|
||||||
|
# Webhook Configuration
|
||||||
|
WEBHOOK_PORT=3002
|
||||||
|
ALLOWED_GROUP=120363407356808413@g.us
|
||||||
|
BOT_NAME=EdGpt
|
||||||
|
|
||||||
|
# Paths
|
||||||
|
DIENSTEN_JSON=./diensten/dienst-tijden.json
|
||||||
|
DIENSTEN_PNG=./diensten/png
|
||||||
|
|
||||||
|
# Admin notifications
|
||||||
|
ADMIN_NUMBER=31612345678@c.us
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
|
.env
|
||||||
diensten/
|
diensten/
|
||||||
|
|
|
||||||
127
README.md
Normal file
127
README.md
Normal file
|
|
@ -0,0 +1,127 @@
|
||||||
|
# Dienst Bot
|
||||||
|
|
||||||
|
WhatsApp bot die dienstschema's (PNG) verstuurt op basis van een dienstnummer in een WhatsApp groep.
|
||||||
|
|
||||||
|
## Hoe het werkt
|
||||||
|
|
||||||
|
1. Iemand tagt **@EdGpt** in de toegestane groep met een 4-cijferig dienstnummer (bijv. `@EdGpt 4002`)
|
||||||
|
2. De bot zoekt het dienstschema op in `dienst-tijden.json`
|
||||||
|
3. De bijbehorende PNG-bestanden worden privé naar de afzender gestuurd
|
||||||
|
|
||||||
|
## Vereisten
|
||||||
|
|
||||||
|
- [Node.js](https://nodejs.org/) 18+
|
||||||
|
- [wwebjs-api](https://github.com/pedroslopez/whatsapp-web.js) Docker container (poort 3000)
|
||||||
|
- WhatsApp sessie "EdGpt" actief in wwebjs-api
|
||||||
|
- PM2 (optioneel, voor procesbeheer)
|
||||||
|
|
||||||
|
## Installatie
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone <repo-url>
|
||||||
|
cd dienst_echo_whatsappgroep
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuratie
|
||||||
|
|
||||||
|
Kopieer `.env.example` naar `.env` en vul de waarden in:
|
||||||
|
|
||||||
|
```env
|
||||||
|
# WhatsApp API
|
||||||
|
WHATSAPP_API_ENDPOINT=http://localhost:3000
|
||||||
|
WHATSAPP_SESSION=EdGpt
|
||||||
|
|
||||||
|
# Webhook
|
||||||
|
WEBHOOK_PORT=3002
|
||||||
|
ALLOWED_GROUP=120363407356808413@g.us
|
||||||
|
BOT_NAME=EdGpt
|
||||||
|
|
||||||
|
# Bestanden
|
||||||
|
DIENSTEN_JSON=./diensten/dienst-tijden.json
|
||||||
|
DIENSTEN_PNG=./diensten/png
|
||||||
|
|
||||||
|
# Admin
|
||||||
|
ADMIN_NUMBER=31620248011@c.us
|
||||||
|
```
|
||||||
|
|
||||||
|
### wwebjs-api webhook config
|
||||||
|
|
||||||
|
In de `.env` van wwebjs-api:
|
||||||
|
|
||||||
|
```env
|
||||||
|
BASE_WEBHOOK_URL=http://host.docker.internal:3002/webhook
|
||||||
|
ENABLE_LOCAL_CALLBACK_EXAMPLE=FALSE
|
||||||
|
ENABLE_WEBHOOK=TRUE
|
||||||
|
```
|
||||||
|
|
||||||
|
Belangrijk: gebruik **`docker compose up -d`** (niet `docker restart`) om `.env` wijzigingen door te voeren.
|
||||||
|
|
||||||
|
## Data
|
||||||
|
|
||||||
|
De map `diensten/` bevat:
|
||||||
|
|
||||||
|
- `dienst-tijden.json` — array met dienstmetadata:
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"dienstnummer": "4002",
|
||||||
|
"startTime": "09:30",
|
||||||
|
"endTime": "10:30",
|
||||||
|
"paginas": [
|
||||||
|
{ "bestandsnaam": "4002-001.png" },
|
||||||
|
{ "bestandsnaam": "4002-002.png" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
- `png/` — PNG bestanden met dienstschema's (bijv. `4002-001.png`)
|
||||||
|
|
||||||
|
Beide zijn uitgesloten van git via `.gitignore`.
|
||||||
|
|
||||||
|
## Gebruik
|
||||||
|
|
||||||
|
### Starten
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
Of met PM2:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx pm2 start src/index.js --name dienst-bot
|
||||||
|
npx pm2 save
|
||||||
|
```
|
||||||
|
|
||||||
|
### Stoppen
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx pm2 stop dienst-bot
|
||||||
|
```
|
||||||
|
|
||||||
|
### Logs bekijken
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx pm2 logs dienst-bot
|
||||||
|
```
|
||||||
|
|
||||||
|
## Projectstructuur
|
||||||
|
|
||||||
|
```
|
||||||
|
src/
|
||||||
|
index.js # Express webhook server
|
||||||
|
messageHandler.js # Berichtverwerking en filtering
|
||||||
|
dienstService.js # JSON lookup en PNG bestandspaden
|
||||||
|
whatsappApi.js # WhatsApp API client (bericht + afbeelding)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Foutafhandeling
|
||||||
|
|
||||||
|
- **Ongeldig dienstnummer**: de bot stuurt een melding terug naar de afzender
|
||||||
|
- **Fout bij verzenden PNG**: de admin krijgt een WhatsApp melding
|
||||||
|
- **Webhook fout**: wordt gelogd in PM2 logs
|
||||||
|
|
||||||
|
## Licentie
|
||||||
|
|
||||||
|
Privé project — niet voor distributie.
|
||||||
|
|
@ -13,8 +13,11 @@ function isBotMentioned(message) {
|
||||||
if (message._data?.mentionedJidList?.length > 0) {
|
if (message._data?.mentionedJidList?.length > 0) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if (message.body && message.body.toLowerCase().includes(`@${BOT_NAME}`)) {
|
if (message.body) {
|
||||||
return true
|
const normalized = message.body.toLowerCase().replace(/\s+/g, '')
|
||||||
|
if (normalized.includes(`@${BOT_NAME.replace(/\s+/g, '')}`)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -32,6 +35,8 @@ async function handleWebhook(payload) {
|
||||||
const dienstnummer = extractDienstnummer(message.body || '')
|
const dienstnummer = extractDienstnummer(message.body || '')
|
||||||
if (!dienstnummer) return
|
if (!dienstnummer) return
|
||||||
|
|
||||||
|
console.log(`Processing dienst ${dienstnummer} for ${message.author}`)
|
||||||
|
|
||||||
const author = message.author
|
const author = message.author
|
||||||
if (!author) return
|
if (!author) return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue