Skip to main content

Custom Webhook Integrations

Use AudioSpliter webhooks to build custom integrations with any service that can receive HTTP requests.

Overview​

Any application that can accept incoming HTTP POST requests can integrate with AudioSpliter. Common patterns include:

  • Serverless functions (AWS Lambda, Vercel, Cloudflare Workers)
  • Custom backend services
  • Message queues (SQS, RabbitMQ)
  • Chat platforms (Slack, Discord, Microsoft Teams)

AWS Lambda Example​

// handler.js
const crypto = require('crypto');

exports.handler = async (event) => {
const body = event.body;
const signature = event.headers['x-audiospliter-signature'];

// Verify signature
const expected = crypto
.createHmac('sha256', process.env.WEBHOOK_SECRET)
.update(body)
.digest('hex');

if (signature !== expected) {
return { statusCode: 401, body: 'Invalid signature' };
}

const payload = JSON.parse(body);

if (payload.event === 'job.completed') {
// Process segments - e.g., copy to S3, trigger transcription
for (const segment of payload.data.segments) {
console.log(`Segment ${segment.index}: ${segment.downloadUrl}`);
}
}

return { statusCode: 200, body: JSON.stringify({ received: true }) };
};

Cloudflare Worker Example​

export default {
async fetch(request, env) {
if (request.method !== 'POST') {
return new Response('Method not allowed', { status: 405 });
}

const body = await request.text();
const signature = request.headers.get('x-audiospliter-signature');

// Verify signature
const encoder = new TextEncoder();
const key = await crypto.subtle.importKey(
'raw',
encoder.encode(env.WEBHOOK_SECRET),
{ name: 'HMAC', hash: 'SHA-256' },
false,
['sign']
);
const sig = await crypto.subtle.sign('HMAC', key, encoder.encode(body));
const expected = [...new Uint8Array(sig)]
.map(b => b.toString(16).padStart(2, '0'))
.join('');

if (expected !== signature) {
return new Response('Invalid signature', { status: 401 });
}

const payload = JSON.parse(body);
// Process the event...

return new Response(JSON.stringify({ received: true }), {
headers: { 'Content-Type': 'application/json' },
});
},
};

Discord Bot Notification​

// Send a Discord message when a job completes
async function notifyDiscord(webhookUrl, payload) {
if (payload.event !== 'job.completed') return;

const segments = payload.data.segments;
const message = {
embeds: [{
title: 'Audio Split Complete',
description: `Job \`${payload.jobId}\` produced ${segments.length} segments`,
color: 0x00ff00,
fields: segments.map((s, i) => ({
name: `Segment ${i + 1}`,
value: `Duration: ${s.duration}s | [Download](${s.downloadUrl})`,
})),
}],
};

await fetch(webhookUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(message),
});
}

Tips​

  • Always verify the webhook signature before processing
  • Return a 200 status quickly, then process asynchronously
  • Implement idempotency using the X-AudioSpliter-Delivery header
  • See Signature Verification for full details