Skill站外收录 @skilllib/skill-2014279410545799171
gamma-webhooks-events
实现对 Gamma 平台实时事件的可靠接收与处理,支持创建、更新、导出和删除演示文稿等操作的自动化响应,通过异步队列确保消息不丢失,适用于构建高可用的事件驱动型集成应用。
效率工具 AI 技能
Skills.MD
# Gamma Webhooks & Events
## Overview
Implement webhook handlers and event processing for real-time Gamma updates.
## Prerequisites
- Public endpoint for webhook delivery
- Webhook secret from Gamma dashboard
- Understanding of event-driven architecture
## Instructions
### Step 1: Register Webhook Endpoint
```typescript
// Register via API
const webhook = await gamma.webhooks.create({
url: 'https://your-app.com/webhooks/gamma',
events: [
'presentation.created',
'presentation.updated',
'presentation.exported',
'presentation.deleted',
],
secret: process.env.GAMMA_WEBHOOK_SECRET,
});
console.log('Webhook registered:', webhook.id);
```
### Step 2: Create Webhook Handler
```typescript
// routes/webhooks/gamma.ts
import express from 'express';
import crypto from 'crypto';
const router = express.Router();
// Verify webhook signature
function verifySignature(payload: string, signature: string): boolean {
const secret = process.env.GAMMA_WEBHOOK_SECRET!;
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(`sha256=${expected}`)
);
}
router.post('/gamma',
express.raw({ type: 'application/json' }),
async (req, res) => {
const signature = req.headers['x-gamma-signature'] as string;
const payload = req.body.toString();
// Verify signature
if (!verifySignature(payload, signature)) {
return res.status(401).json({ error: 'Invalid signature' });
}
// Parse event
const event = JSON.parse(payload);
// Acknowledge receipt quickly
res.status(200).json({ received: true });
// Process event async
await processEvent(event);
}
);
export default router;
```
### Step 3: Event Processing
```typescript
// services/gamma-events.ts
interface GammaEvent {
id: string;
type: string;
data: any;
timestamp: string;
}
type EventHandler = (data: any) => Promise<void>;
const handlers: Record<string, EventHandler> = {
'presentation.created': async (data) => {
console.log('New presentation:', data.id);
await notifyTeam(`New presentation created: ${data.title}`);
await updateDatabase({ presentationId: data.id, status: 'created' });
},
'presentation.updated': async (data) => {
console.log('Presentation updated:', data.id);
await updateDatabase({ presentationId: data.id, status: 'updated' });
},
'presentation.exported': async (data) => {
console.log('Export complete:', data.exportUrl);
await sendExportNotification(data.userId, data.exportUrl);
},
'presentation.deleted': async (data) => {
console.log('Presentation deleted:', data.id);
await cleanupAssets(data.id);
},
};
export async function processEvent(event: GammaEvent) {
const handler = handlers[event.type];
if (!handler) {
console.warn('Unhandled event type:', event.type);
return;
}
try {
await handler(event.data);
await recordEventProcessed(event.id);
} catch (err) {
console.error('Event processing failed:', err);
await recordEventFailed(event.id, err);
}
}
```
### Step 4: Event Queue for Reliability
```typescript
// services/event-queue.ts
import Bull from 'bull';
const eventQueue = new Bull('gamma-events', {
redis: process.env.REDIS_URL,
});
// Add to queue instead of processing directly
export async function queueEvent(event: GammaEvent) {
await eventQueue.add(event, {
attempts: 3,
backoff: {
type: 'exponential',
delay: 5000,
},
});
}
// Process queue
eventQueue.process(async (job) => {
await processEvent(job.data);
});
eventQueue.on('failed', (job, err) => {
console.error(`Event ${job.id} failed:`, err.message);
// Send to dead letter queue or alert
});
```
### Step 5: Webhook Management
```typescript
// List webhooks
const webhooks = await gamma.webhooks.list();
// Update webhook
await gamma.webhooks.update(webhookId, {
events: ['presentation.created', 'presentation.exported'],
});
// Delete webhook
await gamma.webhooks.delete(webhookId);
// Test webhook
await gamma.webhooks.test(webhookId);
```
## Event Types Reference
| Event | Description | Payload |
|-------|-------------|---------|
| `presentation.created` | New presentation | id, title, userId |
| `presentation.updated` | Slides modified | id, changes[] |
| `presentation.exported` | Export completed | id, format, url |
| `presentation.deleted` | Presentation removed | id |
| `presentation.shared` | Sharing updated | id, shareSettings |
## Output
- Verified webhook handler
- Event processing pipeline
- Reliable queue system
- Webhook management API
## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| Invalid signature | Secret mismatch | Verify webhook secret |
| Timeout | Slow processing | Use async queue |
| Duplicate events | Retry delivery | Implement idempotency |
| Missing events | Endpoint down | Use reliable hosting |
## Resources
- [Gamma Webhooks Guide](https://gamma.app/docs/webhooks)
- [Webhook Best Practices](https://gamma.app/docs/webhooks-best-practices)
## Next Steps
Proceed to `gamma-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
举报「gamma-webhooks-events」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次