mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 02:22:54 +00:00
fix(feishu): use full gateway channel runtime
This commit is contained in:
@@ -3704,7 +3704,7 @@ describe("createFeishuMessageReceiveHandler media dedupe", () => {
|
||||
});
|
||||
const handler = createFeishuMessageReceiveHandler({
|
||||
cfg: { channels: { feishu: { dmPolicy: "open" } } } as ClawdbotConfig,
|
||||
core,
|
||||
channelRuntime: core.channel,
|
||||
accountId: "receive-media-dedupe",
|
||||
chatHistories: new Map(),
|
||||
handleMessage,
|
||||
|
||||
@@ -440,6 +440,7 @@ export async function handleFeishuMessage(params: {
|
||||
botOpenId?: string;
|
||||
botName?: string;
|
||||
runtime?: RuntimeEnv;
|
||||
channelRuntime?: ReturnType<typeof getFeishuRuntime>["channel"];
|
||||
chatHistories?: Map<string, HistoryEntry[]>;
|
||||
accountId?: string;
|
||||
processingClaimHeld?: boolean;
|
||||
@@ -450,6 +451,7 @@ export async function handleFeishuMessage(params: {
|
||||
botOpenId,
|
||||
botName,
|
||||
runtime,
|
||||
channelRuntime,
|
||||
chatHistories,
|
||||
accountId,
|
||||
processingClaimHeld = false,
|
||||
@@ -709,7 +711,9 @@ export async function handleFeishuMessage(params: {
|
||||
}
|
||||
|
||||
try {
|
||||
const core = getFeishuRuntime();
|
||||
const core = {
|
||||
channel: channelRuntime ?? getFeishuRuntime().channel,
|
||||
} as ReturnType<typeof getFeishuRuntime>;
|
||||
const pairing = createChannelPairingController({
|
||||
core,
|
||||
channel: "feishu",
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
isFutureDateTimestampMs,
|
||||
resolveExpiresAtMsFromDurationMs,
|
||||
} from "openclaw/plugin-sdk/number-runtime";
|
||||
import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
|
||||
import type { ClawdbotConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
|
||||
import { resolveFeishuRuntimeAccount } from "./accounts.js";
|
||||
import { handleFeishuMessage, type FeishuMessageEvent } from "./bot.js";
|
||||
import { decodeFeishuCardAction, buildFeishuCardActionTextFallback } from "./card-interaction.js";
|
||||
@@ -170,6 +170,7 @@ async function dispatchSyntheticCommand(params: {
|
||||
account: ReturnType<typeof resolveFeishuRuntimeAccount>;
|
||||
botOpenId?: string;
|
||||
runtime?: RuntimeEnv;
|
||||
channelRuntime?: PluginRuntime["channel"];
|
||||
accountId?: string;
|
||||
chatType?: "p2p" | "group";
|
||||
}): Promise<void> {
|
||||
@@ -184,6 +185,7 @@ async function dispatchSyntheticCommand(params: {
|
||||
event: buildSyntheticMessageEvent(params.event, params.command, resolvedChatType),
|
||||
botOpenId: params.botOpenId,
|
||||
runtime: params.runtime,
|
||||
channelRuntime: params.channelRuntime,
|
||||
accountId: params.accountId,
|
||||
});
|
||||
}
|
||||
@@ -342,6 +344,7 @@ export async function handleFeishuCardAction(params: {
|
||||
event: FeishuCardActionEvent;
|
||||
botOpenId?: string;
|
||||
runtime?: RuntimeEnv;
|
||||
channelRuntime?: PluginRuntime["channel"];
|
||||
accountId?: string;
|
||||
}): Promise<void> {
|
||||
const { cfg, event, runtime, accountId } = params;
|
||||
@@ -465,6 +468,7 @@ export async function handleFeishuCardAction(params: {
|
||||
account,
|
||||
botOpenId: params.botOpenId,
|
||||
runtime,
|
||||
channelRuntime: params.channelRuntime,
|
||||
accountId,
|
||||
chatType: envelope.c?.t,
|
||||
});
|
||||
@@ -495,6 +499,7 @@ export async function handleFeishuCardAction(params: {
|
||||
account,
|
||||
botOpenId: params.botOpenId,
|
||||
runtime,
|
||||
channelRuntime: params.channelRuntime,
|
||||
accountId,
|
||||
});
|
||||
completeFeishuCardActionToken({ token: event.token, accountId: account.accountId });
|
||||
|
||||
@@ -31,6 +31,7 @@ import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
|
||||
import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
|
||||
import { createComputedAccountStatusAdapter } from "openclaw/plugin-sdk/status-helpers";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
import type { PluginRuntime } from "../runtime-api.js";
|
||||
import {
|
||||
inspectFeishuCredentials,
|
||||
listEnabledFeishuAccounts,
|
||||
@@ -1319,6 +1320,9 @@ export const feishuPlugin: ChannelPlugin<ResolvedFeishuAccount, FeishuProbeResul
|
||||
return monitorFeishuProvider({
|
||||
config: ctx.cfg,
|
||||
runtime: ctx.runtime,
|
||||
// Gateway provides the full channel runtime here; the public SDK type
|
||||
// stays context-only for external compatibility.
|
||||
channelRuntime: ctx.channelRuntime as PluginRuntime["channel"] | undefined,
|
||||
abortSignal: ctx.abortSignal,
|
||||
accountId: ctx.accountId,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as crypto from "node:crypto";
|
||||
import type * as Lark from "@larksuiteoapi/node-sdk";
|
||||
import type { ClawdbotConfig, RuntimeEnv, HistoryEntry } from "../runtime-api.js";
|
||||
import type { ClawdbotConfig, PluginRuntime, RuntimeEnv, HistoryEntry } from "../runtime-api.js";
|
||||
import { raceWithTimeoutAndAbort } from "./async.js";
|
||||
import {
|
||||
handleFeishuMessage,
|
||||
@@ -164,6 +164,7 @@ function normalizeFeishuChatType(value: unknown): FeishuChatType | undefined {
|
||||
type RegisterEventHandlersContext = {
|
||||
cfg: ClawdbotConfig;
|
||||
accountId: string;
|
||||
channelRuntime: PluginRuntime["channel"];
|
||||
runtime?: RuntimeEnv;
|
||||
chatHistories: Map<string, HistoryEntry[]>;
|
||||
fireAndForget?: boolean;
|
||||
@@ -266,7 +267,7 @@ function registerEventHandlers(
|
||||
eventDispatcher: Lark.EventDispatcher,
|
||||
context: RegisterEventHandlersContext,
|
||||
): void {
|
||||
const { cfg, accountId, runtime, chatHistories, fireAndForget } = context;
|
||||
const { cfg, accountId, channelRuntime, runtime, chatHistories, fireAndForget } = context;
|
||||
const log = runtime?.log ?? console.log;
|
||||
const error = runtime?.error ?? console.error;
|
||||
const runFeishuHandler = async (params: { task: () => Promise<void>; errorMessage: string }) => {
|
||||
@@ -286,7 +287,7 @@ function registerEventHandlers(
|
||||
eventDispatcher.register({
|
||||
"im.message.receive_v1": createFeishuMessageReceiveHandler({
|
||||
cfg,
|
||||
core: getFeishuRuntime(),
|
||||
channelRuntime,
|
||||
accountId,
|
||||
runtime,
|
||||
chatHistories,
|
||||
@@ -353,6 +354,7 @@ function registerEventHandlers(
|
||||
botOpenId: myBotId,
|
||||
botName: botNames.get(accountId),
|
||||
runtime,
|
||||
channelRuntime,
|
||||
chatHistories,
|
||||
accountId,
|
||||
});
|
||||
@@ -383,6 +385,7 @@ function registerEventHandlers(
|
||||
botOpenId: myBotId,
|
||||
botName: botNames.get(accountId),
|
||||
runtime,
|
||||
channelRuntime,
|
||||
chatHistories,
|
||||
accountId,
|
||||
});
|
||||
@@ -396,6 +399,7 @@ function registerEventHandlers(
|
||||
runtime,
|
||||
chatHistories,
|
||||
fireAndForget,
|
||||
channelRuntime,
|
||||
}),
|
||||
"card.action.trigger": async (data: unknown) => {
|
||||
try {
|
||||
@@ -409,6 +413,7 @@ function registerEventHandlers(
|
||||
event,
|
||||
botOpenId: botOpenIds.get(accountId),
|
||||
runtime,
|
||||
channelRuntime,
|
||||
accountId,
|
||||
});
|
||||
if (fireAndForget) {
|
||||
@@ -432,6 +437,7 @@ export type BotOpenIdSource =
|
||||
export type MonitorSingleAccountParams = {
|
||||
cfg: ClawdbotConfig;
|
||||
account: ResolvedFeishuAccount;
|
||||
channelRuntime?: PluginRuntime["channel"];
|
||||
runtime?: RuntimeEnv;
|
||||
abortSignal?: AbortSignal;
|
||||
botOpenIdSource?: BotOpenIdSource;
|
||||
@@ -473,10 +479,12 @@ export async function monitorSingleAccount(params: MonitorSingleAccountParams):
|
||||
const eventDispatcher = createEventDispatcher(account);
|
||||
const chatHistories = new Map<string, HistoryEntry[]>();
|
||||
threadBindingManager = createFeishuThreadBindingManager({ accountId, cfg });
|
||||
const channelRuntime = params.channelRuntime ?? getFeishuRuntime().channel;
|
||||
|
||||
registerEventHandlers(eventDispatcher, {
|
||||
cfg,
|
||||
accountId,
|
||||
channelRuntime,
|
||||
runtime,
|
||||
chatHistories,
|
||||
fireAndForget: params.fireAndForget ?? true,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { isRecord, readStringValue as readString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
import type { ClawdbotConfig, HistoryEntry, RuntimeEnv } from "../runtime-api.js";
|
||||
import type { ClawdbotConfig, HistoryEntry, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
|
||||
import { handleFeishuMessage, type FeishuMessageEvent } from "./bot.js";
|
||||
import { maybeHandleFeishuQuickActionMenu } from "./card-ux-launcher.js";
|
||||
import {
|
||||
@@ -54,6 +54,7 @@ export function createFeishuBotMenuHandler(params: {
|
||||
cfg: ClawdbotConfig;
|
||||
accountId: string;
|
||||
runtime?: RuntimeEnv;
|
||||
channelRuntime?: PluginRuntime["channel"];
|
||||
chatHistories: Map<string, HistoryEntry[]>;
|
||||
fireAndForget?: boolean;
|
||||
getBotOpenId?: (accountId: string) => string | undefined;
|
||||
@@ -117,6 +118,7 @@ export function createFeishuBotMenuHandler(params: {
|
||||
botOpenId: getBotOpenId(accountId),
|
||||
botName: getBotName(accountId),
|
||||
runtime,
|
||||
channelRuntime: params.channelRuntime,
|
||||
chatHistories,
|
||||
accountId,
|
||||
processingClaimHeld: true,
|
||||
|
||||
@@ -12,7 +12,7 @@ import type { FeishuChatType } from "./types.js";
|
||||
|
||||
type FeishuMessageReceiveHandlerContext = {
|
||||
cfg: ClawdbotConfig;
|
||||
core: PluginRuntime;
|
||||
channelRuntime: PluginRuntime["channel"];
|
||||
accountId: string;
|
||||
runtime?: RuntimeEnv;
|
||||
chatHistories: Map<string, HistoryEntry[]>;
|
||||
@@ -23,6 +23,7 @@ type FeishuMessageReceiveHandlerContext = {
|
||||
botOpenId?: string;
|
||||
botName?: string;
|
||||
runtime?: RuntimeEnv;
|
||||
channelRuntime?: PluginRuntime["channel"];
|
||||
chatHistories?: Map<string, HistoryEntry[]>;
|
||||
accountId?: string;
|
||||
processingClaimHeld?: boolean;
|
||||
@@ -154,7 +155,7 @@ function resolveFeishuDebounceMentions(params: {
|
||||
|
||||
export function createFeishuMessageReceiveHandler({
|
||||
cfg,
|
||||
core,
|
||||
channelRuntime,
|
||||
accountId,
|
||||
runtime,
|
||||
chatHistories,
|
||||
@@ -168,7 +169,7 @@ export function createFeishuMessageReceiveHandler({
|
||||
resolveSequentialKey = ({ accountId, event }) =>
|
||||
`feishu:${accountId}:${event.message.chat_id?.trim() || "unknown"}`,
|
||||
}: FeishuMessageReceiveHandlerContext): (data: unknown) => Promise<void> {
|
||||
const inboundDebounceMs = core.channel.debounce.resolveInboundDebounceMs({
|
||||
const inboundDebounceMs = channelRuntime.debounce.resolveInboundDebounceMs({
|
||||
cfg,
|
||||
channel: "feishu",
|
||||
});
|
||||
@@ -196,6 +197,7 @@ export function createFeishuMessageReceiveHandler({
|
||||
botOpenId: getBotOpenId(accountId),
|
||||
botName: getBotName(accountId),
|
||||
runtime,
|
||||
channelRuntime,
|
||||
chatHistories,
|
||||
accountId,
|
||||
processingClaimHeld: true,
|
||||
@@ -238,7 +240,7 @@ export function createFeishuMessageReceiveHandler({
|
||||
}
|
||||
};
|
||||
|
||||
const inboundDebouncer = core.channel.debounce.createInboundDebouncer<FeishuMessageEvent>({
|
||||
const inboundDebouncer = channelRuntime.debounce.createInboundDebouncer<FeishuMessageEvent>({
|
||||
debounceMs: inboundDebounceMs,
|
||||
buildKey: (event) => {
|
||||
const chatId = event.message.chat_id?.trim();
|
||||
@@ -255,7 +257,7 @@ export function createFeishuMessageReceiveHandler({
|
||||
return false;
|
||||
}
|
||||
const text = resolveDebounceText(event);
|
||||
return Boolean(text) && !core.channel.commands.isControlCommandMessage(text, cfg);
|
||||
return Boolean(text) && !channelRuntime.commands.isControlCommandMessage(text, cfg);
|
||||
},
|
||||
onFlush: async (entries) => {
|
||||
const last = entries.at(-1);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
|
||||
import type { ClawdbotConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
|
||||
import { listEnabledFeishuAccounts, resolveFeishuRuntimeAccount } from "./accounts.js";
|
||||
import { fetchBotIdentityForMonitor } from "./monitor.startup.js";
|
||||
import {
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
export type MonitorFeishuOpts = {
|
||||
config?: ClawdbotConfig;
|
||||
runtime?: RuntimeEnv;
|
||||
channelRuntime?: PluginRuntime["channel"];
|
||||
abortSignal?: AbortSignal;
|
||||
accountId?: string;
|
||||
};
|
||||
@@ -48,6 +49,7 @@ export async function monitorFeishuProvider(opts: MonitorFeishuOpts = {}): Promi
|
||||
return monitorSingleAccount({
|
||||
cfg,
|
||||
account,
|
||||
channelRuntime: opts.channelRuntime,
|
||||
runtime: opts.runtime,
|
||||
abortSignal: opts.abortSignal,
|
||||
});
|
||||
@@ -85,6 +87,7 @@ export async function monitorFeishuProvider(opts: MonitorFeishuOpts = {}): Promi
|
||||
monitorSingleAccount({
|
||||
cfg,
|
||||
account,
|
||||
channelRuntime: opts.channelRuntime,
|
||||
runtime: opts.runtime,
|
||||
abortSignal: opts.abortSignal,
|
||||
botOpenIdSource: { kind: "prefetched", botOpenId, botName },
|
||||
|
||||
Reference in New Issue
Block a user