Webhook

Webhook

🚀
You have to subscribe to Premium plan or above to use Webhook
 

Introduction

Webhook allows you to send real-time notifications of events within testimonial.to to external services.
 
You can create/manage the webhook on your Settings page. Scroll down and you will find the Webhook section 👇
notion image
A webhook consists of:
  • A URL you have configured, to which a webhook event will be posted
  • One or more events, which will be posted to a specified URL
  • A secret key, which can be used to verify a webhook payload was sent by testimonial.to
 
When a webhook is triggered, a POST request will be made to the URL configured along with a JSON payload specific for the event type.

All events

You can configure a webhook to be sent on the following events:
  • create - when a testimonial is created
  • like - when a testimonial is liked
  • unlike - when a testimonial is unliked
  • delete - when a testimonial is deleted
 

Sample payload

create event

Generated when a video/text testimonial is created
{
  "type": "create",
  "data": {
    "type": "video",
    "id": "b1f8b3e1-c52d-4cf6-a1a7-*********",
    "createdAt": "2022-05-10T18:07:34.000Z",
    "testimonial": {
      "video_url": "https://stream.testimonial.to/*****/medium.mp4",
			"duration": 87.2, // in seconds
      "aspect_ratio": "4:3",
      "img_thumbnail": "https://image.testimonial.to/*****/thumbnail.jpg",
      "gif_thumbnail": "https://image.testimonial.to/*****/animated.gif?width=350",
      "sent_by": {
        "email": "johndoe@gmail.com",
        "name": "John Doe"
      }
    },
    "space": {
      "id": "space-id",
      "url": "https://testimonial.to/products/space-id"
    }
  }
}
 

like event

Generated when a video/text testimonial is liked
{
  "type": "like",
  "data": {
    "type": "video",
    "id": "b1f8b3e1-c52d-4cf6-a1a7-*********",
    "createdAt": "2022-05-10T18:07:34.000Z",
    "testimonial": {
      "video_url": "https://stream.testimonial.to/*****/medium.mp4",
			"duration": 87.2, // in seconds
      "aspect_ratio": "4:3",
      "img_thumbnail": "https://image.testimonial.to/*****/thumbnail.jpg",
      "gif_thumbnail": "https://image.testimonial.to/*****/animated.gif?width=350",
      "sent_by": {
        "email": "johndoe@gmail.com",
        "name": "John Doe"
      }
    },
    "space": {
      "id": "space-id",
      "url": "https://testimonial.to/products/space-id"
    }
  }
}
 

unlike event

Generated when a video/text testimonial is unliked
{
  "type": "unlike",
  "data": {
    "type": "video",
    "id": "5d05a6ef-8123-4341-81d8-**********",
    "space": {
      "id": "space-id",
      "url": "https://testimonial.to/products/space-id"
    }
  }
}
 

delete event

Generated when a video/text testimonial is deleted
{
  "type": "delete",
  "data": {
    "type": "video",
    "id": "b16a3c9c-ef2f-48b7-aa11-**********",
    "space": {
      "id": "space-id",
      "url": "https://testimonial.to/products/space-id"
    }
  }
}
 

Verifying webhook signature

Each webhook event is signed via a Hash-based Message Authentication Code (HMAC) using the webhook’s secret key.
 
The HMAC-SHA1 algorithm is used to generate the webhook payload signature. Each request's signature is passed along in the headers as ‘X-Testimonial-Signature.’
 
notion image
 

Node.js verify example

const WEBHOOK_SECRET = 'webhook secret key';
const crypto = require('crypto');
function verifySignature (body, signature) {
    const digest = crypto
        .createHmac('sha1', WEBHOOK_SECRET)
        .update(JSON.stringify(body)) // Convert body from JSON to string
        .digest('hex');
    return signature === digest;
};
app.post('/webhooks', function (req, res, next) {
    if (!verifySignature(req.body, req.headers['x-testimonial-signature'])) {
        // verification failed
    }
    // verification success
});
Â