cake_crm/internal/modules/messenger/telegram/messenger.go

31 lines
578 B
Go
Raw Permalink Normal View History

2024-05-22 18:40:59 +00:00
package telegram
import (
2024-05-23 18:10:31 +00:00
"cake_crm/internal/modules/messenger"
2024-05-22 18:40:59 +00:00
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
type messengerTelegram struct {
chatID int64
bot *tgbotapi.BotAPI
}
func NewMessenger(
chatID int64,
token string,
) (messenger.IMessenger, error) {
bot, err := tgbotapi.NewBotAPI(token)
if err != nil {
return nil, err
}
return &messengerTelegram{
chatID: chatID,
bot: bot,
}, nil
}
func (m *messengerTelegram) SendMessage(message string) error {
_, err := m.bot.Send(tgbotapi.NewMessage(m.chatID, message))
return err
}