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:
danielz1z
2026-01-17 05:33:59 +00:00
committed by Peter Steinberger
parent 410b8f223e
commit 80bb6b712c
2 changed files with 36 additions and 1 deletions

View File

@@ -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";
}