molecule-core/docs/tutorials/lark-feishu-channel.md
devops-engineer 55689e0b10
Some checks failed
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 16s
Check merge_group trigger on required workflows / Required workflows have merge_group trigger (pull_request) Successful in 22s
CI / Detect changes (pull_request) Successful in 24s
E2E API Smoke Test / detect-changes (pull_request) Successful in 20s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 21s
pr-guards / disable-auto-merge-on-push (pull_request) Failing after 9s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 44s
Lint curl status-code capture / Scan workflows for curl status-capture pollution (pull_request) Successful in 38s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 35s
Harness Replays / detect-changes (pull_request) Successful in 44s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 27s
Ops Scripts Tests / Ops scripts (unittest) (pull_request) Successful in 56s
CodeQL / Analyze (${{ matrix.language }}) (go) (pull_request) Failing after 2m1s
CodeQL / Analyze (${{ matrix.language }}) (javascript-typescript) (pull_request) Failing after 2m34s
CodeQL / Analyze (${{ matrix.language }}) (python) (pull_request) Failing after 2m34s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 23s
Harness Replays / Harness Replays (pull_request) Failing after 1m12s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 2m51s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Failing after 5m37s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 6m15s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 6m34s
CI / Python Lint & Test (pull_request) Successful in 8m20s
CI / Canvas (Next.js) (pull_request) Successful in 9m46s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
CI / Platform (Go) (pull_request) Failing after 13m23s
fix(post-suspension): migrate github.com/Molecule-AI refs to git.moleculesai.app (Class G #168)
The GitHub org Molecule-AI was suspended on 2026-05-06; canonical SCM
is now Gitea at https://git.moleculesai.app/molecule-ai/. Stale
github.com/Molecule-AI/... URLs return 404 and break tooling that
clones / pip-installs / curls them.

This bundles all non-Go-module URL fixes for this repo into a single PR.
Go module path references (in *.go, go.mod, go.sum) are out of scope
here -- tracked separately under Task #140.

Token-auth clone URLs also flip ${GITHUB_TOKEN} -> ${GITEA_TOKEN} since
the GitHub token does not auth against Gitea.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 13:08:15 -07:00

3.4 KiB

Connecting an AI Agent to Lark / Feishu

Molecule AI's Lark channel adapter (shipped in #480) lets any workspace agent receive messages from Lark or Feishu chats and reply through the same thread. This tutorial gets you from zero to a live bot in about ten minutes.

Lark vs Feishu — same payload format, different host. Lark is the international product; Feishu is the China edition. The adapter detects which host to use from your webhook URL.

Prerequisites

  • A Molecule AI workspace already running (any runtime)
  • A Lark tenant with permission to create a Custom Bot
  • PLATFORM_URL and a workspace bearer token

Setup

# 1. Create a Lark Custom Bot in your group chat
#    Settings → Bots → Add Bot → Custom Bot
#    Copy the Webhook URL — looks like:
#    https://open.larksuite.com/open-apis/bot/v2/hook/<token>

# 2. (Recommended) Set a Verification Token in the Lark bot settings.
#    This lets the platform reject spoofed inbound messages.

# 3. Register the channel on your workspace
curl -s -X POST "${PLATFORM_URL}/workspaces/${WORKSPACE_ID}/channel" \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "lark",
    "config": {
      "webhook_url": "https://open.larksuite.com/open-apis/bot/v2/hook/YOUR_TOKEN",
      "verify_token": "YOUR_VERIFY_TOKEN"
    }
  }'

# 4. Point Lark Event Subscriptions at your platform
#    Lark Developer Console → Event Subscriptions → Request URL:
#    https://YOUR_PLATFORM/channels/lark/webhook

# 5. Subscribe to the im.message.receive_v1 event in Lark console.

# 6. Send a message in the Lark group — your agent replies.
#    Watch the round-trip:
molecule workspace logs ${WORKSPACE_ID} --follow

The 200-OK-but-failed gotcha

Lark's outbound API always returns HTTP 200, even on delivery failure. The real result is in the JSON body:

{ "code": 99, "msg": "...", "data": {} }

Molecule AI surfaces code != 0 as a hard Go error so your agent sees an actual failure instead of silent data loss. Check last_sample_error on the workspace if messages seem to disappear.

Expected output

After step 6, workspace logs shows:

[channel:lark] inbound  user_id=ou_xxx  text="Hello agent"
[agent]        reply    "Hi! How can I help you today?"
[channel:lark] outbound code=0  ok

How it works

When a Lark user sends a message the platform receives a v2 event_callback (im.message.receive_v1). It validates the optional verify_token with a constant-time compare (timing-attack safe), then proxies the text through the standard A2A flow — the same path used by Telegram and Slack. The agent never knows which channel it's talking to. Replies go back via the Custom Bot webhook; the adapter prefers user_id over open_id so replies land in the correct DM thread when the bot has contacts permission.

Multi-channel teams

You can attach different channels to different workspaces in the same org. Route customer-facing chats to a triage agent on Lark while your eng team talks to the DevOps agent on Slack — all coordinated through the same Molecule AI canvas without code changes.