whatapp-go-pvnet/note.txt
2025-05-09 10:14:22 +02:00

94 lines
1.9 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 📘 Documentation Admin Intégration WhatsApp Business API
## 🔐 Configuration de base
### `.env` requis
```env
WHATSAPP_TOKEN=EAA...
WHATSAPP_PHONE_NUMBER_ID=1234567890
WHATSAPP_WEBHOOK_TOKEN=secrettoken
```
### Vérification du webhook (Meta)
- URL : `https://yourdomain/api/whatsapp/webhook`
- Token de vérification : doit correspondre à `WHATSAPP_WEBHOOK_TOKEN`
---
## 📩 Envoi de message
**Route :** `POST /api/message/send`
### Exemple JSON (texte)
```json
{
"to": "33612345678",
"type": "text",
"text": {
"body": "Bonjour 👋"
}
}
```
> Supporte aussi `image`, `video`, `document`, `interactive`, etc.
---
## 📥 Réception de messages / statuts
- Le webhook `POST /api/whatsapp/webhook` :
- enregistre les messages reçus dans la table `conversations`
- décrémente les crédits `CurrentMonthCredits`
- met à jour le `status` d'un message (`delivered`, `read`, etc.)
---
## 🧾 Historique utilisateur
### Interface admin
- URL : `/admin/user/{id}/conversations`
- Permet :
- de visualiser tous les messages avec filtres
- de voir la conversation complète au clic sur une ligne (HTMX)
### API :
`GET /api/user/{id}/conversations`
---
## 💬 Modèle de conversation
```go
type Conversation struct {
UserID uint
From string
To string
MessageID string
Type string
Content string
Direction string // inbound / outbound
Status string // delivered, read, sent...
}
```
---
## 🧮 Crédit consommé par message
| Type | Crédit |
|--------------|--------|
| text | 1 |
| image/video | 2 |
| document | 2 |
| interactive | 1 |
| sticker/audio| 1 |
| reaction | 0 |
---
## ✅ À tester
- [ ] Vérifier réception via webhook
- [ ] Vérifier affichage des conversations admin
- [ ] Vérifier décompte de crédits
- [ ] Tester `GET` de validation webhook avec Meta