peelo
v1.2.3
Published
SDK officiel pour l'API WhatsApp Peelo
Readme
Peelo SDK
SDK officiel Node.js pour intégrer l'API WhatsApp Peelo dans vos applications.
Installation
npm install peeloPrérequis
- Node.js >= 14
- Une clé API Peelo (format
pk_...)
Initialisation
const { PeeloClient } = require('peelo');
const client = new PeeloClient('pk_votre_cle_api');Fonctionnalités
- Envoi de messages (Texte, Image, Vidéo, Document, Audio, Localisation, Sticker, Contacts)
- Messages interactifs (Boutons, Listes, Demande de localisation)
- Templates WhatsApp (Marketing, Utility, OTP/Authentification)
- Indicateur de frappe (typing indicator)
- Réactions à des messages
- Marquage des messages comme lus
- Rate Limiting automatique — le SDK gère une file d'attente interne pour ne pas dépasser 10 requêtes/seconde
Utilisation
Envoyer un message texte
await client.sendText('221771234567', 'Bonjour !');
// Avec aperçu de lien
await client.sendText('221771234567', 'Visitez https://peelo.chat', { preview_url: true });Envoyer une image
await client.sendImage('221771234567', 'https://example.com/image.jpg', 'Ma légende');Envoyer une vidéo
await client.sendVideo('221771234567', 'https://example.com/video.mp4', 'Ma légende');Envoyer un document
await client.sendDocument('221771234567', 'https://example.com/facture.pdf', 'facture.pdf', 'Votre facture');Envoyer un audio
await client.sendAudio('221771234567', 'https://example.com/audio.mp3');Envoyer une localisation
await client.sendLocation('221771234567', 14.6928, -17.4467, 'Dakar', 'Sénégal');Envoyer un sticker
// Par URL (webp)
await client.sendSticker('221771234567', 'https://example.com/sticker.webp');
// Par ID
await client.sendSticker('221771234567', 'sticker-id-ici');Envoyer des contacts
await client.sendContacts('221771234567', [
{
name: { first_name: 'Jean', last_name: 'Dupont' },
phones: [{ phone: '+221771234567', type: 'MOBILE' }]
}
]);Réagir à un message
await client.sendReaction('221771234567', 'wamid.HBg...', '❤️');
// Supprimer une réaction
await client.sendReaction('221771234567', 'wamid.HBg...', '');Marquer un message comme lu
await client.markAsRead('wamid.HBg...');Indicateur de frappe
await client.sendTypingIndicator('221771234567', 'wamid.HBg...');Messages Interactifs
Boutons de réponse rapide
Maximum 3 boutons.
await client.sendReplyButtons('221771234567', 'Confirmez-vous votre commande ?', {
'btn_yes': 'Oui, confirmer',
'btn_no': 'Non, annuler'
});Liste de choix (menu)
await client.sendList(
'221771234567',
'Choisissez un produit', // Corps du message
'Voir le menu', // Texte du bouton d'ouverture
[
{
title: 'Nos Pizzas',
rows: [
{ id: 'piz_1', title: 'Marguerite', description: 'Tomate, Mozza' },
{ id: 'piz_2', title: 'Reine', description: 'Tomate, Mozza, Jambon' }
]
},
{
title: 'Nos Boissons',
rows: [
{ id: 'boi_1', title: 'Coca-Cola', description: '33cl' }
]
}
],
'Menu du Restaurant' // Titre (optionnel)
);Demande de localisation
await client.sendLocationRequest('221771234567', 'Veuillez partager votre position pour la livraison.');Message interactif personnalisé
await client.sendInteractive('221771234567', {
type: 'button',
body: { text: 'Choisissez une option' },
action: {
buttons: [
{ type: 'reply', reply: { id: 'opt_1', title: 'Option 1' } }
]
}
});Templates
Template simple
await client.sendTemplate('221771234567', 'hello_world', 'fr');Template Marketing (image + variables)
await client.sendMarketingTemplate(
'221771234567',
'promo_ete', // Nom du template
'fr', // Langue
'https://example.com/promo.jpg', // Image d'en-tête (null si aucune)
['Jean', '-50%'] // Variables : {{1}}=Jean, {{2}}=-50%
);Template Utility (variables seulement)
// Variables positionnelles ({{1}}, {{2}}...)
await client.sendUtilityTemplate('221771234567', 'confirmation_rdv', 'fr', ['Lundi 10h', 'Dr. Martin']);
// Variables nommées
await client.sendUtilityTemplate('221771234567', 'confirmation_rdv', 'fr', {
date: 'Lundi 10h',
medecin: 'Dr. Martin'
});
// Sans variable
await client.sendUtilityTemplate('221771234567', 'simple_notif', 'fr');Template OTP / Authentification
// Bouton ONE_TAP (auto-remplissage)
await client.sendOTP({
to: '221771234567',
templateName: 'auth_otp',
language: 'fr',
otp_code: '483921',
otp_type: 'ONE_TAP' // ou 'COPY_CODE'
});Gestion des erreurs
Toutes les méthodes retournent une Promise. Utilisez try/catch pour gérer les erreurs.
try {
const response = await client.sendText('221771234567', 'Bonjour !');
console.log('Message envoyé, ID :', response.messages[0].id);
} catch (error) {
console.error('Statut HTTP :', error.status);
console.error('Message :', error.message);
}Rate Limiting
Le SDK intègre un rate limiter automatique fixé à 10 requêtes/seconde. Toutes les requêtes sont mises en file d'attente et traitées séquentiellement dans la limite autorisée. Vous n'avez rien à configurer.
Licence
ISC — © Peelo
