@colinlu50/openclaw-lark-stream 2026.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +141 -0
- package/README.zh.md +70 -0
- package/bin/openclaw-lark.js +48 -0
- package/index.d.ts +36 -0
- package/index.js +118 -0
- package/openclaw.plugin.json +10 -0
- package/package.json +66 -0
- package/skills/feishu-bitable/SKILL.md +248 -0
- package/skills/feishu-bitable/references/examples.md +813 -0
- package/skills/feishu-bitable/references/field-properties.md +763 -0
- package/skills/feishu-bitable/references/record-values.md +911 -0
- package/skills/feishu-calendar/SKILL.md +244 -0
- package/skills/feishu-channel-rules/SKILL.md +24 -0
- package/skills/feishu-channel-rules/references/markdown-syntax.md +138 -0
- package/skills/feishu-create-doc/SKILL.md +719 -0
- package/skills/feishu-fetch-doc/SKILL.md +93 -0
- package/skills/feishu-im-read/SKILL.md +163 -0
- package/skills/feishu-task/SKILL.md +293 -0
- package/skills/feishu-troubleshoot/SKILL.md +70 -0
- package/skills/feishu-update-doc/SKILL.md +285 -0
- package/src/card/builder.d.ts +106 -0
- package/src/card/builder.js +443 -0
- package/src/card/cardkit.d.ts +90 -0
- package/src/card/cardkit.js +181 -0
- package/src/card/flush-controller.d.ts +45 -0
- package/src/card/flush-controller.js +134 -0
- package/src/card/image-resolver.d.ts +45 -0
- package/src/card/image-resolver.js +112 -0
- package/src/card/markdown-style.d.ts +16 -0
- package/src/card/markdown-style.js +97 -0
- package/src/card/reply-dispatcher-types.d.ts +120 -0
- package/src/card/reply-dispatcher-types.js +57 -0
- package/src/card/reply-dispatcher.d.ts +15 -0
- package/src/card/reply-dispatcher.js +299 -0
- package/src/card/reply-mode.d.ts +38 -0
- package/src/card/reply-mode.js +65 -0
- package/src/card/streaming-card-controller.d.ts +101 -0
- package/src/card/streaming-card-controller.js +810 -0
- package/src/card/unavailable-guard.d.ts +35 -0
- package/src/card/unavailable-guard.js +83 -0
- package/src/channel/abort-detect.d.ts +34 -0
- package/src/channel/abort-detect.js +124 -0
- package/src/channel/chat-queue.d.ts +41 -0
- package/src/channel/chat-queue.js +58 -0
- package/src/channel/config-adapter.d.ts +23 -0
- package/src/channel/config-adapter.js +101 -0
- package/src/channel/directory.d.ts +57 -0
- package/src/channel/directory.js +191 -0
- package/src/channel/event-handlers.d.ts +15 -0
- package/src/channel/event-handlers.js +221 -0
- package/src/channel/monitor.d.ts +17 -0
- package/src/channel/monitor.js +129 -0
- package/src/channel/onboarding-config.d.ts +17 -0
- package/src/channel/onboarding-config.js +88 -0
- package/src/channel/onboarding-migrate.d.ts +25 -0
- package/src/channel/onboarding-migrate.js +67 -0
- package/src/channel/onboarding.d.ts +12 -0
- package/src/channel/onboarding.js +296 -0
- package/src/channel/plugin.d.ts +13 -0
- package/src/channel/plugin.js +278 -0
- package/src/channel/probe.d.ts +14 -0
- package/src/channel/probe.js +21 -0
- package/src/channel/types.d.ts +36 -0
- package/src/channel/types.js +7 -0
- package/src/commands/auth.d.ts +21 -0
- package/src/commands/auth.js +161 -0
- package/src/commands/diagnose.d.ts +69 -0
- package/src/commands/diagnose.js +807 -0
- package/src/commands/doctor.d.ts +26 -0
- package/src/commands/doctor.js +584 -0
- package/src/commands/index.d.ts +25 -0
- package/src/commands/index.js +212 -0
- package/src/commands/locale.d.ts +7 -0
- package/src/commands/locale.js +7 -0
- package/src/core/accounts.d.ts +37 -0
- package/src/core/accounts.js +163 -0
- package/src/core/agent-config.d.ts +100 -0
- package/src/core/agent-config.js +139 -0
- package/src/core/api-error.d.ts +48 -0
- package/src/core/api-error.js +112 -0
- package/src/core/app-owner-fallback.d.ts +21 -0
- package/src/core/app-owner-fallback.js +38 -0
- package/src/core/app-scope-checker.d.ts +87 -0
- package/src/core/app-scope-checker.js +190 -0
- package/src/core/auth-errors.d.ts +144 -0
- package/src/core/auth-errors.js +154 -0
- package/src/core/chat-info-cache.d.ts +57 -0
- package/src/core/chat-info-cache.js +152 -0
- package/src/core/config-schema.d.ts +448 -0
- package/src/core/config-schema.js +200 -0
- package/src/core/device-flow.d.ts +77 -0
- package/src/core/device-flow.js +212 -0
- package/src/core/domains.d.ts +18 -0
- package/src/core/domains.js +28 -0
- package/src/core/feishu-fetch.d.ts +18 -0
- package/src/core/feishu-fetch.js +25 -0
- package/src/core/footer-config.d.ts +24 -0
- package/src/core/footer-config.js +39 -0
- package/src/core/lark-client.d.ts +108 -0
- package/src/core/lark-client.js +353 -0
- package/src/core/lark-logger.d.ts +23 -0
- package/src/core/lark-logger.js +154 -0
- package/src/core/lark-ticket.d.ts +29 -0
- package/src/core/lark-ticket.js +35 -0
- package/src/core/message-unavailable.d.ts +53 -0
- package/src/core/message-unavailable.js +130 -0
- package/src/core/owner-policy.d.ts +31 -0
- package/src/core/owner-policy.js +52 -0
- package/src/core/permission-url.d.ts +22 -0
- package/src/core/permission-url.js +72 -0
- package/src/core/raw-request.d.ts +27 -0
- package/src/core/raw-request.js +62 -0
- package/src/core/scope-manager.d.ts +168 -0
- package/src/core/scope-manager.js +213 -0
- package/src/core/security-check.d.ts +72 -0
- package/src/core/security-check.js +174 -0
- package/src/core/shutdown-hooks.d.ts +22 -0
- package/src/core/shutdown-hooks.js +56 -0
- package/src/core/targets.d.ts +60 -0
- package/src/core/targets.js +164 -0
- package/src/core/token-store.d.ts +54 -0
- package/src/core/token-store.js +314 -0
- package/src/core/tool-client.d.ts +176 -0
- package/src/core/tool-client.js +380 -0
- package/src/core/tool-scopes.d.ts +153 -0
- package/src/core/tool-scopes.js +326 -0
- package/src/core/tools-config.d.ts +55 -0
- package/src/core/tools-config.js +137 -0
- package/src/core/types.d.ts +87 -0
- package/src/core/types.js +11 -0
- package/src/core/uat-client.d.ts +46 -0
- package/src/core/uat-client.js +187 -0
- package/src/core/version.d.ts +25 -0
- package/src/core/version.js +49 -0
- package/src/messaging/converters/audio.d.ts +8 -0
- package/src/messaging/converters/audio.js +21 -0
- package/src/messaging/converters/calendar.d.ts +13 -0
- package/src/messaging/converters/calendar.js +50 -0
- package/src/messaging/converters/content-converter.d.ts +41 -0
- package/src/messaging/converters/content-converter.js +106 -0
- package/src/messaging/converters/file.d.ts +8 -0
- package/src/messaging/converters/file.js +20 -0
- package/src/messaging/converters/folder.d.ts +8 -0
- package/src/messaging/converters/folder.js +20 -0
- package/src/messaging/converters/hongbao.d.ts +8 -0
- package/src/messaging/converters/hongbao.js +16 -0
- package/src/messaging/converters/image.d.ts +8 -0
- package/src/messaging/converters/image.js +18 -0
- package/src/messaging/converters/index.d.ts +8 -0
- package/src/messaging/converters/index.js +50 -0
- package/src/messaging/converters/interactive/card-converter.d.ts +76 -0
- package/src/messaging/converters/interactive/card-converter.js +1173 -0
- package/src/messaging/converters/interactive/card-utils.d.ts +9 -0
- package/src/messaging/converters/interactive/card-utils.js +42 -0
- package/src/messaging/converters/interactive/index.d.ts +8 -0
- package/src/messaging/converters/interactive/index.js +21 -0
- package/src/messaging/converters/interactive/legacy.d.ts +11 -0
- package/src/messaging/converters/interactive/legacy.js +57 -0
- package/src/messaging/converters/interactive/types.d.ts +23 -0
- package/src/messaging/converters/interactive/types.js +24 -0
- package/src/messaging/converters/location.d.ts +8 -0
- package/src/messaging/converters/location.js +19 -0
- package/src/messaging/converters/merge-forward.d.ts +32 -0
- package/src/messaging/converters/merge-forward.js +225 -0
- package/src/messaging/converters/post.d.ts +11 -0
- package/src/messaging/converters/post.js +135 -0
- package/src/messaging/converters/share.d.ts +9 -0
- package/src/messaging/converters/share.js +23 -0
- package/src/messaging/converters/sticker.d.ts +8 -0
- package/src/messaging/converters/sticker.js +18 -0
- package/src/messaging/converters/system.d.ts +12 -0
- package/src/messaging/converters/system.js +32 -0
- package/src/messaging/converters/text.d.ts +8 -0
- package/src/messaging/converters/text.js +14 -0
- package/src/messaging/converters/todo.d.ts +8 -0
- package/src/messaging/converters/todo.js +41 -0
- package/src/messaging/converters/types.d.ts +107 -0
- package/src/messaging/converters/types.js +7 -0
- package/src/messaging/converters/unknown.d.ts +8 -0
- package/src/messaging/converters/unknown.js +16 -0
- package/src/messaging/converters/utils.d.ts +22 -0
- package/src/messaging/converters/utils.js +51 -0
- package/src/messaging/converters/video-chat.d.ts +8 -0
- package/src/messaging/converters/video-chat.js +23 -0
- package/src/messaging/converters/video.d.ts +8 -0
- package/src/messaging/converters/video.js +32 -0
- package/src/messaging/converters/vote.d.ts +8 -0
- package/src/messaging/converters/vote.js +24 -0
- package/src/messaging/inbound/dedup.d.ts +59 -0
- package/src/messaging/inbound/dedup.js +116 -0
- package/src/messaging/inbound/dispatch-builders.d.ts +84 -0
- package/src/messaging/inbound/dispatch-builders.js +152 -0
- package/src/messaging/inbound/dispatch-commands.d.ts +27 -0
- package/src/messaging/inbound/dispatch-commands.js +112 -0
- package/src/messaging/inbound/dispatch-context.d.ts +67 -0
- package/src/messaging/inbound/dispatch-context.js +136 -0
- package/src/messaging/inbound/dispatch.d.ts +47 -0
- package/src/messaging/inbound/dispatch.js +264 -0
- package/src/messaging/inbound/enrich.d.ts +102 -0
- package/src/messaging/inbound/enrich.js +227 -0
- package/src/messaging/inbound/gate-effects.d.ts +23 -0
- package/src/messaging/inbound/gate-effects.js +43 -0
- package/src/messaging/inbound/gate.d.ts +60 -0
- package/src/messaging/inbound/gate.js +233 -0
- package/src/messaging/inbound/handler.d.ts +35 -0
- package/src/messaging/inbound/handler.js +173 -0
- package/src/messaging/inbound/media-resolver.d.ts +32 -0
- package/src/messaging/inbound/media-resolver.js +87 -0
- package/src/messaging/inbound/mention.d.ts +39 -0
- package/src/messaging/inbound/mention.js +81 -0
- package/src/messaging/inbound/parse-io.d.ts +50 -0
- package/src/messaging/inbound/parse-io.js +81 -0
- package/src/messaging/inbound/parse.d.ts +28 -0
- package/src/messaging/inbound/parse.js +106 -0
- package/src/messaging/inbound/permission.d.ts +17 -0
- package/src/messaging/inbound/permission.js +40 -0
- package/src/messaging/inbound/policy.d.ts +94 -0
- package/src/messaging/inbound/policy.js +160 -0
- package/src/messaging/inbound/reaction-handler.d.ts +61 -0
- package/src/messaging/inbound/reaction-handler.js +221 -0
- package/src/messaging/inbound/user-name-cache.d.ts +82 -0
- package/src/messaging/inbound/user-name-cache.js +241 -0
- package/src/messaging/outbound/actions.d.ts +16 -0
- package/src/messaging/outbound/actions.js +309 -0
- package/src/messaging/outbound/chat-manage.d.ts +64 -0
- package/src/messaging/outbound/chat-manage.js +111 -0
- package/src/messaging/outbound/deliver.d.ts +155 -0
- package/src/messaging/outbound/deliver.js +298 -0
- package/src/messaging/outbound/fetch.d.ts +12 -0
- package/src/messaging/outbound/fetch.js +12 -0
- package/src/messaging/outbound/forward.d.ts +26 -0
- package/src/messaging/outbound/forward.js +48 -0
- package/src/messaging/outbound/media-url-utils.d.ts +29 -0
- package/src/messaging/outbound/media-url-utils.js +130 -0
- package/src/messaging/outbound/media.d.ts +260 -0
- package/src/messaging/outbound/media.js +758 -0
- package/src/messaging/outbound/outbound.d.ts +89 -0
- package/src/messaging/outbound/outbound.js +121 -0
- package/src/messaging/outbound/reactions.d.ts +124 -0
- package/src/messaging/outbound/reactions.js +378 -0
- package/src/messaging/outbound/send.d.ts +152 -0
- package/src/messaging/outbound/send.js +355 -0
- package/src/messaging/outbound/typing.d.ts +71 -0
- package/src/messaging/outbound/typing.js +179 -0
- package/src/messaging/shared/message-lookup.d.ts +54 -0
- package/src/messaging/shared/message-lookup.js +117 -0
- package/src/messaging/types.d.ts +176 -0
- package/src/messaging/types.js +10 -0
- package/src/tools/auto-auth.d.ts +56 -0
- package/src/tools/auto-auth.js +919 -0
- package/src/tools/helpers.d.ts +260 -0
- package/src/tools/helpers.js +364 -0
- package/src/tools/mcp/doc/create.d.ts +12 -0
- package/src/tools/mcp/doc/create.js +44 -0
- package/src/tools/mcp/doc/fetch.d.ts +12 -0
- package/src/tools/mcp/doc/fetch.js +36 -0
- package/src/tools/mcp/doc/index.d.ts +12 -0
- package/src/tools/mcp/doc/index.js +41 -0
- package/src/tools/mcp/doc/update.d.ts +12 -0
- package/src/tools/mcp/doc/update.js +61 -0
- package/src/tools/mcp/shared.d.ts +59 -0
- package/src/tools/mcp/shared.js +226 -0
- package/src/tools/oapi/bitable/app-table-field.d.ts +16 -0
- package/src/tools/oapi/bitable/app-table-field.js +222 -0
- package/src/tools/oapi/bitable/app-table-record.d.ts +20 -0
- package/src/tools/oapi/bitable/app-table-record.js +436 -0
- package/src/tools/oapi/bitable/app-table-view.d.ts +17 -0
- package/src/tools/oapi/bitable/app-table-view.js +195 -0
- package/src/tools/oapi/bitable/app-table.d.ts +19 -0
- package/src/tools/oapi/bitable/app-table.js +247 -0
- package/src/tools/oapi/bitable/app.d.ts +18 -0
- package/src/tools/oapi/bitable/app.js +186 -0
- package/src/tools/oapi/bitable/index.d.ts +9 -0
- package/src/tools/oapi/bitable/index.js +9 -0
- package/src/tools/oapi/calendar/calendar.d.ts +15 -0
- package/src/tools/oapi/calendar/calendar.js +122 -0
- package/src/tools/oapi/calendar/event-attendee.d.ts +16 -0
- package/src/tools/oapi/calendar/event-attendee.js +263 -0
- package/src/tools/oapi/calendar/event.d.ts +16 -0
- package/src/tools/oapi/calendar/event.js +709 -0
- package/src/tools/oapi/calendar/freebusy.d.ts +13 -0
- package/src/tools/oapi/calendar/freebusy.js +111 -0
- package/src/tools/oapi/calendar/index.d.ts +8 -0
- package/src/tools/oapi/calendar/index.js +8 -0
- package/src/tools/oapi/chat/chat.d.ts +16 -0
- package/src/tools/oapi/chat/chat.js +124 -0
- package/src/tools/oapi/chat/index.d.ts +10 -0
- package/src/tools/oapi/chat/index.js +15 -0
- package/src/tools/oapi/chat/members.d.ts +11 -0
- package/src/tools/oapi/chat/members.js +81 -0
- package/src/tools/oapi/common/get-user.d.ts +12 -0
- package/src/tools/oapi/common/get-user.js +106 -0
- package/src/tools/oapi/common/index.d.ts +6 -0
- package/src/tools/oapi/common/index.js +6 -0
- package/src/tools/oapi/common/search-user.d.ts +11 -0
- package/src/tools/oapi/common/search-user.js +73 -0
- package/src/tools/oapi/drive/doc-comments.d.ts +15 -0
- package/src/tools/oapi/drive/doc-comments.js +279 -0
- package/src/tools/oapi/drive/doc-media.d.ts +19 -0
- package/src/tools/oapi/drive/doc-media.js +335 -0
- package/src/tools/oapi/drive/file.d.ts +19 -0
- package/src/tools/oapi/drive/file.js +483 -0
- package/src/tools/oapi/drive/index.d.ts +12 -0
- package/src/tools/oapi/drive/index.js +36 -0
- package/src/tools/oapi/helpers.d.ts +182 -0
- package/src/tools/oapi/helpers.js +354 -0
- package/src/tools/oapi/im/format-messages.d.ts +50 -0
- package/src/tools/oapi/im/format-messages.js +165 -0
- package/src/tools/oapi/im/index.d.ts +10 -0
- package/src/tools/oapi/im/index.js +17 -0
- package/src/tools/oapi/im/message-read.d.ts +13 -0
- package/src/tools/oapi/im/message-read.js +411 -0
- package/src/tools/oapi/im/message.d.ts +16 -0
- package/src/tools/oapi/im/message.js +149 -0
- package/src/tools/oapi/im/resource.d.ts +13 -0
- package/src/tools/oapi/im/resource.js +150 -0
- package/src/tools/oapi/im/time-utils.d.ts +46 -0
- package/src/tools/oapi/im/time-utils.js +201 -0
- package/src/tools/oapi/im/user-name-uat.d.ts +26 -0
- package/src/tools/oapi/im/user-name-uat.js +140 -0
- package/src/tools/oapi/index.d.ts +11 -0
- package/src/tools/oapi/index.js +58 -0
- package/src/tools/oapi/sdk-types.d.ts +96 -0
- package/src/tools/oapi/sdk-types.js +12 -0
- package/src/tools/oapi/search/doc-search.d.ts +13 -0
- package/src/tools/oapi/search/doc-search.js +191 -0
- package/src/tools/oapi/search/index.d.ts +12 -0
- package/src/tools/oapi/search/index.js +33 -0
- package/src/tools/oapi/sheets/index.d.ts +12 -0
- package/src/tools/oapi/sheets/index.js +31 -0
- package/src/tools/oapi/sheets/sheet.d.ts +16 -0
- package/src/tools/oapi/sheets/sheet.js +652 -0
- package/src/tools/oapi/task/comment.d.ts +15 -0
- package/src/tools/oapi/task/comment.js +140 -0
- package/src/tools/oapi/task/index.d.ts +8 -0
- package/src/tools/oapi/task/index.js +8 -0
- package/src/tools/oapi/task/subtask.d.ts +14 -0
- package/src/tools/oapi/task/subtask.js +162 -0
- package/src/tools/oapi/task/task.d.ts +16 -0
- package/src/tools/oapi/task/task.js +344 -0
- package/src/tools/oapi/task/tasklist.d.ts +21 -0
- package/src/tools/oapi/task/tasklist.js +321 -0
- package/src/tools/oapi/wiki/index.d.ts +12 -0
- package/src/tools/oapi/wiki/index.js +34 -0
- package/src/tools/oapi/wiki/space-node.d.ts +17 -0
- package/src/tools/oapi/wiki/space-node.js +230 -0
- package/src/tools/oapi/wiki/space.d.ts +15 -0
- package/src/tools/oapi/wiki/space.js +130 -0
- package/src/tools/oauth-batch-auth.d.ts +11 -0
- package/src/tools/oauth-batch-auth.js +142 -0
- package/src/tools/oauth-cards.d.ts +39 -0
- package/src/tools/oauth-cards.js +315 -0
- package/src/tools/oauth.d.ts +47 -0
- package/src/tools/oauth.js +620 -0
- package/src/tools/onboarding-auth.d.ts +27 -0
- package/src/tools/onboarding-auth.js +130 -0
- package/src/tools/tat/im/index.d.ts +15 -0
- package/src/tools/tat/im/index.js +18 -0
- package/src/tools/tat/im/resource.d.ts +15 -0
- package/src/tools/tat/im/resource.js +157 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Message fetching for the Lark/Feishu channel plugin.
|
|
6
|
+
*
|
|
7
|
+
* Shared between inbound (reaction handler, enrich) and outbound modules.
|
|
8
|
+
* Extracted from `outbound/fetch.ts` to eliminate inbound→outbound
|
|
9
|
+
* dependency inversion.
|
|
10
|
+
*/
|
|
11
|
+
import { convertMessageContent, buildConvertContextFromItem } from '../converters/content-converter';
|
|
12
|
+
import { LarkClient } from '../../core/lark-client';
|
|
13
|
+
import { larkLogger } from '../../core/lark-logger';
|
|
14
|
+
const log = larkLogger('shared/message-lookup');
|
|
15
|
+
import { getUserNameCache, createBatchResolveNames } from '../inbound/user-name-cache';
|
|
16
|
+
import { getLarkAccount } from '../../core/accounts';
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// getMessageFeishu
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/**
|
|
21
|
+
* Retrieve a single message by its ID from the Feishu IM API.
|
|
22
|
+
*
|
|
23
|
+
* Returns a normalised {@link FeishuMessageInfo} object, or `null` if the
|
|
24
|
+
* message cannot be found or the API returns an error.
|
|
25
|
+
*
|
|
26
|
+
* @param params.cfg - Plugin configuration with Feishu credentials.
|
|
27
|
+
* @param params.messageId - The message ID to fetch.
|
|
28
|
+
* @param params.accountId - Optional account identifier for multi-account setups.
|
|
29
|
+
*/
|
|
30
|
+
export async function getMessageFeishu(params) {
|
|
31
|
+
const { cfg, messageId, accountId, expandForward } = params;
|
|
32
|
+
const larkClient = LarkClient.fromCfg(cfg, accountId);
|
|
33
|
+
const sdk = larkClient.sdk;
|
|
34
|
+
try {
|
|
35
|
+
const requestOpts = {
|
|
36
|
+
method: 'GET',
|
|
37
|
+
url: `/open-apis/im/v1/messages/mget`,
|
|
38
|
+
params: {
|
|
39
|
+
message_ids: messageId,
|
|
40
|
+
user_id_type: 'open_id',
|
|
41
|
+
card_msg_content_type: 'raw_card_content',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
const response = await sdk.request(requestOpts);
|
|
46
|
+
const items = response?.data?.items;
|
|
47
|
+
if (!items || items.length === 0) {
|
|
48
|
+
log.info(`getMessageFeishu: no items returned for ${messageId}`);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const expandCtx = expandForward
|
|
52
|
+
? {
|
|
53
|
+
cfg,
|
|
54
|
+
accountId,
|
|
55
|
+
fetchSubMessages: async (msgId) => {
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
+
const res = await larkClient.sdk.request({
|
|
58
|
+
method: 'GET',
|
|
59
|
+
url: `/open-apis/im/v1/messages/${msgId}`,
|
|
60
|
+
params: { user_id_type: 'open_id', card_msg_content_type: 'raw_card_content' },
|
|
61
|
+
});
|
|
62
|
+
if (res?.code !== 0) {
|
|
63
|
+
throw new Error(`API error: code=${res?.code} msg=${res?.msg}`);
|
|
64
|
+
}
|
|
65
|
+
return res?.data?.items ?? [];
|
|
66
|
+
},
|
|
67
|
+
batchResolveNames: createBatchResolveNames(getLarkAccount(cfg, accountId), (...args) => log.info(args.map(String).join(' '))),
|
|
68
|
+
}
|
|
69
|
+
: undefined;
|
|
70
|
+
return await parseMessageItem(items[0], messageId, expandCtx);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
log.error(`get message failed (${messageId}): ${error instanceof Error ? error.message : String(error)}`);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Helpers
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
/**
|
|
81
|
+
* Parse a single message item from the Feishu IM API response into a
|
|
82
|
+
* normalised {@link FeishuMessageInfo}.
|
|
83
|
+
*
|
|
84
|
+
* Content parsing is delegated to the shared converter system so that
|
|
85
|
+
* every message-type mapping is defined in exactly one place.
|
|
86
|
+
*/
|
|
87
|
+
async function parseMessageItem(
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
+
msg, fallbackMessageId, expandCtx) {
|
|
90
|
+
const msgType = msg.msg_type ?? 'text';
|
|
91
|
+
const rawContent = msg.body?.content ?? '{}';
|
|
92
|
+
const messageId = msg.message_id ?? fallbackMessageId;
|
|
93
|
+
const acctId = expandCtx?.accountId;
|
|
94
|
+
const ctx = {
|
|
95
|
+
...buildConvertContextFromItem(msg, fallbackMessageId, acctId),
|
|
96
|
+
cfg: expandCtx?.cfg,
|
|
97
|
+
accountId: acctId,
|
|
98
|
+
fetchSubMessages: expandCtx?.fetchSubMessages,
|
|
99
|
+
batchResolveNames: expandCtx?.batchResolveNames,
|
|
100
|
+
};
|
|
101
|
+
const { content } = await convertMessageContent(rawContent, msgType, ctx);
|
|
102
|
+
const senderId = msg.sender?.id ?? undefined;
|
|
103
|
+
const senderType = msg.sender?.sender_type ?? undefined;
|
|
104
|
+
const senderName = senderId && acctId ? getUserNameCache(acctId).get(senderId) : undefined;
|
|
105
|
+
return {
|
|
106
|
+
messageId,
|
|
107
|
+
chatId: msg.chat_id ?? '',
|
|
108
|
+
chatType: msg.chat_type ?? undefined,
|
|
109
|
+
senderId,
|
|
110
|
+
senderName,
|
|
111
|
+
senderType,
|
|
112
|
+
content,
|
|
113
|
+
contentType: msgType,
|
|
114
|
+
createTime: msg.create_time ? parseInt(String(msg.create_time), 10) : undefined,
|
|
115
|
+
threadId: msg.thread_id || undefined,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Messaging type definitions for the Lark/Feishu channel plugin.
|
|
6
|
+
*
|
|
7
|
+
* Pure shape types for inbound message events, normalised message context,
|
|
8
|
+
* mention targets, and media metadata.
|
|
9
|
+
*/
|
|
10
|
+
export interface FeishuMessageEvent {
|
|
11
|
+
sender: {
|
|
12
|
+
sender_id: {
|
|
13
|
+
open_id?: string;
|
|
14
|
+
user_id?: string;
|
|
15
|
+
union_id?: string;
|
|
16
|
+
};
|
|
17
|
+
sender_type?: string;
|
|
18
|
+
tenant_key?: string;
|
|
19
|
+
};
|
|
20
|
+
message: {
|
|
21
|
+
message_id: string;
|
|
22
|
+
root_id?: string;
|
|
23
|
+
parent_id?: string;
|
|
24
|
+
create_time?: string;
|
|
25
|
+
update_time?: string;
|
|
26
|
+
chat_id: string;
|
|
27
|
+
thread_id?: string;
|
|
28
|
+
chat_type: 'p2p' | 'group';
|
|
29
|
+
message_type: string;
|
|
30
|
+
content: string;
|
|
31
|
+
mentions?: Array<{
|
|
32
|
+
key: string;
|
|
33
|
+
id: {
|
|
34
|
+
open_id?: string;
|
|
35
|
+
user_id?: string;
|
|
36
|
+
union_id?: string;
|
|
37
|
+
};
|
|
38
|
+
name: string;
|
|
39
|
+
tenant_key?: string;
|
|
40
|
+
}>;
|
|
41
|
+
user_agent?: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface FeishuReactionCreatedEvent {
|
|
45
|
+
message_id: string;
|
|
46
|
+
chat_id?: string;
|
|
47
|
+
chat_type?: 'p2p' | 'group' | 'private';
|
|
48
|
+
reaction_type?: {
|
|
49
|
+
emoji_type?: string;
|
|
50
|
+
};
|
|
51
|
+
operator_type?: string;
|
|
52
|
+
user_id?: {
|
|
53
|
+
open_id?: string;
|
|
54
|
+
user_id?: string;
|
|
55
|
+
union_id?: string;
|
|
56
|
+
};
|
|
57
|
+
action_time?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface FeishuBotAddedEvent {
|
|
60
|
+
chat_id: string;
|
|
61
|
+
operator_id: {
|
|
62
|
+
open_id?: string;
|
|
63
|
+
user_id?: string;
|
|
64
|
+
union_id?: string;
|
|
65
|
+
};
|
|
66
|
+
external: boolean;
|
|
67
|
+
operator_tenant_key?: string;
|
|
68
|
+
name?: string;
|
|
69
|
+
i18n_names?: {
|
|
70
|
+
zh_cn?: string;
|
|
71
|
+
en_us?: string;
|
|
72
|
+
ja_jp?: string;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** Metadata describing a media resource in a message (no binary data). */
|
|
76
|
+
export interface ResourceDescriptor {
|
|
77
|
+
type: 'image' | 'file' | 'audio' | 'video' | 'sticker';
|
|
78
|
+
/** image_key or file_key from the raw message content. */
|
|
79
|
+
fileKey: string;
|
|
80
|
+
/** Original file name (file/video messages). */
|
|
81
|
+
fileName?: string;
|
|
82
|
+
/** Duration in milliseconds (audio/video messages). */
|
|
83
|
+
duration?: number;
|
|
84
|
+
/** Video cover image key. */
|
|
85
|
+
coverImageKey?: string;
|
|
86
|
+
}
|
|
87
|
+
/** Structured @mention information from a message. */
|
|
88
|
+
export interface MentionInfo {
|
|
89
|
+
/** Placeholder key in raw content (e.g. "@_user_1"). */
|
|
90
|
+
key: string;
|
|
91
|
+
/** Feishu Open ID of the mentioned user. */
|
|
92
|
+
openId: string;
|
|
93
|
+
/** Display name. */
|
|
94
|
+
name: string;
|
|
95
|
+
/** Whether this mention targets the bot itself. */
|
|
96
|
+
isBot: boolean;
|
|
97
|
+
}
|
|
98
|
+
/** Raw message body, directly mapped from FeishuMessageEvent.message. */
|
|
99
|
+
export interface RawMessage {
|
|
100
|
+
message_id: string;
|
|
101
|
+
root_id?: string;
|
|
102
|
+
parent_id?: string;
|
|
103
|
+
create_time?: string;
|
|
104
|
+
update_time?: string;
|
|
105
|
+
chat_id: string;
|
|
106
|
+
thread_id?: string;
|
|
107
|
+
chat_type: 'p2p' | 'group';
|
|
108
|
+
message_type: string;
|
|
109
|
+
content: string;
|
|
110
|
+
mentions?: Array<{
|
|
111
|
+
key: string;
|
|
112
|
+
id: {
|
|
113
|
+
open_id?: string;
|
|
114
|
+
user_id?: string;
|
|
115
|
+
union_id?: string;
|
|
116
|
+
};
|
|
117
|
+
name: string;
|
|
118
|
+
tenant_key?: string;
|
|
119
|
+
}>;
|
|
120
|
+
user_agent?: string;
|
|
121
|
+
}
|
|
122
|
+
/** Raw sender data, directly mapped from FeishuMessageEvent.sender. */
|
|
123
|
+
export interface RawSender {
|
|
124
|
+
sender_id: {
|
|
125
|
+
open_id?: string;
|
|
126
|
+
user_id?: string;
|
|
127
|
+
union_id?: string;
|
|
128
|
+
};
|
|
129
|
+
sender_type?: string;
|
|
130
|
+
tenant_key?: string;
|
|
131
|
+
}
|
|
132
|
+
/** Normalised representation of an inbound Feishu message. */
|
|
133
|
+
export interface MessageContext {
|
|
134
|
+
chatId: string;
|
|
135
|
+
messageId: string;
|
|
136
|
+
senderId: string;
|
|
137
|
+
senderName?: string;
|
|
138
|
+
chatType: 'p2p' | 'group';
|
|
139
|
+
content: string;
|
|
140
|
+
contentType: string;
|
|
141
|
+
/** Media resource descriptors extracted during parsing. */
|
|
142
|
+
resources: ResourceDescriptor[];
|
|
143
|
+
/** All @mentions in the message (including bot). */
|
|
144
|
+
mentions: MentionInfo[];
|
|
145
|
+
rootId?: string;
|
|
146
|
+
parentId?: string;
|
|
147
|
+
threadId?: string;
|
|
148
|
+
createTime?: number;
|
|
149
|
+
rawMessage: RawMessage;
|
|
150
|
+
rawSender: RawSender;
|
|
151
|
+
}
|
|
152
|
+
/** @deprecated Use {@link MessageContext} instead. */
|
|
153
|
+
export type FeishuMessageContext = MessageContext;
|
|
154
|
+
/** Metadata about a media attachment received in or sent through Feishu. */
|
|
155
|
+
export interface FeishuMediaInfo {
|
|
156
|
+
path: string;
|
|
157
|
+
contentType?: string;
|
|
158
|
+
placeholder: string;
|
|
159
|
+
/** Original Feishu file_key / image_key that was downloaded. */
|
|
160
|
+
fileKey: string;
|
|
161
|
+
/** Resource type from the original descriptor. */
|
|
162
|
+
resourceType: ResourceDescriptor['type'];
|
|
163
|
+
}
|
|
164
|
+
/** Result of sending a message via the Feishu API. */
|
|
165
|
+
export interface FeishuSendResult {
|
|
166
|
+
messageId: string;
|
|
167
|
+
chatId: string;
|
|
168
|
+
/**
|
|
169
|
+
* Human-readable warning when the send succeeded but with degradation
|
|
170
|
+
* (e.g. media upload failed, fell back to a text link).
|
|
171
|
+
*
|
|
172
|
+
* Populated so upstream callers (and the AI) can detect that the
|
|
173
|
+
* delivery was not fully as intended and take corrective action.
|
|
174
|
+
*/
|
|
175
|
+
warning?: string;
|
|
176
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Messaging type definitions for the Lark/Feishu channel plugin.
|
|
6
|
+
*
|
|
7
|
+
* Pure shape types for inbound message events, normalised message context,
|
|
8
|
+
* mention targets, and media metadata.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* auto-auth.ts — 工具层自动授权处理。
|
|
6
|
+
*
|
|
7
|
+
* 当 OAPI 工具遇到授权问题时,直接在工具层处理,不再让 AI 判断:
|
|
8
|
+
*
|
|
9
|
+
* - UserAuthRequiredError (appScopeVerified=true)
|
|
10
|
+
* → 直接调用 executeAuthorize 发起 OAuth Device Flow 卡片
|
|
11
|
+
*
|
|
12
|
+
* - UserScopeInsufficientError
|
|
13
|
+
* → 直接调用 executeAuthorize(使用 missingScopes)
|
|
14
|
+
*
|
|
15
|
+
* - AppScopeMissingError
|
|
16
|
+
* → 发送应用权限引导卡片;用户点击"我已完成"后:
|
|
17
|
+
* 1. 更新卡片为处理中状态
|
|
18
|
+
* 2. invalidateAppScopeCache
|
|
19
|
+
* 3. 发送中间合成消息告知 AI("应用权限已确认,正在发起用户授权...")
|
|
20
|
+
* 4. 调用 executeAuthorize 发起 OAuth Device Flow
|
|
21
|
+
*
|
|
22
|
+
* - 其他情况(AppScopeCheckFailedError、appScopeVerified=false 等)
|
|
23
|
+
* → 回退到原 handleInvokeError(不触发自动授权)
|
|
24
|
+
*
|
|
25
|
+
* 降级策略(保守):以下情况均回退到 handleInvokeError:
|
|
26
|
+
* - 无 LarkTicket(非消息场景)
|
|
27
|
+
* - 无 senderOpenId(无法确定授权对象)
|
|
28
|
+
* - 账号未配置(!acct.configured)
|
|
29
|
+
* - 任何步骤抛出异常
|
|
30
|
+
*/
|
|
31
|
+
import type { ClawdbotConfig } from 'openclaw/plugin-sdk';
|
|
32
|
+
/**
|
|
33
|
+
* 处理 card.action.trigger 回调事件(由 monitor.ts 调用)。
|
|
34
|
+
*
|
|
35
|
+
* 当用户点击应用权限引导卡片的"我已完成,继续授权"按钮时:
|
|
36
|
+
* 1. 更新卡片为"处理中"状态
|
|
37
|
+
* 2. 清除应用 scope 缓存
|
|
38
|
+
* 3. 发送中间合成消息告知 AI
|
|
39
|
+
* 4. 发起 OAuth Device Flow
|
|
40
|
+
*
|
|
41
|
+
* 注意:函数体内的主要逻辑通过 setImmediate + fire-and-forget 异步执行,
|
|
42
|
+
* 确保 Feishu card.action.trigger 回调在 3 秒内返回。
|
|
43
|
+
*/
|
|
44
|
+
export declare function handleCardAction(data: unknown, cfg: ClawdbotConfig, accountId: string): Promise<unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* 统一处理 `client.invoke()` 抛出的错误,支持自动发起 OAuth 授权。
|
|
47
|
+
*
|
|
48
|
+
* 替代 `handleInvokeError`,在工具层直接处理授权问题:
|
|
49
|
+
* - 用户授权类错误 → 直接 executeAuthorize(发 Device Flow 卡片)
|
|
50
|
+
* - 应用权限缺失 → 发送引导卡片,用户确认后自动接力 OAuth
|
|
51
|
+
* - 其他错误 → 回退到 handleInvokeError 的标准处理
|
|
52
|
+
*
|
|
53
|
+
* @param err - invoke() 或其他逻辑抛出的错误
|
|
54
|
+
* @param cfg - OpenClaw 配置对象(从工具注册函数的闭包中获取)
|
|
55
|
+
*/
|
|
56
|
+
export declare function handleInvokeErrorWithAutoAuth(err: unknown, cfg: ClawdbotConfig): Promise<import("./helpers").ToolResult>;
|