Notifications Push
Documentation Intégrations Tierces
VUE D'ENSEMBLE
1.1 Objectifs
Les notifications push sont un composant essentiel de l'expérience utilisateur REWAPP. Elles permettent :
- Informer en temps réel des événements importants (transactions, points crédités)
- Engager l'utilisateur avec des offres personnalisées et des rappels
- Améliorer la rétention en maintenant une communication proactive
- Faciliter la navigation via le deep linking vers les écrans pertinents
1.2 Fournisseurs de Services
Plateformes de Notification
| Plateforme | Fournisseur | Protocole | Usage |
|---|---|---|---|
| Android | Firebase Cloud Messaging (FCM) | HTTP v1 / Legacy |
Notifications Android natives |
| iOS | Apple Push Notification Service (APNs) | HTTP/2 |
Notifications iOS natives |
| Multi | Firebase (via FCM) | HTTP v1 |
Gestion unifiée des deux plateformes |
1.3 Principes Directeurs
RÈGLES FONDAMENTALES
- Consentement explicite requis avant l'envoi de notifications (RGPD)
- Notifications opt-in/opt-out par catégorie
- Fréquence maîtrisée pour éviter la fatigue utilisateur
- Personnalisation basée sur les préférences et le comportement
ARCHITECTURE DES NOTIFICATIONS PUSH
2.1 Schéma d'Architecture
L'architecture des notifications push REWAPP est conçue pour être scalable et fiable :
[Backend REWAPP] → [Service Notification] → [Firebase Cloud Messaging] → [Application Mobile]
→ [Apple Push Notification Service] → [Application Mobile]
2.2 Composants du Système
Stack Technique
| Composant | Technologie | Rôle |
|---|---|---|
Notification Service |
Node.js + NestJS | Orchestration des notifications |
Queue de Messages |
Bull Queue (Redis) | File d'attente asynchrone |
Firebase Admin SDK |
firebase-admin | Interface FCM pour Android/iOS |
APNs Provider |
firebase-admin APNs | Communication directe avec APNs via Firebase |
Base de Données |
PostgreSQL | Stockage tokens et préférences |
Cache |
Redis | Cache tokens et rate limiting |
2.3 Flux de Notification
Étape 1 : Déclenchement
Un événement métier déclenche une notification (ex: transaction détectée)
Étape 2 : Mise en Queue
Le message est ajouté à la queue Bull pour traitement asynchrone
Étape 3 : Enrichissement
Le service récupère les tokens et préférences de l'utilisateur
Étape 4 : Envoi
La notification est envoyée via FCM (Android) ou APNs (iOS)
Étape 5 : Confirmation
Le statut de livraison est enregistré et les métriques mises à jour
CONFIGURATION FIREBASE CLOUD MESSAGING (FCM)
3.1 Prérequis
- Compte Firebase avec projet créé
- Application Android et iOS enregistrées dans Firebase
- Fichier de clé de service (service account JSON)
- SDK Firebase configuré dans l'application mobile
3.2 Variables d'Environnement
Configuration Firebase
| Variable | Description | Exemple |
|---|---|---|
FIREBASE_PROJECT_ID |
ID du projet Firebase | rewapp-prod |
FIREBASE_PRIVATE_KEY |
Clé privée du service account | -----BEGIN PRIVATE KEY-----... |
FIREBASE_CLIENT_EMAIL |
Email du service account | firebase-adminsdk@rewapp.iam... |
FIREBASE_DATABASE_URL |
URL de la base Firebase (optionnel) | https://rewapp-prod.firebaseio.com |
3.3 Initialisation du SDK
// notification.service.ts
import * as admin from 'firebase-admin';
const firebaseConfig = {
projectId: process.env.FIREBASE_PROJECT_ID,
privateKey: process.env.FIREBASE_PRIVATE_KEY.replace(/\n/g, '
'),
clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
};
admin.initializeApp({
credential: admin.credential.cert(firebaseConfig),
});
3.4 Configuration Mobile (Angular + Ionic / Capacitor)
Installation des Dépendances
# Installation Capacitor Push Notifications
npm install @capacitor/push-notifications
npx cap sync
# Configuration Firebase pour Angular
npm install @angular/fire firebase
Configuration app.json
{
"appId": "fr.rewapp.app",
"appName": "REWAPP",
"webDir": "www",
"plugins": {
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
}
},
"android": {
"googleServicesFile": "./google-services.json"
},
"ios": {
"googleServicesFile": "./GoogleService-Info.plist"
}
}
CONFIGURATION APPLE PUSH NOTIFICATION SERVICE (APNs)
4.1 Prérequis Apple Developer
- Compte Apple Developer actif
- Certificat APNs ou clé d'authentification (p8)
- Bundle ID de l'application enregistré
- Provisioning profile avec capability Push Notifications
4.2 Types de Clés APNs
Comparaison des Types de Clés
| Type | Extension | Durée de Vie | Recommandation |
|---|---|---|---|
| Certificat | .p12 |
1 an | Non recommandé |
| Clé d'authentification | .p8 |
Illimitée | Recommandé |
4.3 Configuration via Firebase
Firebase gère automatiquement la communication avec APNs. Configuration requise :
-
1
Télécharger la clé APNs
Télécharger la clé APNs (.p8) depuis Apple Developer Portal
-
2
Uploader dans Firebase
Firebase Console > Project Settings > Cloud Messaging
-
3
Renseigner les identifiants
Key ID et Team ID
4.4 Variables d'Environnement APNs (Direct)
Configuration APNs
| Variable | Description | Environnement |
|---|---|---|
APNS_KEY_ID |
ID de la clé APNs | Production/Development |
APNS_TEAM_ID |
Team ID Apple Developer | Production/Development |
APNS_KEY_FILE |
Chemin vers le fichier .p8 | Production/Development |
APNS_BUNDLE_ID |
Bundle ID de l'application | com.rewapp.mobile |
GESTION DES TOKENS DE NOTIFICATION
5.1 Cycle de Vie des Tokens
Événements du Cycle de Vie
| Événement | Action Backend | Action Mobile |
|---|---|---|
| Premier lancement | Créer enregistrement | Demander permission + obtenir token |
| Mise à jour token | Mettre à jour en base | Envoyer nouveau token au backend |
| Désinstallation | Marquer token invalide | - |
| Réinstallation | Créer nouveau token | Obtenir et envoyer nouveau token |
| Révocation permission | Désactiver notifications | Notifier le backend |
5.2 Modèle de Données
device_tokens
Stockage des tokens de notification par appareil| Champ | Type | Description |
|---|---|---|
| id | UUID |
Identifiant unique |
| user_id | UUID |
Référence utilisateur (FK) |
| token | VARCHAR(500) |
Token FCM ou APNs |
| platform | ENUM('ios', 'android') |
Plateforme de l'appareil |
| device_id | VARCHAR(255) |
Identifiant unique appareil |
| is_active | BOOLEAN |
Token actif/inactif |
| last_used_at | TIMESTAMP |
Dernière utilisation |
| created_at | TIMESTAMP |
Date de création |
| updated_at | TIMESTAMP |
Date de mise à jour |
5.3 API Enregistrement de Token
/api/v1/notifications/register-token
Enregistre ou met à jour un token de notification pour un appareil.
Request Body
{
"token": "fcm_token_string",
"platform": "android",
"device_id": "unique_device_identifier"
}
Response200 OK
{
"success": true,
"message": "Token enregistré avec succès",
"data": {
"token_id": "uuid-token-id",
"platform": "android"
}
}
5.4 Nettoyage des Tokens Invalides
Un job planifié (CRON) nettoie les tokens invalides quotidiennement :
- Tokens avec erreurs FCM/APNs répétées (
NotRegistered,InvalidToken) - Tokens non utilisés depuis plus de 90 jours
- Tokens d'appareils désinstallés
TYPES DE NOTIFICATIONS REWAPP
6.1 Catégories de Notifications
Catégories Disponibles
| Catégorie | Code | Opt-out | Priorité | Description |
|---|---|---|---|---|
| Transactionnelles | TRANSACTION |
Non | Haute | Transactions détectées, points crédités |
| Compte | ACCOUNT |
Non | Haute | Sécurité, vérification, alertes compte |
| Promotionnelles | PROMO |
Oui | Normale | Offres, campagnes, nouveaux partenaires |
| Rappels | REMINDER |
Oui | Normale | Points qui expirent, actions en attente |
| Système | SYSTEM |
Non | Haute | Mises à jour importantes, maintenance |
6.2 Notifications Transactionnelles
6.2.1 Transaction Détectée
DÉCLENCHEUR
Détection transaction bancaire chez partenaire • Délai : temps réel (< 30 secondes)
{
"notification": {
"title": "Achat détecté chez Boulangerie Martin 🛒",
"body": "25,00€ • Vous allez recevoir 25 points"
},
"data": {
"type": "TRANSACTION_DETECTED",
"transaction_id": "txn_123456",
"merchant_name": "Boulangerie Martin",
"deep_link": "rewapp://transaction/txn_123456"
}
}
6.2.2 Points Crédités
{
"notification": {
"title": "Points crédités ! 🎉",
"body": "+25 points ajoutés • Total : 450 points"
},
"data": {
"type": "POINTS_CREDITED",
"points_added": "25",
"total_balance": "450",
"deep_link": "rewapp://wallet"
}
}
6.2.3 QR Code Scanné
{
"notification": {
"title": "Paiement réussi chez Café du Centre ✅",
"body": "-50 points utilisés (5,25€)"
},
"data": {
"type": "QR_SCANNED",
"points_used": "50",
"deep_link": "rewapp://history"
}
}
6.3 Notifications Compte & Rappels
API NOTIFICATIONS PUSH
7.1 Endpoints Backend
/api/v1/notifications/register-token
Enregistre un token de notification.
/api/v1/notifications/preferences
Met à jour les préférences de notification.
{
"categories": {
"TRANSACTION": true,
"ACCOUNT": true,
"PROMO": false,
"REMINDER": true,
"SYSTEM": true
},
"quiet_hours": {
"enabled": true,
"start": "22:00",
"end": "08:00"
}
}
/api/v1/notifications/preferences
Récupère les préférences de notification.
/api/v1/notifications/token/{device_id}
Désactive un token de notification.
7.2 Service d'Envoi Interne
interface NotificationPayload {
userId: string;
title: string;
body: string;
data?: Record<string, string>;
category: NotificationCategory;
priority?: 'high' | 'normal';
}
interface BatchNotificationPayload {
userIds: string[];
title: string;
body: string;
category: NotificationCategory;
}
LIMITE FCM
Maximum 500 tokens par requête multicast
DEEP LINKING
8.1 Configuration des Deep Links
Mapping des Deep Links
| Screen | Deep Link | Paramètres |
|---|---|---|
| Accueil | rewapp://home | - |
| Portefeuille | rewapp://wallet | - |
| Transaction | rewapp://transaction/{id} | transaction_id |
| Historique | rewapp://history | - |
| Partenaire | rewapp://partner/{id} | partner_id |
| Profil | rewapp://profile | - |
| Virements | rewapp://withdrawals | - |
8.2 Configuration Mobile
{
"appId": "fr.rewapp.app",
"appName": "REWAPP",
"webDir": "www",
"server": {
"hostname": "rewapp.fr"
},
"plugins": {
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
}
}
}
GESTION DES ERREURS
9.1 Codes d'Erreur FCM
Erreurs Firebase Cloud Messaging
| Code | Signification | Action |
|---|---|---|
messaging/invalid-registration-token |
Token invalide | Supprimer |
messaging/registration-token-not-registered |
Désinstallation | Supprimer |
messaging/message-rate-exceeded |
Rate limit | Backoff |
messaging/server-unavailable |
Serveur FCM down | Retry |
9.2 Codes d'Erreur APNs
Erreurs Apple Push Notification
| Code | Signification | Action |
|---|---|---|
BadDeviceToken | Token invalide | Supprimer |
Unregistered | App désinstallée | Supprimer |
PayloadTooLarge | Payload > 4KB | Réduire |
TooManyRequests | Rate limit | Backoff |
9.3 Stratégie de Retry
{
"maxRetries": 3,
"initialDelayMs": 1000,
"maxDelayMs": 60000,
"backoffMultiplier": 2
}
FORMULE
delay = min(initialDelay × (backoffMultiplier ^ attempt), maxDelay)
MONITORING ET ANALYTICS
10.1 Métriques à Suivre
KPIs des Notifications
| Métrique | Description | Seuil Alerte |
|---|---|---|
| Delivery Rate | Taux de livraison réussie | < 95% |
| Open Rate | Taux d'ouverture | < 10% |
| Click Rate | Taux de clic (deep link) | < 5% |
| Unsubscribe Rate | Taux de désabonnement | > 2% |
| Error Rate | Taux d'erreurs d'envoi | > 5% |
| Latency P95 | Temps d'envoi 95e percentile | > 2s |
10.2 Alertes Configurées
Règles d'Alerte
| Alerte | Condition | Notification |
|---|---|---|
| Taux d'erreur élevé | error_rate > 5% pendant 5 min | Slack #alerts + PagerDuty |
| Latence élevée | p95 > 5s pendant 10 min | Slack #alerts |
| Tokens invalides masse | > 1000 tokens invalides/h | Slack #alerts |
| Service FCM down | 5 erreurs consécutives | PagerDuty |
BONNES PRATIQUES
11.1 Contenu des Notifications
✅ À FAIRE
- Messages courts et percutants (< 100 caractères)
- Personnalisation avec le prénom ou données contextuelles
- Call-to-action clair
- Emojis modérés pour améliorer le taux d'ouverture
- Valeur immédiate pour l'utilisateur
❌ À ÉVITER
- Messages génériques sans valeur ajoutée
- Notifications trop fréquentes (max 3-5/jour)
- Envois nocturnes (respecter les quiet hours)
- Contenus promotionnels excessifs
- Notifications sans action possible
11.2 Timing des Envois
Horaires Optimaux
| Type | Timing Optimal | À Éviter |
|---|---|---|
| Transactionnelles | Temps réel | - |
| Promotionnelles | 10h-12h ou 18h-20h | Avant 9h, après 21h |
| Rappels | 10h-11h | Week-end, jours fériés |
| Nouveaux partenaires | Samedi 10h | Dimanche, lundi matin |
11.3 Segmentation
Segments recommandés pour les notifications promotionnelles :
- Utilisateurs actifs : transaction < 30 jours
- Utilisateurs dormants : pas de transaction > 30 jours
- Utilisateurs premium : palier Gold+
- Nouveaux utilisateurs : inscription < 7 jours
- Utilisateurs géolocalisés : proche d'un partenaire
11.4 Tests A/B
Variables à tester :
Métrique principale : taux d'ouverture et taux de conversion
ANNEXES
12.1 Checklist d'Implémentation
- Créer projet Firebase et configurer FCM
- Générer clé APNs et uploader dans Firebase
- Configurer variables d'environnement backend
- Implémenter service de notification NestJS
- Configurer Bull Queue pour traitement asynchrone
- Créer table device_tokens en base
- Implémenter endpoints API (register, preferences)
- Configurer SDK mobile (Capacitor Push Notifications)
- Implémenter deep linking
- Configurer channels Android
- Tester sur appareils physiques iOS et Android
- Configurer monitoring CloudWatch
12.2 Ressources
12.3 Contacts
Équipe
| Rôle | Contact | Responsabilité |
|---|---|---|
| Tech Lead | tech-lead@rewapp.fr | Architecture et implémentation |
| DevOps | devops@rewapp.fr | Configuration infrastructure |
| Support Firebase | Firebase Console | Problèmes FCM/APNs |