What is the webhook center?

The Treble webhook center is where you can configure the URLs of your endpoints to receive real-time notifications about relevant platform events. When an event occurs, Treble sends an HTTP POST request to the URL you configure, including a JSON in the body with the event information. Your server can process this information to execute specific actions such as updating records, sending alerts, or initiating internal processes.

Available event types

Currently, you can subscribe to different types of global events:
  • HSM Status Update: Notifies when an HSM changes state.
  • Session Close Update: Notifies when a conversation session is closed.
  • Deployment Failure: Notifies when an error occurs during a deployment.
Each of these webhooks can be activated or deactivated according to your needs from the configuration panel.

Requirements

  • Your endpoint must respond in less than 5 seconds.
  • The response must be a valid JSON body.
  • It’s recommended to use HTTPS for greater security.

Basic example

Here’s an example in Node.js to handle a Treble webhook:
const express = require('express');
const app = express();
app.use(express.json());

app.post('/webhook', (req, res) => {
  const { event_type } = req.body;

  console.log('Event received:', event_type);

  // Process the event according to its type
  switch (event_type) {
    case 'hsm.status':
      // Logic to handle HSM state changes
      break;
    case 'session.close':
      // Logic to handle session closure
      break;
    case 'deployment.failure':
      // Logic to handle deployment failures
      break;
  }

  res.status(200).json({ success: true });
});

app.listen(3000, () => console.log('Webhook server listening on port 3000'));