diff --git a/internal/channel/adapters/telegram/config.go b/internal/channel/adapters/telegram/config.go index d77e2feb..9e807476 100644 --- a/internal/channel/adapters/telegram/config.go +++ b/internal/channel/adapters/telegram/config.go @@ -146,15 +146,26 @@ func normalizeTarget(raw string) string { if strings.HasPrefix(value, "@") { return value } - isNumeric := true - for _, r := range value { - if r < '0' || r > '9' { - isNumeric = false - break - } - } - if isNumeric { + if isTelegramChatID(value) { return value } return "@" + value } + +// isTelegramChatID returns true when s looks like a Telegram numeric chat ID, +// which may be negative (e.g. supergroup IDs like -1002280927535). +func isTelegramChatID(s string) bool { + digits := s + if strings.HasPrefix(digits, "-") { + digits = digits[1:] + } + if len(digits) == 0 { + return false + } + for _, r := range digits { + if r < '0' || r > '9' { + return false + } + } + return true +} diff --git a/internal/channel/adapters/telegram/config_test.go b/internal/channel/adapters/telegram/config_test.go index 3a314592..2aa041da 100644 --- a/internal/channel/adapters/telegram/config_test.go +++ b/internal/channel/adapters/telegram/config_test.go @@ -85,4 +85,10 @@ func TestNormalizeTarget(t *testing.T) { if got := normalizeTarget("@alice"); got != "@alice" { t.Fatalf("unexpected normalized target: %s", got) } + if got := normalizeTarget("123456789"); got != "123456789" { + t.Fatalf("positive chat ID mangled: %s", got) + } + if got := normalizeTarget("-1002280927535"); got != "-1002280927535" { + t.Fatalf("negative supergroup chat ID mangled: %s", got) + } }