Files
miti99bot/internal/modules/util/info.go
T
tiennm99 cf620a257e docs: fix stale code comments and add missing package docs
Correct comments that described the retired webhook transport, a removed
/cron route, the old KV store and wrapper types, and behaviour that has since
changed; drop plan and review labels; reword two startup log lines that
overstated or misnamed what they report.
2026-09-30 14:19:01 +07:00

49 lines
1.7 KiB
Go

package util
import (
"context"
"fmt"
"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
"github.com/tiennm99/miti99bot/internal/modules"
"github.com/tiennm99/miti99bot/internal/modules/util/chathelper"
)
// infoCommand returns /info — replies plain text with chat / thread / sender
// IDs, with "n/a" fallbacks. Used to debug bot routing in groups + topics.
func infoCommand() modules.Command {
return modules.Command{
Name: "info",
// Protected (not Public) because the response exposes internal
// routing IDs — chat id, thread id, sender id. Useful for admins
// debugging group/topic routing; not something every group member
// should be able to enumerate. Non-admins see no response at all
// (Visibility denies are silent — see modules.Auth.Permits).
Visibility: modules.VisibilityProtected,
Description: "Show chat id, thread id, and sender id (debug helper)",
Handler: func(ctx context.Context, b *bot.Bot, update *models.Update) error {
msg := update.Message
if msg == nil {
// Today the dispatcher only routes message-text commands, but
// guard so /info can be safely reused from other update paths.
return nil
}
chatID := fmt.Sprintf("%d", msg.Chat.ID)
// Telegram omits message_thread_id outside forum topics, so a 0
// here means "no thread" — render as "n/a" instead of "0".
threadID := "n/a"
if msg.MessageThreadID != 0 {
threadID = fmt.Sprintf("%d", msg.MessageThreadID)
}
senderID := "n/a"
if msg.From != nil {
senderID = fmt.Sprintf("%d", msg.From.ID)
}
text := fmt.Sprintf("chat id: %s\nthread id: %s\nsender id: %s", chatID, threadID, senderID)
return chathelper.Reply(ctx, b, msg, text)
},
}
}