Files
telegram-gateway/handler_echo.go
Gabriel Radureau ee832de089
All checks were successful
Docker Build / build-and-push-image (push) Successful in 1m8s
Phase 1 MVP — echo bot factory
2026-05-09 12:23:59 +02:00

34 lines
678 B
Go

package main
import (
"context"
"fmt"
"strings"
)
type EchoHandler struct {
tg *TelegramClient
}
func (e *EchoHandler) Handle(ctx context.Context, update Update, bot Bot) error {
chatID, ok := update.ChatID()
if !ok {
return nil
}
text := strings.TrimSpace(update.Text())
if text == "" {
return nil
}
reply := text
if strings.HasPrefix(text, "/echo") {
reply = strings.TrimSpace(strings.TrimPrefix(text, "/echo"))
if reply == "" {
reply = "echo bot online — send me anything"
}
}
if err := e.tg.SendMessage(ctx, bot.Token, SendMessageParams{ChatID: chatID, Text: reply}); err != nil {
return fmt.Errorf("sendMessage: %w", err)
}
return nil
}