Back to Eliza

Feishu/Lark Client Plugin for ElizaOS

plugins/plugin-feishu/README.md

2.0.14.3 KB
Original Source

Feishu/Lark Client Plugin for ElizaOS

This plugin integrates a Feishu (飞书) / Lark client with ElizaOS, allowing agents to interact via ByteDance's enterprise collaboration platform. It supports both the Chinese Feishu platform and the global Lark platform.

Features

  • Seamless Feishu/Lark Integration: Connects ElizaOS agents to Feishu/Lark through the Open Platform API.
  • WebSocket Real-time Events: Receives messages and events via WebSocket for low-latency interactions.
  • Multi-region Support: Works with both Feishu (China) and Lark (Global) platforms.
  • Configuration Validation: Ensures required settings are properly configured before starting.
  • DM and Group Support: Handles both direct messages and group conversations.

Configuration Options

KeyTypeDefaultDescription
FEISHU_APP_IDStringRequiredApplication ID from Feishu/Lark Open Platform (cli_xxx format).
FEISHU_APP_SECRETStringRequiredApplication secret for authentication.
FEISHU_DOMAINString"feishu"Domain to use: "feishu" for China or "lark" for global.
FEISHU_ALLOWED_CHATSJSON Array[]List of chat IDs the bot is allowed to interact with.
FEISHU_TEST_CHAT_IDString-Chat ID for running tests.

Pre-Requisites

1. Create a Feishu/Lark App

  1. Go to the Feishu Open Platform or Lark Open Platform
  2. Create a new application
  3. Enable the following capabilities:
    • Bot - For sending and receiving messages
    • Event Subscription - Enable WebSocket mode for real-time events
  4. Copy your App ID and App Secret from the credentials page

2. Configure Environment Variables

Add the following to your .env file:

env
FEISHU_APP_ID=cli_xxx
FEISHU_APP_SECRET=your-app-secret
FEISHU_DOMAIN=feishu  # or "lark" for global

3. Configure Your Character

Create or modify your character configuration file:

json
{
  "clients": ["feishu"],
  "settings": {
    "feishu": {
      "appId": "cli_xxx",
      "appSecret": "your-app-secret",
      "domain": "feishu"
    }
  }
}

Usage

Starting the Bot

From the project root:

bash
npm run dev

Or using bun:

bash
bun start --character="characters/your-character.json"

API Endpoints

The plugin connects to the following Feishu/Lark API endpoints:

DomainBase URL
Feishu (China)https://open.feishu.cn
Lark (Global)https://open.larksuite.com

Message Types Supported

  • Text messages
  • Rich text (post) messages
  • Interactive cards
  • Image messages
  • File messages

Event Types

The plugin emits the following event types:

EventDescription
FEISHU_WORLD_JOINEDBot joined a new chat/group
FEISHU_WORLD_CONNECTEDBot connected successfully
FEISHU_WORLD_LEFTBot left a chat/group
FEISHU_MESSAGE_RECEIVEDA message was received
FEISHU_MESSAGE_SENTA message was sent
FEISHU_ENTITY_JOINEDA user joined a chat
FEISHU_ENTITY_LEFTA user left a chat

Security Best Practices

  • Production: Restrict bot access using FEISHU_ALLOWED_CHATS to specify authorized chat IDs.
  • Token Management: Keep your App Secret secure and never expose it in public repositories.
  • Webhook Verification: The plugin automatically verifies webhook signatures from Feishu/Lark.

Feishu vs Lark

FeatureFeishuLark
RegionChinaGlobal
Domainopen.feishu.cnopen.larksuite.com
LanguageChineseEnglish
Data ResidencyChinaGlobal

Use FEISHU_DOMAIN=lark when deploying for international users.

Troubleshooting

Connection Issues

If you encounter connection issues:

  1. Verify your App ID and App Secret are correct
  2. Ensure the Bot capability is enabled in your app settings
  3. Check that WebSocket event subscription is enabled
  4. Verify your server can reach Feishu/Lark API endpoints

Message Not Received

If messages are not being received:

  1. Ensure the bot is added to the chat/group
  2. Check that FEISHU_ALLOWED_CHATS includes the chat ID (or is empty for all chats)
  3. Verify event subscription is properly configured

License

MIT