Skip to main content

À quoi servent les webhooks ?

MsgFlash peut envoyer des requêtes HTTP signées à votre application à chaque événement important :
  • instance.connected
  • instance.disconnected
  • message.sent
  • message.delivered
  • message.read
  • message.failed
  • message.received

Gérer vos endpoints via l’API publique

Paramètres

POST /api/v1/webhooks

ChampTypeRequisEmplacementDescription
urlstringouibodyURL HTTPS de réception
eventsstring[]ouibody1 à 50 événements

DELETE /api/v1/webhooks/{id}

ParamètreTypeRequisEmplacementDescription
idUUIDouipathID du webhook

Lister

curl https://srv.msgflash.com/api/v1/webhooks \
  -H "x-api-key: msgf_live_your_api_key_here"

Créer

curl -X POST https://srv.msgflash.com/api/v1/webhooks \
  -H "x-api-key: msgf_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/webhooks/msgflash",
    "events": ["message.delivered", "message.failed", "message.read"]
  }'
Réponse :
{
  "data": {
    "id": "wh_uuid",
    "url": "https://example.com/webhooks/msgflash",
    "events": ["message.delivered", "message.failed", "message.read"],
    "secret": "generated_once_secret",
    "createdAt": "2026-04-01T10:00:00.000Z"
  }
}
Le secret doit être conservé immédiatement. Il sert à vérifier la signature HMAC.

Supprimer

curl -X DELETE https://srv.msgflash.com/api/v1/webhooks/WEBHOOK_ID \
  -H "x-api-key: msgf_live_your_api_key_here"

Erreurs courantes

CodeHTTPQuand
WEBHOOKS_NOT_AVAILABLE_ON_PLAN403Feature non disponible
MAX_WEBHOOK_ENDPOINTS_REACHED403Limite atteinte
NOT_FOUND404Webhook introuvable

Headers envoyés par MsgFlash

HeaderDescription
Content-Type: application/jsonPayload JSON
X-MsgFlash-SignatureSignature sha256=<hex>
X-MsgFlash-EventNom de l’événement

Exemple de payload

{
  "event": "message.delivered",
  "instanceId": "inst_uuid",
  "messageId": "msg_uuid",
  "providerMessageId": "BAE5D1A2B3C4D5E6",
  "to": "+22912345678",
  "status": "delivered",
  "timestamp": "2026-04-01T10:00:05.000Z"
}

Vérifier la signature

Algorithme : HMAC-SHA256(secret, rawBody)
import crypto from 'crypto'
import express from 'express'

const app = express()

app.post('/webhooks/msgflash', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.headers['x-msgflash-signature'] as string
  const secret = process.env.MSGFLASH_WEBHOOK_SECRET!

  const expected = 'sha256=' + crypto
    .createHmac('sha256', secret)
    .update(req.body)
    .digest('hex')

  if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
    return res.status(401).send('Invalid signature')
  }

  res.sendStatus(200)
})

Livraison et retry

  • 5 tentatives
  • backoff exponentiel
  • toute réponse non-2xx déclenche un retry
Répondez 200 rapidement puis traitez en asynchrone.