


























@@ -2,10 +2,7 @@ import { createHash } from "node:crypto";
22import fs from "node:fs";
33import type { Message } from "grammy/types";
44import { formatLocationText } from "openclaw/plugin-sdk/channel-inbound";
5-import {
6-parseStrictNonNegativeInteger,
7-parseStrictPositiveInteger,
8-} from "openclaw/plugin-sdk/number-runtime";
5+import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
96import type { MsgContext } from "openclaw/plugin-sdk/reply-runtime";
107import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
118import { appendRegularFileSync, replaceFileAtomicSync } from "openclaw/plugin-sdk/security-runtime";
@@ -17,6 +14,7 @@ import {
1714getTelegramTextParts,
1815normalizeForwardedContext,
1916} from "./bot/helpers.js";
17+import { parseTelegramMessageThreadId } from "./outbound-params.js";
2018import { getOptionalTelegramRuntime } from "./runtime.js";
21192220export type TelegramReplyChainEntry = NonNullable<MsgContext["ReplyChain"]>[number];
@@ -166,6 +164,7 @@ function normalizeMessageNode(
166164const forwardedFrom = normalizeForwardedContext(msg);
167165const replyMessage = resolveReplyMessage(msg);
168166const body = resolveMessageBody(msg);
167+const threadId = normalizeTelegramCacheThreadId(params.threadId);
169168return {
170169sourceMessage: msg,
171170messageId: String(msg.message_id),
@@ -181,7 +180,7 @@ function normalizeMessageNode(
181180 ...(forwardedFrom?.fromId ? { forwardedFromId: forwardedFrom.fromId } : {}),
182181 ...(forwardedFrom?.fromUsername ? { forwardedFromUsername: forwardedFrom.fromUsername } : {}),
183182 ...(forwardedFrom?.date ? { forwardedDate: forwardedFrom.date * 1000 } : {}),
184- ...(params.threadId != null ? { threadId: String(params.threadId) } : {}),
183+ ...(threadId !== undefined ? { threadId: String(threadId) } : {}),
185184};
186185}
187186@@ -198,9 +197,7 @@ function normalizeRequiredMessageNode(
198197199198function resolveMessageThreadId(msg: Message): number | undefined {
200199const threadId = (msg as { message_thread_id?: unknown }).message_thread_id;
201-return typeof threadId === "number" && Number.isFinite(threadId)
202- ? Math.trunc(threadId)
203- : undefined;
200+return normalizeTelegramCacheThreadId(threadId);
204201}
205202206203function normalizeMessageNodes(
@@ -246,7 +243,11 @@ function parseSafeMessageId(value: string | undefined): number | undefined {
246243}
247244248245function parseCachedThreadId(value: unknown): number | undefined {
249-return parseStrictNonNegativeInteger(value);
246+return normalizeTelegramCacheThreadId(value);
247+}
248+249+function normalizeTelegramCacheThreadId(value: unknown): number | undefined {
250+return parseTelegramMessageThreadId(value);
250251}
251252252253function isTelegramSourceMessage(value: unknown): value is Message {
@@ -754,7 +755,11 @@ export function createTelegramMessageCache(params?: {
754755}) => {
755756await hydrateMessageCacheBucket(bucket, maxMessages, scopeKey);
756757const prefix = telegramMessageCacheKeyPrefix({ scopeKey, ...params });
757-const threadId = params.threadId != null ? String(params.threadId) : undefined;
758+const normalizedThreadId = normalizeTelegramCacheThreadId(params.threadId);
759+if (params.threadId != null && normalizedThreadId === undefined) {
760+return [];
761+}
762+const threadId = normalizedThreadId !== undefined ? String(normalizedThreadId) : undefined;
758763return Array.from(messages, ([key, node]) => ({ key, node }))
759764.filter(({ key, node }) => {
760765if (!key.startsWith(prefix)) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。