Webhooks API

实时会议事件通知

Webhooks API 支持会议事件的实时通知,让你的应用程序能够接收会议开始、完成、转写事件等相关更新。

  • 接收实时会议通知
  • 与现有 workflow 工具集成
  • 为会议事件构建自定义事件处理程序
  • 自动化会后流程

Webhook 提供了一种强大的方式,让应用程序能够响应会议生命周期事件,无需持续轮询,从而实现与 CRM、分析平台及其他业务系统的高效集成。

核心功能

  • 会议生命周期事件: 接收会议开始、完成和失败的通知
  • 转写事件: 在转写可用或更新时获取通知
  • 日历事件: 日历变更和同步通知
  • 重试机制: 用于重试失败 webhook 投递的 API endpoint
  • 自定义 Endpoint: 为不同事件类型设置不同的 webhook URL
  • 事件过滤: 控制哪些事件触发通知

Webhook 事件类型

Meeting BaaS webhook 投递以下事件类型:

  • meeting.started: bot 已成功加入会议
  • meeting.completed: 会议已结束,录像可用
  • meeting.failed: bot 加入会议失败
  • transcription.available: 初始转写已可用
  • transcription.updated: 转写已更新或优化
  • calendar.synced: 日历已同步
  • event.added: 检测到新日历事件
  • event.updated: 日历事件已更新
  • event.deleted: 日历事件已删除

设置与配置

配置 Webhook Endpoint

以下示例展示如何为会议事件配置 webhook URL:

此 JSON 配置展示了如何在你的 Meeting BaaS 账户中设置 webhook endpoint。

webhook_config.json
{
  "webhook_url": "https://your-app.com/webhooks/meetingbaas",
  "events": [
    "meeting.started",
    "meeting.completed",
    "meeting.failed",
    "transcription.available"
  ],
  "secret": "your-webhook-secret-key",
  "enabled": true
}

列出 Webhook Endpoint

list_webhooks.sh
curl -X GET "https://api.meetingbaas.com/bots/webhooks/bot" \
  -H "x-meeting-baas-api-key: <token>"

Webhook 事件格式

以下是 webhook 事件 payload 的示例:

这些 JSON 示例展示了会议开始和完成事件通知的格式。

会议完成事件

meeting_completed.json
{
  "event": "complete",
  "data": {
    "bot_id": "123e4567-e89b-12d3-a456-426614174000",
    "transcript": [
      {
        "speaker": "John Doe",
        "offset": 1.5,
        "words": [
          {
            "start": 1.5,
            "end": 1.9,
            "word": "Hello"
          },
          {
            "start": 2.0,
            "end": 2.4,
            "word": "everyone"
          }
        ]
      }
    ],
    "speakers": [
      "Jane Smith",
      "John Doe"
    ],
    "mp4": "https://storage.example.com/recordings/video123.mp4?token=abc",
    "event": "complete"
  }
}

会议失败事件

meeting_failed.json
{
  "event": "failed",
  "data": {
    "bot_id": "123e4567-e89b-12d3-a456-426614174000",
    "error": "meeting_not_found",
    "message": "Could not join meeting: The meeting ID was not found or has expired"
  }
}

转写完成事件

transcription_complete.json
{
  "event": "transcription_complete",
  "data": {
    "bot_id": "123e4567-e89b-12d3-a456-426614174000"
  }
}

实现示例

Python Webhook 处理程序

webhook_handler_flask.py
from flask import Flask, request, jsonify
import hmac
import hashlib

app = Flask(__name__)
WEBHOOK_SECRET = "your-webhook-secret-key"

def verify_signature(payload, signature):
    expected_signature = hmac.new(
        WEBHOOK_SECRET.encode(),
        payload,
        hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(signature, expected_signature)

@app.route('/webhooks/meetingbaas', methods=['POST'])
def webhook_handler():
    signature = request.headers.get('X-MeetingBaas-Signature')
    payload = request.get_data()
    
    if not verify_signature(payload, signature):
        return jsonify({"error": "Invalid signature"}), 401
    
    event_data = request.json
    
    if event_data['event'] == 'complete':
        # Handle meeting completion
        bot_id = event_data['data']['bot_id']
        transcript = event_data['data']['transcript']
        recording_url = event_data['data']['mp4']
        
        # Process the meeting data
        process_meeting_completion(bot_id, transcript, recording_url)
        
    elif event_data['event'] == 'failed':
        # Handle meeting failure
        bot_id = event_data['data']['bot_id']
        error = event_data['data']['error']
        message = event_data['data']['message']
        
        # Log the failure
        log_meeting_failure(bot_id, error, message)
    
    return jsonify({"status": "success"}), 200

def process_meeting_completion(bot_id, transcript, recording_url):
    # Your custom logic here
    print(f"Meeting {bot_id} completed")
    print(f"Recording available at: {recording_url}")

if __name__ == '__main__':
    app.run(debug=True, port=5000)
webhook_handler_fastapi.py
from fastapi import FastAPI, Request, HTTPException, Header
import hmac
import hashlib
from typing import Optional

app = FastAPI()
WEBHOOK_SECRET = "your-webhook-secret-key"

def verify_signature(payload: bytes, signature: str) -> bool:
    expected_signature = hmac.new(
        WEBHOOK_SECRET.encode(),
        payload,
        hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(signature, expected_signature)

@app.post("/webhooks/meetingbaas")
async def webhook_handler(
    request: Request,
    x_meetingbaas_signature: Optional[str] = Header(None)
):
    payload = await request.body()
    
    if not x_meetingbaas_signature:
        raise HTTPException(status_code=401, detail="Missing signature")
    
    if not verify_signature(payload, x_meetingbaas_signature):
        raise HTTPException(status_code=401, detail="Invalid signature")
    
    event_data = await request.json()
    
    # Process different event types
    if event_data['event'] == 'complete':
        await handle_meeting_completion(event_data['data'])
    elif event_data['event'] == 'failed':
        await handle_meeting_failure(event_data['data'])
    elif event_data['event'] == 'transcription_complete':
        await handle_transcription_complete(event_data['data'])
    
    return {"status": "success"}

async def handle_meeting_completion(data):
    bot_id = data['bot_id']
    transcript = data['transcript']
    recording_url = data['mp4']
    
    # Your custom logic here
    print(f"Meeting {bot_id} completed")
    print(f"Recording available at: {recording_url}")

async def handle_meeting_failure(data):
    bot_id = data['bot_id']
    error = data['error']
    message = data['message']
    
    # Your custom logic here
    print(f"Meeting {bot_id} failed: {error} - {message}")

async def handle_transcription_complete(data):
    bot_id = data['bot_id']
    
    # Your custom logic here
    print(f"Transcription completed for meeting {bot_id}")

Node.js Webhook 处理程序

webhook_handler_node.js
const express = require('express');
const crypto = require('crypto');
const app = express();

const WEBHOOK_SECRET = 'your-webhook-secret-key';

app.use(express.json());

function verifySignature(payload, signature) {
  const expectedSignature = crypto
    .createHmac('sha256', WEBHOOK_SECRET)
    .update(payload)
    .digest('hex');
  
  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(expectedSignature)
  );
}

app.post('/webhooks/meetingbaas', (req, res) => {
  const signature = req.headers['x-meetingbaas-signature'];
  const payload = JSON.stringify(req.body);
  
  if (!verifySignature(payload, signature)) {
    return res.status(401).json({ error: 'Invalid signature' });
  }
  
  const eventData = req.body;
  
  switch (eventData.event) {
    case 'complete':
      handleMeetingCompletion(eventData.data);
      break;
    case 'failed':
      handleMeetingFailure(eventData.data);
      break;
    case 'transcription_complete':
      handleTranscriptionComplete(eventData.data);
      break;
    default:
      console.log(`Unknown event: ${eventData.event}`);
  }
  
  res.json({ status: 'success' });
});

function handleMeetingCompletion(data) {
  const { bot_id, transcript, mp4 } = data;
  console.log(`Meeting ${bot_id} completed`);
  console.log(`Recording available at: ${mp4}`);
  
  // Your custom logic here
  // e.g., save to database, send notifications, etc.
}

function handleMeetingFailure(data) {
  const { bot_id, error, message } = data;
  console.log(`Meeting ${bot_id} failed: ${error} - ${message}`);
  
  // Your custom logic here
  // e.g., retry logic, alert notifications, etc.
}

function handleTranscriptionComplete(data) {
  const { bot_id } = data;
  console.log(`Transcription completed for meeting ${bot_id}`);
  
  // Your custom logic here
  // e.g., process transcript, update database, etc.
}

app.listen(3000, () => {
  console.log('Webhook server running on port 3000');
});

最佳实践

安全性

  • 始终验证 webhook 签名
  • 使用 HTTPS endpoint
  • 实施 rate limiting
  • 验证事件数据

可靠性

  • 快速返回 200 状态码
  • 实现幂等性
  • 处理重复事件
  • 设置监控和告警

错误处理

  • 记录所有 webhook 事件的 log
  • 为失败实现重试逻辑
  • 设置死信队列
  • 监控 webhook 投递状态
Meeting BaaS API Preview Features

开始使用

准备好集成实时会议通知了吗?请查看我们的综合资源: