Service de notifications (SMS, email, OTP) base sur Node.js, Express, TypeScript, PostgreSQL, RabbitMQ.
Ce service expose des endpoints HTTP et consomme des evenements RabbitMQ pour envoyer des notifications.
Comportement cle actuel:
- OTP generation: telephone only, canal SMS.
- Alertes securite: SMS prioritaire, email secondaire si disponible.
- Les types de notification sont centralises dans
TypeNotification.
- Node.js >= 18
- npm
- PostgreSQL
- RabbitMQ
- Compte Twilio (SMS)
- Compte SMTP/Gmail (email)
cd notification_service
npm install
npm run build
npm run dev- SERVICE_PORT (ex: 8000)
- SERVICE_VERSION (optionnel)
- COMMIT_SHA (optionnel)
- DB_HOST
- DB_PORT (defaut 5432)
- DB_USER
- DB_PASSWORD
- DB_NAME
- RABBITMQ_URL
- RABBITMQ_EXCHANGE
- RABBITMQ_QUEUE
- TWILIO_ACCOUNT_SID
- TWILIO_AUTH_TOKEN
- TWILIO_PHONE_NUMBER
- MAIL_USER
- MAIL_PASS
- HEALTH_CHECK_TIMEOUT_MS (defaut 1000)
- HEALTH_CACHE_TTL_MS (defaut 5000)
- HEALTH_EXPOSE_ERRORS (defaut false)
npm run dev
npm run build
npm starthttp://{host}:{SERVICE_PORT}
- Methode: GET
- Route: /health
Reponse exemple:
{
"status": "OK",
"uptime": 123.45
}- Methode: GET
- Route: /health/ready
Reponse exemple:
{
"status": "OK",
"uptime": 123.45,
"timestamp": "2026-03-24T10:00:00.000Z",
"version": "1.0.0",
"commit": "abc123",
"components": {
"db": { "status": "OK" },
"rabbitmq": { "status": "OK" }
}
}- Methode: POST
- Route: /api/notifications/envoyer
{
"type": "transfer",
"sender": {
"email": "sender@example.com",
"phone": "+22370000001"
},
"receiver": {
"email": "receiver@example.com",
"phone": "+22370000002"
},
"amount": 5000,
"content": "Transfert de 5000 FCFA effectue"
}{
"type": "alert_securite",
"user": {
"phone": "+22370000003",
"email": "client@example.com"
},
"content": "Tentative de connexion suspecte detectee"
}Note: pour les types simples hors transfer et alert_securite, user.email et user.phone sont attendus.
{
"type": "CLIENT_COMPTE_ACTIF",
"user": {
"email": "client@example.com",
"phone": "+22370000004"
},
"content": "Votre compte est desormais actif"
}- Methode: GET
- Route: /api/notifications
Reponse exemple:
[
{
"id": "0f4c...",
"utilisateurId": "user-123",
"typeNotification": "ALERT_SECURITE",
"canal": "SMS",
"message": "Alerte securite...",
"statut": "ENVOYEE",
"dateEnvoi": "2026-03-24T10:00:00.000Z"
}
]- Methode: POST
- Route: /api/notifications/rabbitmq
Request exemple:
{
"routingKey": "notification.process",
"message": {
"utilisateurId": "user-123",
"typeNotification": "ALERT_SECURITE",
"canal": "SMS",
"phone": "+22370000005"
}
}Reponse exemple:
{
"success": true
}- Methode: POST
- Route: /api/notifications/otp/generate
- Regle actuelle: telephone only, SMS only.
Request exemple minimal:
{
"phone": "+22370000006"
}Request exemple avec utilisateurId:
{
"utilisateurId": "pre-user-001",
"phone": "+22370000006"
}Reponse exemple:
{
"success": true,
"message": "OTP envoye",
"expiration": "2026-03-24T10:05:00.000Z"
}- Methode: POST
- Route: /api/notifications/otp/verify
Request exemple:
{
"utilisateurId": "pre-user-001",
"code": "1234"
}Reponse exemple:
{
"success": true,
"message": "OTP valide"
}Message type attendu pour notification inter-service:
{
"utilisateurId": "user-123",
"typeNotification": "ALERT_SECURITE",
"canal": "SMS",
"email": "client@example.com",
"phone": "+22370000007",
"context": {
"reason": "multiple_failed_pin_attempts"
},
"metadata": {
"service": "wallet-service",
"correlationId": "evt-123"
}
}Regle importante:
- Pour
ALERT_SECURITE, le service applique une priorite SMS quand un numero est present, puis envoi email si adresse disponible.
- ADMIN_CREE
- ADMIN_MIS_A_JOUR
- ADMIN_SUPPRIME
- AGENT_INSCRIPTION
- AGENT_EN_ATTENTE_VALIDATION
- AGENT_VALIDE
- AGENT_REJETE
- CLIENT_INSCRIPTION
- CLIENT_COMPTE_ACTIF
- CONNEXION_REUSSIE
- ECHEC_CONNEXION
- DECONNEXION
- NOUVEL_APPAREIL
- CHANGEMENT_MOT_DE_PASSE
- CHANGEMENT_EMAIL
- CHANGEMENT_TELEPHONE
- COMPTE_BLOQUE
- COMPTE_DEBLOQUE
- ALERT_SECURITE
- CONFIRMATION_TRANSFERT
- CONFIRMATION_DEPOT
- CONFIRMATION_RETRAIT
- TRANSFERT_ENVOYE
- TRANSFERT_RECU
- ECHEC_TRANSFERT
- DEPOT_EN_COURS
- DEPOT_REUSSI
- ECHEC_DEPOT
- RETRAIT_EN_COURS
- RETRAIT_REUSSI
- ECHEC_RETRAIT
- OTP_ENVOYE
- OTP_VALIDE
- OTP_EXPIRE
- OTP_INVALIDE
- VERIFICATION_EMAIL
- VERIFICATION_TELEPHONE
- KYC_EN_COURS
- KYC_VALIDE
- KYC_REJETE
- VERIFICATION_KYC
- PAIEMENT_REUSSI
- PAIEMENT_ECHOUE
- FACTURE_GENEREE
- FACTURE_PAYEE
- TENTATIVE_FRAUDE
- TRANSACTION_SUSPECTE
- ACTIVITE_INHABITUELLE
- MAINTENANCE
- MISE_A_JOUR_SYSTEME
- ANNONCE
- En cas d'erreur SMS/email, le statut est marque ECHEC.
- Pour la production, preferer des migrations TypeORM controlees plutot que synchronize.
- Eviter d'exposer les erreurs internes du health endpoint en production.