Files
openclaw/src/auto-reply/reply/auto-topic-label-config.ts
Taras Lukavyi 466debb75c feat(telegram): auto-rename DM topics on first message (#51502)
* feat(telegram): auto-rename DM topics on first message

fix(telegram): use bot.api for topic rename to avoid SecretRef resolution

* fix(telegram): address security + test review feedback

- Fix test assertion: DEFAULT_PROMPT_SUBSTRING matches 'very short'
- Use RawBody instead of Body (no envelope metadata to LLM)
- Truncate user message to 500 chars for LLM prompt
- Remove user-derived content from verbose logs
- Remove redundant threadSpec.id null check
- Fix AutoTopicLabelParams type to match generateTopicLabel

* fix(telegram): use effective dm auto-topic config

* fix(telegram): detect direct auto-topic overrides

* fix: auto-rename Telegram DM topics on first message (#51502) (thanks @Lukavyi)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
2026-03-21 16:53:30 +05:30

37 lines
1.3 KiB
TypeScript

/**
* Config resolution for auto-topic-label feature.
* Kept separate from LLM logic to avoid heavy transitive dependencies in tests.
*/
import type { AutoTopicLabelConfig } from "../../config/types.telegram.js";
export const AUTO_TOPIC_LABEL_DEFAULT_PROMPT =
"Generate a very short topic label (2-4 words, max 25 chars) for a chat conversation based on the user's first message below. No emoji. Use the same language as the message. Be concise and descriptive. Return ONLY the topic name, nothing else.";
/**
* Resolve whether auto topic labeling is enabled and get the prompt.
* Returns null if disabled.
*/
export function resolveAutoTopicLabelConfig(
directConfig?: AutoTopicLabelConfig,
accountConfig?: AutoTopicLabelConfig,
): { enabled: true; prompt: string } | null {
// Per-DM config takes priority over account-level config.
const config = directConfig ?? accountConfig;
// Default: enabled (when config is undefined, treat as true).
if (config === undefined || config === true) {
return { enabled: true, prompt: AUTO_TOPIC_LABEL_DEFAULT_PROMPT };
}
if (config === false) {
return null;
}
// Object form.
if (config.enabled === false) {
return null;
}
return {
enabled: true,
prompt: config.prompt?.trim() || AUTO_TOPIC_LABEL_DEFAULT_PROMPT,
};
}