mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-14 02:31:24 +00:00
25 lines
811 B
TypeScript
25 lines
811 B
TypeScript
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
|
import { parseTelegramTarget } from "./targets.js";
|
|
|
|
export function resolveTelegramAutoThreadId(params: {
|
|
to: string;
|
|
toolContext?: { currentThreadTs?: string; currentChannelId?: string };
|
|
}): string | undefined {
|
|
const context = params.toolContext;
|
|
if (!context?.currentThreadTs || !context.currentChannelId) {
|
|
return undefined;
|
|
}
|
|
const parsedTo = parseTelegramTarget(params.to);
|
|
if (parsedTo.messageThreadId != null) {
|
|
return undefined;
|
|
}
|
|
const parsedChannel = parseTelegramTarget(context.currentChannelId);
|
|
if (
|
|
normalizeLowercaseStringOrEmpty(parsedTo.chatId) !==
|
|
normalizeLowercaseStringOrEmpty(parsedChannel.chatId)
|
|
) {
|
|
return undefined;
|
|
}
|
|
return context.currentThreadTs;
|
|
}
|