Files
miti99bot/internal/modules/dispatcher.go
T
tiennm99 35ad4cb997 feat(server,modules): bootstrap server and module framework
Implements Phases 02 (partial) and 03 of the go-port-cloud-run plan.
Introduces module framework with per-module KV prefix isolation,
health check endpoint, request timeout protection, and comprehensive
test coverage. Cloud Run deployment deferred to Phase 01.

Security hardening: constant-time secret comparison, cron auth bridge,
and secrets stripped from dependency environment exports. Includes
Dockerfile, GitHub CI workflow (vet + race + build), and integration
tests for module lifecycle.
2026-05-08 23:27:12 +07:00

30 lines
767 B
Go

package modules
import (
"context"
"log"
"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
)
// Install registers every command in the registry with the Telegram bot.
//
// MatchTypeCommand expects the bare command name without the leading slash;
// the library compares against entity bytes after the "/" prefix.
func Install(b *bot.Bot, reg *Registry) {
for name, cmd := range reg.AllCommands {
cmdCopy := cmd // capture by value for the closure
b.RegisterHandler(
bot.HandlerTypeMessageText,
name,
bot.MatchTypeCommand,
func(ctx context.Context, b *bot.Bot, update *models.Update) {
if err := cmdCopy.Handler(ctx, b, update); err != nil {
log.Printf("command /%s failed: %v", cmdCopy.Name, err)
}
},
)
}
}