38 lines
901 B
Go
38 lines
901 B
Go
package telegram
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
)
|
|
|
|
type BotGateway struct {
|
|
bot *tgbotapi.BotAPI
|
|
logger *slog.Logger
|
|
}
|
|
|
|
func NewBotGateway(bot *tgbotapi.BotAPI, logger *slog.Logger) *BotGateway {
|
|
return &BotGateway{bot: bot, logger: logger}
|
|
}
|
|
|
|
func (g *BotGateway) SendText(ctx context.Context, chatID int64, text string) error {
|
|
msg := tgbotapi.NewMessage(chatID, text)
|
|
msg.ParseMode = tgbotapi.ModeMarkdown
|
|
_, err := g.bot.Send(msg)
|
|
if err != nil {
|
|
return fmt.Errorf("telegram send text: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (g *BotGateway) SendTyping(ctx context.Context, chatID int64) error {
|
|
action := tgbotapi.NewChatAction(chatID, tgbotapi.ChatTyping)
|
|
_, err := g.bot.Request(action)
|
|
if err != nil {
|
|
g.logger.WarnContext(ctx, "failed to send typing action", "error", err, "chat_id", chatID)
|
|
}
|
|
return nil
|
|
}
|