Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/deepgram-webhooks-events

@0d57af8
Run it yourself

Implement Deepgram callback and webhook handling for async transcription. Use when implementing callback URLs, processing async transcription results, or handling Deepgram event notifications. Trigger: "deepgram callback", "deepgram webhook", "async transcription", "deepgram events", "deepgram notifications", "deepgram async".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/deepgram-webhooks-events

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesimplementation.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Deepgram Webhooks Events - Implementation Details

TypeScript Callback Server (Express)

import express from 'express';
import crypto from 'crypto';

const app = express();
app.use('/webhooks/deepgram', express.raw({ type: 'application/json' }));
app.use(express.json());

interface DeepgramCallback {
  request_id: string;
  metadata: { request_id: string; duration: number; channels: number; models: string[] };
  results: { channels: Array<{ alternatives: Array<{ transcript: string; confidence: number; words: Array<{ word: string; start: number; end: number; confidence: number }> }> }> };
}

function verifyDeepgramSignature(payload: Buffer, signature: string | undefined, secret: string): boolean {
  if (!signature) return false;
  const expectedSignature = crypto.createHmac('sha256', secret).update(payload).digest('hex');
  return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expectedSignature));
}

app.post('/webhooks/deepgram', async (req, res) => {
  const signature = req.headers['x-deepgram-signature'] as string;
  const webhookSecret = process.env.DEEPGRAM_WEBHOOK_SECRET;
  if (webhookSecret && !verifyDeepgramSignature(req.body, signature, webhookSecret)) {
    return res.status(401).json({ error: 'Invalid signature' });
  }
  const callback: DeepgramCallback = JSON.parse(req.body.toString());
  const transcript = callback.results.channels[0]?.alternatives[0]?.transcript;
  await storeTranscription({ requestId: callback.request_id, transcript, metadata: callback.metadata });
  await notifyClient(callback.request_id, { status: 'completed', transcript });
  res.status(200).json({ received: true });
});

Async Transcription Service

import { createClient } from '@deepgram/sdk';
import { v4 as uuidv4 } from 'uuid';

export class AsyncTranscriptionService {
  private client;
  private callbackBaseUrl: string;

  constructor(apiKey: string, callbackBaseUrl: string) {
    this.client = createClient(apiKey);
    this.callbackBaseUrl = callbackBaseUrl;
  }

  async submitTranscription(audioUrl: string, options = {}) {
    const jobId = uuidv4();
    const callbackUrl = `${this.callbackBaseUrl}/webhooks/deepgram?job=${jobId}`;
    const { result, error } = await this.client.listen.prerecorded.transcribeUrl(
      { url: audioUrl },
      { model: 'nova-2', smart_format: true, callback: callbackUrl, ...options }
    );
    if (error) throw new Error(`Submission failed: ${error.message}`);
    await redis.hset(`transcription:${jobId}`, { status: 'processing', requestId: result.request_id, submittedAt: new Date().toISOString() });
    return { jobId, requestId: result.request_id };
  }
}

Callback Retry Handler

export class CallbackRetryHandler {
  private config: { maxRetries: number; baseDelay: number; maxDelay: number };

  async processWithRetry(requestId: string, processor: () => Promise<void>): Promise<void> {
    let attempt = 0;
    while (attempt < this.config.maxRetries) {
      try { await processor(); return; }
      catch (error) {
        attempt++;
        if (attempt >= this.config.maxRetries) throw error;
        const delay = Math.min(this.config.baseDelay * Math.pow(2, attempt - 1), this.config.maxDelay);
        await new Promise(resolve => setTimeout(resolve, delay));
      }
    }
  }
}

Testing Callbacks Locally

# Use ngrok to expose local server
ngrok http 3000

# Test callback endpoint
curl -X POST https://your-ngrok-url.ngrok.io/webhooks/deepgram \
  -H "Content-Type: application/json" \
  -d '{"request_id":"test-123","metadata":{"request_id":"test-123","duration":10.5},"results":{"channels":[{"alternatives":[{"transcript":"This is a test.","confidence":0.95}]}]}}'

Client SDK for Async Transcription

export class AsyncTranscriptionClient {
  private baseUrl: string;
  private pollInterval: number;

  constructor(baseUrl: string, pollInterval = 2000) {
    this.baseUrl = baseUrl;
    this.pollInterval = pollInterval;
  }

  async transcribe(audioUrl: string): Promise<{ transcript: string; confidence: number }> {
    const response = await fetch(`${this.baseUrl}/transcribe/async`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ audioUrl }),
    });
    const { jobId } = await response.json();
    return this.waitForResult(jobId);
  }

  async waitForResult(jobId: string, timeout = 300000) {
    const startTime = Date.now();
    while (Date.now() - startTime < timeout) {
      const response = await fetch(`${this.baseUrl}/transcribe/status/${jobId}`);
      const data = await response.json();
      if (data.status === 'completed') return data.result;
      if (data.status === 'failed') throw new Error('Transcription failed');
      await new Promise(r => setTimeout(r, this.pollInterval));
    }
    throw new Error('Transcription timeout');
  }
}

Tons of Skills by Intent Solutions | jeremylongshore.com

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides an implementation guide for handling Deepgram webhooks and asynchronous transcription, including security best practices like HMAC signature verification and environment variable management. It carries a low risk of indirect prompt injection as it is designed to ingest and process external transcription data.

  • Socket2mo

    1 alert: gptAnomaly

  • Snyk8mo

    Risk: LOW · No issues

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 3 months ago
What it can do
Reads files Edits files Runs commands
version
1.13.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
tags
[
  "saas",
  "deepgram",
  "webhooks",
  "transcription",
  "async"
]
All 4 allowed tools
ReadWriteEditBash(curl:*)
Other metadata
compatibility
Designed for Claude Code

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/deepgram-webhooks-events