技能 编程开发 处理Lucidchart网络钩子事件

处理Lucidchart网络钩子事件

v20260423
lucidchart-webhooks-events
本技能详细介绍了如何接收和处理来自Lucidchart的实时网络钩子(Webhook)事件。它涵盖了从文档创建、更新、分享到形状添加等各种事件的处理流程,包括使用签名验证(Signature Verification)确保数据安全。可用于构建流程自动化、实现合规审计或与Slack等外部系统集成。
获取技能
266 次下载
概览

Lucidchart Webhooks & Events

Overview

Lucidchart delivers real-time webhook notifications when documents, shapes, and collaboration states change across your organization's diagramming workspace. These events power integrations such as auto-archiving diagrams to Confluence when finalized, notifying Slack channels when collaborators join a shared document, triggering CI pipelines when architecture diagrams are updated, and maintaining audit logs of all document access. Payloads are signed JSON delivered over HTTPS using a webhook signing secret.

Prerequisites

  • A Lucid developer account with an OAuth2 app registered at developer.lucid.co
  • Webhook endpoint URL accessible over HTTPS (TLS 1.2+)
  • Webhook signing secret from the Lucid app settings (LUCID_WEBHOOK_SECRET)
  • Express.js with raw body parsing for signature verification

Webhook Registration

import axios from "axios";

const res = await axios.post(
  "https://api.lucid.co/v1/webhooks",
  {
    callbackUrl: "https://your-app.com/webhooks/lucidchart",
    events: ["document.created", "document.updated", "document.shared",
             "shape.added", "collaborator.joined"],
    scope: "account",
  },
  { headers: { Authorization: `Bearer ${process.env.LUCID_ACCESS_TOKEN}`,
               "Lucid-Api-Version": "1" } }
);
console.log("Webhook ID:", res.data.webhookId);

Signature Verification

import crypto from "crypto";
import { Request, Response, NextFunction } from "express";

function verifyLucidSignature(req: Request, res: Response, next: NextFunction) {
  const signature = req.headers["x-lucid-signature"] as string;
  const requestId = req.headers["x-lucid-request-id"] as string;
  if (!signature || !requestId) return res.status(401).send("Missing signature");

  const expected = crypto
    .createHmac("sha256", process.env.LUCID_WEBHOOK_SECRET!)
    .update((req as any).rawBody)
    .digest("base64");

  if (!crypto.timingSafeEqual(Buffer.from(signature, "base64"), Buffer.from(expected, "base64"))) {
    return res.status(403).send("Invalid signature");
  }
  next();
}

Event Handler

app.post("/webhooks/lucidchart", verifyLucidSignature, (req, res) => {
  const { eventType, data, timestamp } = req.body;

  switch (eventType) {
    case "document.created":
      console.log(`New doc: "${data.title}" by ${data.creatorId} in ${data.folderId}`);
      break;
    case "document.updated":
      console.log(`Doc updated: ${data.documentId}, pages: ${data.pageCount}`);
      break;
    case "document.shared":
      console.log(`Doc shared: ${data.documentId} → ${data.recipientEmail} (${data.permission})`);
      break;
    case "shape.added":
      console.log(`Shape: ${data.shapeType} on page ${data.pageId} of doc ${data.documentId}`);
      break;
    case "collaborator.joined":
      console.log(`${data.userId} joined doc ${data.documentId} as ${data.role}`);
      break;
    default:
      console.warn(`Unhandled event: ${eventType}`);
  }
  res.status(200).json({ ok: true });
});

Event Types

EventPayload FieldsUse Case
document.createddocumentId, title, creatorId, folderId, templateIdIndex new diagrams in search or notify team channels
document.updateddocumentId, pageCount, lastEditedBy, editSummaryTrigger CI when architecture diagrams change
document.shareddocumentId, recipientEmail, permission, sharedByAudit external sharing for compliance
shape.addeddocumentId, pageId, shapeType, shapeId, positionTrack diagram complexity metrics
collaborator.joineddocumentId, userId, role, joinedAtPost Slack notifications for live collaboration
document.deleteddocumentId, deletedBy, deletedAtRemove stale references from linked systems

Retry & Idempotency

const seen = new Set<string>();

function ensureIdempotent(req: Request, res: Response, next: NextFunction) {
  const requestId = req.headers["x-lucid-request-id"] as string;
  if (seen.has(requestId)) {
    return res.status(200).json({ duplicate: true });
  }
  seen.add(requestId);
  next();
}
// Lucid retries failed deliveries 3 times with exponential backoff (1 min, 5 min, 30 min).
// After 3 consecutive failures the webhook is marked inactive and must be re-enabled via API.

Error Handling

IssueCauseFix
403 on signature checkSigning secret regenerated in Lucid dashboardUpdate LUCID_WEBHOOK_SECRET and redeploy
Events arrive for wrong accountWebhook scope set to user instead of accountRe-register with "scope": "account"
shape.added floods endpointBusy diagram with many rapid editsDebounce by documentId with a 5-second window
Webhook marked inactiveEndpoint returned errors for 3 retriesFix endpoint, then PATCH webhook status to active
Missing Lucid-Api-Version headerAPI version not pinnedAlways include "Lucid-Api-Version": "1" in registration

Resources

Next Steps

See lucidchart-security-basics.

信息
分类 编程开发
名称 lucidchart-webhooks-events
版本 v20260423
大小 5.41KB
更新时间 2026-04-26
语言