Skills.MD
# Lindy Webhooks & Events
## Overview
Configure webhooks and event-driven integrations with Lindy AI.
## Prerequisites
- Lindy account with webhook access
- HTTPS endpoint for receiving webhooks
- Understanding of event types
## Instructions
### Step 1: Register Webhook
```typescript
import { Lindy } from '@lindy-ai/sdk';
const lindy = new Lindy({ apiKey: process.env.LINDY_API_KEY });
async function registerWebhook() {
const webhook = await lindy.webhooks.create({
url: 'https://myapp.com/webhooks/lindy',
events: [
'agent.run.started',
'agent.run.completed',
'agent.run.failed',
'automation.triggered',
],
secret: process.env.WEBHOOK_SECRET,
});
console.log(`Webhook ID: ${webhook.id}`);
return webhook;
}
```
### Step 2: Create Webhook Handler
```typescript
// routes/webhooks/lindy.ts
import express from 'express';
import crypto from 'crypto';
const router = express.Router();
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('/lindy', express.raw({ type: 'application/json' }), (req, res) => {
const signature = req.headers['x-lindy-signature'] as string;
const payload = req.body.toString();
// Verify signature
if (!verifySignature(payload, signature, process.env.WEBHOOK_SECRET!)) {
return res.status(401).send('Invalid signature');
}
const event = JSON.parse(payload);
// Handle event
switch (event.type) {
case 'agent.run.completed':
handleRunCompleted(event.data);
break;
case 'agent.run.failed':
handleRunFailed(event.data);
break;
case 'automation.triggered':
handleAutomationTriggered(event.data);
break;
default:
console.log('Unhandled event:', event.type);
}
res.status(200).send('OK');
});
export default router;
```
### Step 3: Implement Event Handlers
```typescript
// handlers/lindy-events.ts
interface RunCompletedEvent {
runId: string;
agentId: string;
input: string;
output: string;
duration: number;
}
interface RunFailedEvent {
runId: string;
agentId: string;
error: string;
errorCode: string;
}
async function handleRunCompleted(data: RunCompletedEvent) {
console.log(`Run ${data.runId} completed in ${data.duration}ms`);
// Store result
await db.runs.create({
runId: data.runId,
agentId: data.agentId,
output: data.output,
status: 'completed',
});
// Trigger downstream actions
await processResult(data);
}
async function handleRunFailed(data: RunFailedEvent) {
console.error(`Run ${data.runId} failed: ${data.error}`);
// Alert on failure
await alerting.send({
severity: 'high',
message: `Lindy agent failed: ${data.errorCode}`,
details: data,
});
// Retry if appropriate
if (data.errorCode === 'TIMEOUT') {
await retryRun(data.runId);
}
}
async function handleAutomationTriggered(data: any) {
console.log(`Automation ${data.automationId} triggered`);
// Log automation trigger
await db.automations.log({
automationId: data.automationId,
triggeredAt: new Date(),
input: data.input,
});
}
```
### Step 4: Test Webhooks
```typescript
// Test webhook delivery
async function testWebhook(webhookId: string) {
const lindy = new Lindy({ apiKey: process.env.LINDY_API_KEY });
const result = await lindy.webhooks.test(webhookId, {
type: 'agent.run.completed',
data: {
runId: 'test_run_123',
agentId: 'agt_test',
output: 'Test output',
duration: 1000,
},
});
console.log('Test result:', result);
}
```
## Event Types
| Event | Description | Payload |
|-------|-------------|---------|
| `agent.run.started` | Agent run began | runId, agentId, input |
| `agent.run.completed` | Agent run finished | runId, output, duration |
| `agent.run.failed` | Agent run failed | runId, error, errorCode |
| `automation.triggered` | Automation fired | automationId, input |
| `agent.created` | New agent created | agentId, name |
| `agent.deleted` | Agent deleted | agentId |
## Output
- Registered webhooks
- Event handler implementation
- Signature verification
- Event logging
## Error Handling
| Issue | Cause | Solution |
|-------|-------|----------|
| Invalid signature | Wrong secret | Check WEBHOOK_SECRET |
| Timeout | Handler slow | Respond quickly, process async |
| Duplicate events | Retry delivery | Implement idempotency |
## Examples
### Async Processing Pattern
```typescript
router.post('/lindy', async (req, res) => {
// Verify signature first
if (!verifySignature(req)) {
return res.status(401).send('Invalid');
}
// Acknowledge immediately
res.status(200).send('OK');
// Process asynchronously
const event = JSON.parse(req.body);
await queue.push('lindy-events', event);
});
```
## Resources
- [Lindy Webhooks](https://docs.lindy.ai/webhooks)
- [Event Reference](https://docs.lindy.ai/webhooks/events)
- [Security Best Practices](https://docs.lindy.ai/webhooks/security)
## Next Steps
Proceed to `lindy-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
举报「lindy-webhooks-events」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次