deepgram-webhooks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeepgram Webhooks
Deepgram Webhooks
When to Use This Skill
何时使用该Skill
- Setting up Deepgram callback handlers for transcription results
- Processing asynchronous transcription results from Deepgram
- Implementing webhook authentication for Deepgram callbacks
- Handling transcription completion events
- 为转录结果设置Deepgram回调处理器
- 处理来自Deepgram的异步转录结果
- 为Deepgram回调实现webhook身份验证
- 处理转录完成事件
Essential Code
核心代码
Deepgram webhooks (callbacks) are used to receive transcription results asynchronously. When you provide a callback URL in your transcription request, Deepgram immediately responds with a and sends the transcription results to your callback URL when processing is complete.
request_idDeepgram webhook(回调)用于异步接收转录结果。当你在转录请求中提供回调URL时,Deepgram会立即返回一个,并在处理完成后将转录结果发送到你的回调URL。
request_idBasic Webhook Handler
基础Webhook处理器
javascript
// Express.js example
app.post('/webhooks/deepgram', express.raw({ type: 'application/json' }), (req, res) => {
// Verify webhook authenticity using dg-token header
const dgToken = req.headers['dg-token'];
if (!dgToken) {
return res.status(401).send('Missing dg-token header');
}
// Verify the token matches your expected API Key Identifier
// The dg-token contains the API Key Identifier used in the original request
if (dgToken !== process.env.DEEPGRAM_API_KEY_ID) {
return res.status(403).send('Invalid dg-token');
}
// Parse the transcription result
const transcriptionResult = JSON.parse(req.body.toString());
// Process the transcription
console.log('Received transcription:', transcriptionResult);
// Return success to prevent retries
res.status(200).send('OK');
});javascript
// Express.js example
app.post('/webhooks/deepgram', express.raw({ type: 'application/json' }), (req, res) => {
// Verify webhook authenticity using dg-token header
const dgToken = req.headers['dg-token'];
if (!dgToken) {
return res.status(401).send('Missing dg-token header');
}
// Verify the token matches your expected API Key Identifier
// The dg-token contains the API Key Identifier used in the original request
if (dgToken !== process.env.DEEPGRAM_API_KEY_ID) {
return res.status(403).send('Invalid dg-token');
}
// Parse the transcription result
const transcriptionResult = JSON.parse(req.body.toString());
// Process the transcription
console.log('Received transcription:', transcriptionResult);
// Return success to prevent retries
res.status(200).send('OK');
});Authentication Methods
身份验证方式
Deepgram supports two authentication methods for webhooks:
- dg-token Header: Automatically included, contains the API Key Identifier
- Basic Auth: Embed credentials in the callback URL
javascript
// Using dg-token header (recommended)
const verifyDgToken = (req, res, next) => {
const dgToken = req.headers['dg-token'];
if (!dgToken || dgToken !== process.env.DEEPGRAM_API_KEY_ID) {
return res.status(403).send('Invalid authentication');
}
next();
};
// Basic Auth in callback URL
// https://username:password@your-domain.com/webhooks/deepgramDeepgram为webhook支持两种身份验证方式:
- dg-token Header: 自动包含,包含API密钥标识符
- Basic Auth: 在回调URL中嵌入凭证
javascript
// Using dg-token header (recommended)
const verifyDgToken = (req, res, next) => {
const dgToken = req.headers['dg-token'];
if (!dgToken || dgToken !== process.env.DEEPGRAM_API_KEY_ID) {
return res.status(403).send('Invalid authentication');
}
next();
};
// Basic Auth in callback URL
// https://username:password@your-domain.com/webhooks/deepgramMaking a Request with Callback
发起带回调的请求
bash
curl \
--request POST \
--header 'Authorization: Token YOUR_DEEPGRAM_API_KEY' \
--header 'Content-Type: audio/wav' \
--data-binary @audio.wav \
--url 'https://api.deepgram.com/v1/listen?callback=https://your-domain.com/webhooks/deepgram'bash
curl \
--request POST \
--header 'Authorization: Token YOUR_DEEPGRAM_API_KEY' \
--header 'Content-Type: audio/wav' \
--data-binary @audio.wav \
--url 'https://api.deepgram.com/v1/listen?callback=https://your-domain.com/webhooks/deepgram'Common Event Types
常见事件类型
Deepgram sends transcription results as webhook payloads. The structure varies based on the features enabled in your request:
| Field | Description | Always Present |
|---|---|---|
| Unique identifier for the transcription request | Yes |
| Timestamp when transcription was created | Yes |
| Length of the audio in seconds | Yes |
| Number of audio channels | Yes |
| Transcription results by channel | Yes |
| Transcription alternatives | Yes |
| The transcribed text | Yes |
| Confidence score (0-1) | Yes |
Deepgram将转录结果作为webhook负载发送。其结构根据请求中启用的功能而有所不同:
| 字段 | 描述 | 是否始终存在 |
|---|---|---|
| 转录请求的唯一标识符 | 是 |
| 转录创建的时间戳 | 是 |
| 音频时长(秒) | 是 |
| 音频声道数 | 是 |
| 按声道划分的转录结果 | 是 |
| 转录备选结果 | 是 |
| 转录文本 | 是 |
| 置信度分数(0-1) | 是 |
Environment Variables
环境变量
bash
undefinedbash
undefinedYour Deepgram API Key (for making requests)
Your Deepgram API Key (for making requests)
DEEPGRAM_API_KEY=your_api_key_here
DEEPGRAM_API_KEY=your_api_key_here
API Key Identifier (shown in Deepgram console, used to verify dg-token)
API Key Identifier (shown in Deepgram console, used to verify dg-token)
Note: This is NOT your API Key secret - it's a unique identifier shown
Note: This is NOT your API Key secret - it's a unique identifier shown
in the Deepgram console that identifies which API key was used for a request
in the Deepgram console that identifies which API key was used for a request
DEEPGRAM_API_KEY_ID=your_api_key_id_here
DEEPGRAM_API_KEY_ID=your_api_key_id_here
Your webhook endpoint URL
Your webhook endpoint URL
WEBHOOK_URL=https://your-domain.com/webhooks/deepgram
undefinedWEBHOOK_URL=https://your-domain.com/webhooks/deepgram
undefinedLocal Development
本地开发
For local webhook testing, install Hookdeck CLI:
bash
undefined对于本地webhook测试,请安装Hookdeck CLI:
bash
undefinedInstall via npm
Install via npm
npm install -g hookdeck-cli
npm install -g hookdeck-cli
Or via Homebrew
Or via Homebrew
brew install hookdeck/hookdeck/hookdeck
brew install hookdeck/hookdeck/hookdeck
Create a local tunnel (no account required)
Create a local tunnel (no account required)
hookdeck listen 3000 --path /webhooks/deepgram
hookdeck listen 3000 --path /webhooks/deepgram
Use the provided URL as your callback URL when making Deepgram requests
Use the provided URL as your callback URL when making Deepgram requests
This provides:
- Local tunnel URL for testing
- Web UI for inspecting webhook payloads
- Request history and debugging tools
它提供以下功能:
- 用于测试的本地隧道URL
- 用于查看webhook负载的Web界面
- 请求历史和调试工具Important Notes
重要说明
Retry Behavior
重试机制
- Deepgram retries failed callbacks (non-200-299 status) up to 10 times
- 30-second delay between retry attempts
- Always return 200-299 status for successfully processed webhooks
- Deepgram会对失败的回调(非200-299状态码)最多重试10次
- 重试间隔为30秒
- 处理成功的webhook请始终返回200-299状态码
Port Restrictions
端口限制
- Only ports 80, 443, 8080, and 8443 are allowed for callbacks
- Ensure your webhook endpoint uses one of these ports
- 回调仅允许使用80、443、8080和8443端口
- 确保你的webhook端点使用这些端口之一
No Signature Verification
无签名验证
- Deepgram uses a simple token-based authentication via the dg-token header rather than cryptographic HMAC signatures used by other providers
- Authentication relies on the header or Basic Auth
dg-token - Always use HTTPS for webhook endpoints
- Deepgram通过dg-token头使用简单的基于令牌的身份验证,而非其他服务商使用的加密HMAC签名
- 身份验证依赖头或Basic Auth
dg-token - webhook端点请始终使用HTTPS
Resources
相关资源
- overview.md - What Deepgram webhooks are, transcription events
- setup.md - Configure callbacks in Deepgram API requests
- verification.md - Authentication methods and security considerations
- examples/ - Complete implementations for Express, Next.js, and FastAPI
- overview.md - 介绍Deepgram webhook是什么以及转录事件
- setup.md - 配置Deepgram API请求中的回调
- verification.md - 身份验证方式和安全注意事项
- examples/ - Express、Next.js和FastAPI的完整实现示例
Recommended: webhook-handler-patterns
推荐:webhook-handler-patterns
For production handlers, install the patterns skill alongside this one. Key references (links work when only this skill is installed):
Related Skills
相关Skill
- stripe-webhooks - Stripe payment webhooks
- shopify-webhooks - Shopify store webhooks
- github-webhooks - GitHub repository webhooks
- webhook-handler-patterns - Idempotency, error handling, retry logic
- hookdeck-event-gateway - Webhook infrastructure that replaces your queue — guaranteed delivery, automatic retries, replay, rate limiting, and observability for your webhook handlers
- stripe-webhooks - Stripe支付webhook
- shopify-webhooks - Shopify店铺webhook
- github-webhooks - GitHub仓库webhook
- webhook-handler-patterns - 幂等性、错误处理、重试逻辑
- hookdeck-event-gateway - 替代队列的webhook基础设施——为你的webhook处理器提供可靠交付、自动重试、重放、速率限制和可观测性