telegram email

This commit is contained in:
Vladimir V Maksimov
2025-12-10 17:14:16 +03:00
parent b20e040fae
commit 1d9d56dc87
5 changed files with 156 additions and 4 deletions

View File

@@ -55,6 +55,10 @@ func NewTelegram(token string, disableIPV6 bool) (*Bot, error) {
return bot, nil
}
func (s *Bot) GetAPI() *tgbotapi.BotAPI {
return s.api
}
func (s *Bot) SendTextMessage(chatID int64, text string) (tgbotapi.Message, error) {
message := tgbotapi.NewMessage(chatID, text)
message.ParseMode = "Markdown"
@@ -66,3 +70,54 @@ func (s *Bot) SendHTMLMessage(chatID int64, text string) (tgbotapi.Message, erro
message.ParseMode = "HTML"
return s.api.Send(message)
}
func (s *Bot) SendPhotoFromFile(chatID int64, filePath string, caption string) (tgbotapi.Message, error) {
photo := tgbotapi.NewPhoto(chatID, tgbotapi.FilePath(filePath))
photo.Caption = caption
photo.ParseMode = "Markdown" // или "HTML"
return s.api.Send(photo)
}
func (s *Bot) SendPhotoFromURL(chatID int64, fileURL string, caption string) (tgbotapi.Message, error) {
photo := tgbotapi.NewPhoto(chatID, tgbotapi.FileURL(fileURL))
photo.Caption = caption
photo.ParseMode = "Markdown"
return s.api.Send(photo)
}
func (s *Bot) SendPhotoFromBytes(chatID int64, data []byte, filename string, caption string) (tgbotapi.Message, error) {
file := tgbotapi.FileBytes{
Name: filename,
Bytes: data,
}
photo := tgbotapi.NewPhoto(chatID, file)
photo.Caption = caption
photo.ParseMode = "Markdown"
return s.api.Send(photo)
}
func (s *Bot) SendDocumentFromFile(chatID int64, filePath string, caption string) (tgbotapi.Message, error) {
doc := tgbotapi.NewDocument(chatID, tgbotapi.FilePath(filePath))
doc.Caption = caption
doc.ParseMode = "Markdown"
return s.api.Send(doc)
}
func (s *Bot) SendDocumentFromURL(chatID int64, fileURL string, caption string) (tgbotapi.Message, error) {
doc := tgbotapi.NewDocument(chatID, tgbotapi.FileURL(fileURL))
doc.Caption = caption
doc.ParseMode = "Markdown"
return s.api.Send(doc)
}
func (s *Bot) SendDocumentFromBytes(chatID int64, data []byte, filename string, caption string) (tgbotapi.Message, error) {
file := tgbotapi.FileBytes{
Name: filename,
Bytes: data,
}
doc := tgbotapi.NewDocument(chatID, file)
doc.Caption = caption
doc.ParseMode = "Markdown"
return s.api.Send(doc)
}