mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:11:25 +00:00
fix: handle telegram: prefix in resolveTelegramTargetChatType
When using inlineButtons="dm" or "group" scope, the validation check resolveTelegramTargetChatType() failed for numeric chat IDs because normalizeTelegramMessagingTarget() adds a "telegram:" prefix during target resolution. For example, target "5232990709" becomes "telegram:5232990709" after normalization, but the regex /^-?\d+$/ expects a pure numeric string. The fix strips the telegram: prefix before checking the numeric pattern. Adds tests for resolveTelegramTargetChatType with various input formats.
This commit is contained in:
committed by
Peter Steinberger
parent
410b8f223e
commit
80bb6b712c
@@ -61,8 +61,12 @@ export function isTelegramInlineButtonsEnabled(params: {
|
||||
}
|
||||
|
||||
export function resolveTelegramTargetChatType(target: string): "direct" | "group" | "unknown" {
|
||||
const trimmed = target.trim();
|
||||
let trimmed = target.trim();
|
||||
if (!trimmed) return "unknown";
|
||||
// Strip telegram: prefix added by normalizeTelegramMessagingTarget
|
||||
if (trimmed.toLowerCase().startsWith("telegram:")) {
|
||||
trimmed = trimmed.slice("telegram:".length).trim();
|
||||
}
|
||||
if (/^-?\d+$/.test(trimmed)) {
|
||||
return trimmed.startsWith("-") ? "group" : "direct";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user