31 lines
577 B
Go
31 lines
577 B
Go
package telegram
|
|
|
|
import (
|
|
"cake_crm/internal/models/messenger"
|
|
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
|
|
}
|