Lark / Feishu
Chat SDK adapter for Lark / Feishu, built on the official @larksuiteoapi/node-sdk. Receives events over a WebSocket long connection and supports native cardkit streaming, interactive cards, and reactions.
Install
pnpm add @larksuite/vercel-chat-adapterQuick start
bot.initialize() opens the Lark WebSocket connection and keeps it alive until you call bot.shutdown(). The open connection keeps the process running, so a long-running environment doesn't need a separate server.
When you pass no explicit config, the adapter reads LARK_APP_ID, LARK_APP_SECRET, and LARK_BOT_USERNAME from environment variables.
Platform setup
Create a Lark app in one of two ways. Scan-to-create is recommended because it configures the permissions and event subscriptions the adapter needs for you.
Create an app with scan-to-create
registerLarkApp drives Lark's official scan-to-create flow. The SDK generates a one-time URL, you render it as a QR code, and the user scans it with the Lark mobile app and approves. You get back client_id and client_secret, with the permissions and event subscriptions this adapter needs already configured.
You only need to run this once. Persist the returned credentials and provide them through LARK_APP_ID and LARK_APP_SECRET on later runs.
Create an app in the developer console
Create an Intelligent Agent app in the developer console:
- Lark: open.larksuite.com/app
- Feishu: open.feishu.cn/app
Copy the app's client_id and client_secret and pass them as appId and appSecret, or set LARK_APP_ID and LARK_APP_SECRET.
Configuration
| Prop | Type | Description |
|---|---|---|
appId? | string | Lark app ID. Auto-detected from `LARK_APP_ID` when omitted. |
appSecret? | string | Lark app secret. Auto-detected from `LARK_APP_SECRET` when omitted. |
userName? | string | Bot display name. Defaults to `LARK_BOT_USERNAME` or `"bot"`. |
logger? | Logger | Chat SDK-compatible logger. Defaults to `ConsoleLogger("info", "lark")`. |
Environment variables
| Variable | Required | Description |
|---|---|---|
LARK_APP_ID | Yes, unless appId is passed | Lark app ID. Overridden by config.appId. |
LARK_APP_SECRET | Yes, unless appSecret is passed | Lark app secret. Overridden by config.appSecret. |
LARK_BOT_USERNAME | No | Bot display name. Overridden by config.userName. |
Transport
The adapter receives events over a WebSocket only, using Lark's long-connection mode, which works in production. handleWebhook() returns HTTP 501. Webhook transport is on the roadmap.
Because the SDK opens an outbound WebSocket to Lark's servers and receives events through it, you can run a Lark bot without exposing an HTTP endpoint. This suits long-running environments such as a Node process, a worker, or a VM. Serverless platforms that recycle the process on every request won't keep the connection alive.
Streaming
bot.adapter.stream() uses Lark's native cardkit typewriter API. Chunks emitted from your stream handler are appended directly inside a single card message, with no post-and-edit polling.
If the thread has a rootId, the streamed reply is posted as a thread reply through the SDK's replyTo parameter.
Message history
fetchMessages is built on im.v1.messages.list plus the SDK's normalize(), which covers Lark's 23 native message types and produces the same NormalizedMessage shape as live events.
listThreads is derived client-side by grouping list results on root_id. Lark has no server-side list-threads API, so paginate carefully in very active chats.
author.isMe is resolved for historical bot-authored messages as well as live events. The adapter maps the historical entry's app_id back to the bot's open_id through the SDK's botIdentity resolver.
Safety layer
The adapter disables LarkChannel's built-in safety features: stale-message detection, dedup, per-chat queue, and text batch. Chat SDK's per-thread lock and the state adapter handle message deduplication and subscription consistency, and running the SDK's safety layer on top would double-process or drop messages.
Thread IDs
Lark thread IDs use the format lark:{chatId}:{rootId}:
chatId:oc_*for both group and p2p chats, orou_*foropenDM()placeholders before the first message is delivered.rootId: the message'sroot_idif it is a reply, otherwise its ownmessage_id, since the message is its own root.
The adapter doesn't use Lark's native thread_id (omt_*) as the rootId segment. That value identifies a topic container rather than a message, and the send API can't accept it as replyTo.
DM detection
Lark's p2p chat IDs share the oc_* prefix with group chats, so isDM() relies on a chat-type cache populated by inbound events. After a process restart, the first DM may route through onNewMention until the cache catches up.
Limitations
The adapter supports a single app. A future version may support setInstallation() for multi-tenant fan-out; open an issue if you need it.
The following operations are not supported and throw NotImplementedError:
handleWebhook: returns HTTP 501. The adapter uses WebSocket transport only.startTyping: Lark has no typing-indicator API.postChannelMessage: Lark requires every message to belong to a chat, so there are no channel-level top-level messages distinct from threads.scheduleMessage,openModal,postEphemeral: not yet implemented.
Feature support
Messaging
| Feature | Supported |
|---|---|
| Post message | |
| Message replies | |
| Edit message | |
| Delete message | |
| File uploads | Via SDK channel.send |
| Streaming | Native cardkit typewriter |
| Scheduled messages |
Rich content
| Feature | Supported |
|---|---|
| Card format | Lark interactive cards |
| Buttons | |
| Link buttons | |
| Select menus | Card select / overflow |
| Tables | Markdown tables |
| Charts | |
| Fields | Card section fields |
| Images in cards | ImageElement |
| Modals |
Conversations
| Feature | Supported |
|---|---|
| Slash commands | |
| Mentions | |
| Add reactions | |
| Remove reactions | |
| Typing indicator | |
| Mark as read | |
| Message edit events | |
| Message delete events | |
| DMs | |
| Ephemeral messages | |
| User lookup | |
| Parent subject | |
| Native client | |
| Custom API endpoint |
Message history
| Feature | Supported |
|---|---|
| Fetch messages | |
| Fetch single message | |
| Fetch thread info | |
| Fetch channel messages | |
| List threads | Client-side grouping |
| Fetch channel info | |
| Post channel message |