telegram: reduce aggressive TrimSpace/ToLower normalization on content-sensitive paths

This commit is contained in:
DBT
2026-02-27 16:34:36 +00:00
parent 42cde26a5e
commit aeb285a7a1

View File

@@ -422,7 +422,7 @@ func (c *TelegramChannel) sendMedia(ctx context.Context, chatID int64, msg bus.O
func (c *TelegramChannel) isAllowedChat(chatID int64, chatType string) bool { func (c *TelegramChannel) isAllowedChat(chatID int64, chatType string) bool {
// Private chats are governed by allow_from (sender allowlist), not allow_chats. // Private chats are governed by allow_from (sender allowlist), not allow_chats.
if strings.TrimSpace(chatType) == telego.ChatTypePrivate { if chatType == telego.ChatTypePrivate {
return true return true
} }
if len(c.config.AllowChats) == 0 { if len(c.config.AllowChats) == 0 {
@@ -430,7 +430,7 @@ func (c *TelegramChannel) isAllowedChat(chatID int64, chatType string) bool {
} }
sid := fmt.Sprintf("%d", chatID) sid := fmt.Sprintf("%d", chatID)
for _, allowed := range c.config.AllowChats { for _, allowed := range c.config.AllowChats {
if strings.TrimSpace(allowed) == sid { if allowed == sid {
return true return true
} }
} }
@@ -453,7 +453,7 @@ func (c *TelegramChannel) shouldHandleGroupMessage(message *telego.Message, cont
if message.ReplyToMessage != nil && message.ReplyToMessage.From != nil && message.ReplyToMessage.From.IsBot { if message.ReplyToMessage != nil && message.ReplyToMessage.From != nil && message.ReplyToMessage.From.IsBot {
return true return true
} }
if strings.HasPrefix(strings.TrimSpace(content), "/") { if strings.HasPrefix(content, "/") {
return true return true
} }
if c.botUsername != "" && strings.Contains(strings.ToLower(content), "@"+c.botUsername) { if c.botUsername != "" && strings.Contains(strings.ToLower(content), "@"+c.botUsername) {
@@ -609,11 +609,11 @@ func (c *TelegramChannel) downloadFile(runCtx context.Context, fileID, ext, file
url := fmt.Sprintf("https://api.telegram.org/file/bot%s/%s", c.config.Token, file.FilePath) url := fmt.Sprintf("https://api.telegram.org/file/bot%s/%s", c.config.Token, file.FilePath)
mediaDir := filepath.Join(os.TempDir(), "clawgo_media") mediaDir := filepath.Join(os.TempDir(), "clawgo_media")
_ = os.MkdirAll(mediaDir, 0755) _ = os.MkdirAll(mediaDir, 0755)
finalExt := strings.TrimSpace(ext) finalExt := ext
if finalExt == "" { if finalExt == "" {
if fromName := strings.TrimSpace(filepath.Ext(fileName)); fromName != "" { if fromName := filepath.Ext(fileName); fromName != "" {
finalExt = fromName finalExt = fromName
} else if fromPath := strings.TrimSpace(filepath.Ext(file.FilePath)); fromPath != "" { } else if fromPath := filepath.Ext(file.FilePath); fromPath != "" {
finalExt = fromPath finalExt = fromPath
} }
} }
@@ -635,7 +635,6 @@ func min(a, b int) int {
func splitTelegramMarkdown(s string, maxRunes int) []string { func splitTelegramMarkdown(s string, maxRunes int) []string {
s = strings.TrimSpace(s)
if s == "" { if s == "" {
return []string{""} return []string{""}
} }
@@ -657,7 +656,6 @@ func splitTelegramMarkdown(s string, maxRunes int) []string {
} }
func splitTelegramText(s string, maxRunes int) []string { func splitTelegramText(s string, maxRunes int) []string {
s = strings.TrimSpace(s)
if s == "" { if s == "" {
return []string{""} return []string{""}
} }
@@ -672,7 +670,7 @@ func splitTelegramText(s string, maxRunes int) []string {
for start := 0; start < len(r); { for start := 0; start < len(r); {
end := start + maxRunes end := start + maxRunes
if end >= len(r) { if end >= len(r) {
out = append(out, strings.TrimSpace(string(r[start:]))) out = append(out, string(r[start:]))
break break
} }
split := end split := end
@@ -682,12 +680,12 @@ func splitTelegramText(s string, maxRunes int) []string {
break break
} }
} }
out = append(out, strings.TrimSpace(string(r[start:split]))) out = append(out, string(r[start:split]))
start = split start = split
} }
cleaned := make([]string, 0, len(out)) cleaned := make([]string, 0, len(out))
for _, part := range out { for _, part := range out {
if strings.TrimSpace(part) != "" { if part != "" {
cleaned = append(cleaned, part) cleaned = append(cleaned, part)
} }
} }