SDK mobiles (React Native / Flutter)
Installez les packages mobiles Notif (version 0.2.0) pour envoyer des messages et des codes OTP, planifier des relances, vérifier un statut, lire les logs et suivre votre quota quotidien depuis vos apps internes.
React Native
npm i notifml-react-nativeimport { createNotifClient } from "notifml-react-native";
const notif = createNotifClient({ apiKey: "ntf_live_xxx" });
const result = await notif.send({
to: "+22370000000",
channel: "whatsapp",
message: "Votre commande est prete.",
});
await notif.schedule(
{
to: "+22370000000",
channel: "whatsapp",
message: "Relance client",
},
new Date(Date.now() + 60 * 60 * 1000).toISOString(), // dans une heure
);
// Quota du jour : result.messagesUsed / result.limit (pas de solde de crédits).
await notif.status("ntf_msg_xxx");
// Code OTP
const { challengeId } = await notif.sendOtp({ to: "+22370000000", app: "MonApp" });
const check = await notif.verifyOtp({ challengeId, code: "123456" });
// check.valid === false -> check.code : invalid_code | expired | too_many_attempts | not_foundFlutter
flutter pub add notifml_flutterimport 'package:notifml_flutter/notifml_flutter.dart';
final notif = NotifClient(apiKey: 'ntf_live_xxx');
final result = await notif.send(
const NotifSendRequest(
to: '+22370000000',
channel: 'whatsapp',
message: 'Votre commande est prete.',
),
);
await notif.schedule(
const NotifSendRequest(
to: '+22370000000',
channel: 'whatsapp',
message: 'Relance client',
),
DateTime.now().toUtc().add(const Duration(hours: 1)).toIso8601String(),
);
// Quota du jour : result.messagesUsed / result.limit (pas de solde de crédits).
await notif.status('ntf_msg_xxx');
// Code OTP
final otp = await notif.sendOtp(to: '+22370000000', app: 'MonApp');
final check = await notif.verifyOtp(
challengeId: otp['challengeId'] as String,
code: '123456',
);
notif.close();await notif.send({
to: "client@example.com",
channel: "email",
subject: "Votre recu",
message: "Merci pour votre achat.",
html: "<h1>Merci !</h1><p>Votre commande est confirmee.</p>",
});Routage automatique
await notif.send({
to: "+22370000000",
channel: "auto",
message: "Votre colis est en route !",
fallback: { email: "client@example.com", subject: "Votre colis" },
});Le canal auto essaie WhatsApp, puis le SMS via votre passerelle Android appairée, puis l’e-mail uniquement si fallback.email est renseigné.
Statistiques et journaux
// Agregats (par statut, par canal, aujourd'hui)
const analytics = await notif.analytics({ sample: 200 });
// analytics.analytics.byChannel -> { whatsapp: 120, sms: 30, email: 50 }
// Historique des messages
const logs = await notif.logs({ limit: 50 });
// logs.messages -> [{ to, channel, status, content, _creationTime }, ...]Bonnes pratiques
Ne stockez pas la clé en dur : utilisez expo-secure-store (React Native) ou flutter_secure_storage (Flutter).
Gérez les erreurs 429 (limite de 60 envois par minute, plafond par destinataire ou quota quotidien ; lisez retryAfterSeconds) et les retries avec backoff exponentiel.
Pour les tests : sandbox: true ou clé ntf_test_* (une clé de test ne peut qu’envoyer : status, logs et analytics lui répondent 401).
Voir la documentation API complète pour tous les paramètres et exemples.