Phase 1 MVP — echo bot factory
All checks were successful
Docker Build / build-and-push-image (push) Successful in 1m8s
All checks were successful
Docker Build / build-and-push-image (push) Successful in 1m8s
This commit is contained in:
33
handler_echo.go
Normal file
33
handler_echo.go
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user