feat: initial commit
This commit is contained in:
37
internal/infrastructure/telegram/bot_gateway.go
Normal file
37
internal/infrastructure/telegram/bot_gateway.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user