Webhooks
Verify incoming webhook payloads from Lystica and handle events in real-time.
Event types
contact.createdTriggered when a new contact is added
contact.updatedTriggered when contact data is modified
email.deliveredTriggered when an email is delivered
email.bouncedTriggered when an email bounces
Verifying signatures
Use the Webhooks class with your signing secret to verify that incoming requests are from Lystica. Pass the raw body, signature header, and timestamp header.
import { Webhooks } from "lystica-cloud";
const webhooks = new Webhooks("whsec_your_signing_secret");
// In your webhook handler (e.g. Express):
app.post("/webhooks/lystica", async (req, res) => {
try {
const event = await webhooks.verify(
req.body, // raw body string
req.headers["x-lystica-signature"], // signature header
req.headers["x-lystica-timestamp"], // timestamp header
);
switch (event.type) {
case "contact.created":
console.log("New contact:", event.data);
break;
case "email.delivered":
console.log("Email delivered:", event.data);
break;
}
res.status(200).send("ok");
} catch (err) {
res.status(400).send("Invalid signature");
}
});