Skill站外收录 @skilllib/skill-2117939930272410894
juicebox-webhooks-events
实现 Juicebox 平台的实时事件响应能力,支持接收、校验、分发和异步处理搜索完成、档案增强、导出就绪及配额预警等关键事件,内置重试队列与幂等机制,确保通知可靠落地。
效率工具 AI 技能
Skills.MD
# Juicebox Webhooks & Events
## Overview
Implement webhook handlers for real-time Juicebox events and notifications.
## Prerequisites
- Juicebox account with webhooks enabled
- HTTPS endpoint for webhook delivery
- Request signature verification capability
## Instructions
### Step 1: Register Webhook Endpoint
```typescript
// First, configure in Juicebox dashboard or via API
import { JuiceboxClient } from '@juicebox/sdk';
const client = new JuiceboxClient({
apiKey: process.env.JUICEBOX_API_KEY!
});
await client.webhooks.create({
url: 'https://your-app.com/webhooks/juicebox',
events: [
'search.completed',
'profile.enriched',
'export.ready',
'quota.warning'
],
secret: process.env.JUICEBOX_WEBHOOK_SECRET
});
```
### Step 2: Implement Webhook Handler
```typescript
// routes/webhooks.ts
import { Router } from 'express';
import crypto from 'crypto';
const router = Router();
// Verify webhook signature
function verifySignature(payload: string, signature: string, secret: string): boolean {
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(`sha256=${expected}`)
);
}
router.post('/webhooks/juicebox', express.raw({ type: 'application/json' }), async (req, res) => {
const signature = req.headers['x-juicebox-signature'] as string;
const payload = req.body.toString();
// Verify signature
if (!verifySignature(payload, signature, process.env.JUICEBOX_WEBHOOK_SECRET!)) {
return res.status(401).json({ error: 'Invalid signature' });
}
const event = JSON.parse(payload);
// Acknowledge receipt immediately
res.status(200).json({ received: true });
// Process event asynchronously
await processWebhookEvent(event);
});
export default router;
```
### Step 3: Process Different Event Types
```typescript
// services/webhook-processor.ts
interface WebhookEvent {
id: string;
type: string;
timestamp: string;
data: any;
}
export async function processWebhookEvent(event: WebhookEvent): Promise<void> {
console.log(`Processing event: ${event.type} (${event.id})`);
switch (event.type) {
case 'search.completed':
await handleSearchCompleted(event.data);
break;
case 'profile.enriched':
await handleProfileEnriched(event.data);
break;
case 'export.ready':
await handleExportReady(event.data);
break;
case 'quota.warning':
await handleQuotaWarning(event.data);
break;
default:
console.warn(`Unknown event type: ${event.type}`);
}
}
async function handleSearchCompleted(data: { searchId: string; resultCount: number }) {
// Notify user that search is complete
await notificationService.send({
type: 'search_complete',
searchId: data.searchId,
message: `Search completed with ${data.resultCount} results`
});
}
async function handleProfileEnriched(data: { profileId: string; fields: string[] }) {
// Update local cache with enriched data
await cacheService.invalidate(`profile:${data.profileId}`);
await db.profiles.update({
where: { id: data.profileId },
data: { enrichedAt: new Date() }
});
}
async function handleExportReady(data: { exportId: string; downloadUrl: string }) {
// Notify user and store download URL
await notificationService.send({
type: 'export_ready',
exportId: data.exportId,
downloadUrl: data.downloadUrl
});
}
async function handleQuotaWarning(data: { usage: number; limit: number }) {
// Alert team about quota usage
const percentage = (data.usage / data.limit) * 100;
if (percentage > 80) {
await alertService.send({
severity: 'warning',
message: `Juicebox quota at ${percentage.toFixed(1)}%`
});
}
}
```
### Step 4: Implement Retry Logic
```typescript
// lib/webhook-queue.ts
import { Queue } from 'bullmq';
const webhookQueue = new Queue('juicebox-webhooks', {
connection: { host: 'localhost', port: 6379 }
});
export async function queueWebhookProcessing(event: WebhookEvent): Promise<void> {
await webhookQueue.add('process', event, {
attempts: 3,
backoff: {
type: 'exponential',
delay: 1000
}
});
}
// Worker
import { Worker } from 'bullmq';
new Worker('juicebox-webhooks', async (job) => {
await processWebhookEvent(job.data);
}, {
connection: { host: 'localhost', port: 6379 }
});
```
## Webhook Events Reference
| Event | Description | Payload |
|-------|-------------|---------|
| `search.completed` | Async search finished | searchId, resultCount |
| `profile.enriched` | Profile data enriched | profileId, fields |
| `export.ready` | Bulk export ready | exportId, downloadUrl |
| `quota.warning` | Approaching quota limit | usage, limit |
| `key.rotated` | API key rotated | newKeyPrefix |
## Output
- Webhook endpoint handler
- Signature verification
- Event type processors
- Retry queue with backoff
## Error Handling
| Issue | Cause | Solution |
|-------|-------|----------|
| Invalid signature | Wrong secret | Verify webhook secret |
| Duplicate events | Network retry | Implement idempotency |
| Processing timeout | Slow handler | Use async queue |
## Resources
- [Webhooks Documentation](https://juicebox.ai/docs/webhooks)
- [Event Reference](https://juicebox.ai/docs/events)
## Next Steps
After webhooks, see `juicebox-performance-tuning` for optimization.
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「juicebox-webhooks-events」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次