Add support for audio attachments and voice messages
This commit is contained in:
@@ -54,7 +54,9 @@ func (s *anonymousMessagesService) ServeMessages() error {
|
|||||||
err := s.api.SendMessageToOwner(Message{
|
err := s.api.SendMessageToOwner(Message{
|
||||||
Text: notificationText,
|
Text: notificationText,
|
||||||
Image: update.Message.Image,
|
Image: update.Message.Image,
|
||||||
|
Audio: update.Message.Audio,
|
||||||
Video: update.Message.Video,
|
Video: update.Message.Video,
|
||||||
|
Voice: update.Message.Voice,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.errorsChan <- err
|
s.errorsChan <- err
|
||||||
|
|||||||
@@ -19,14 +19,20 @@ type Message struct {
|
|||||||
Text string
|
Text string
|
||||||
UseMarkdown bool
|
UseMarkdown bool
|
||||||
Image *Image
|
Image *Image
|
||||||
|
Audio *Audio
|
||||||
Video *Video
|
Video *Video
|
||||||
Sticker *Sticker
|
Sticker *Sticker
|
||||||
|
Voice *Voice
|
||||||
}
|
}
|
||||||
|
|
||||||
type Image struct {
|
type Image struct {
|
||||||
FileID string
|
FileID string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Audio struct {
|
||||||
|
FileID string
|
||||||
|
}
|
||||||
|
|
||||||
type Video struct {
|
type Video struct {
|
||||||
FileID string
|
FileID string
|
||||||
}
|
}
|
||||||
@@ -36,6 +42,10 @@ type Sticker struct {
|
|||||||
Emoji string
|
Emoji string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Voice struct {
|
||||||
|
FileID string
|
||||||
|
}
|
||||||
|
|
||||||
type Command int
|
type Command int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -58,10 +58,18 @@ func (api *botAPI) SendMessage(chatID int64, message app.Message) error {
|
|||||||
return api.sendPhotoMessage(chatID, message)
|
return api.sendPhotoMessage(chatID, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if message.Audio != nil {
|
||||||
|
return api.sendAudioMessage(chatID, message)
|
||||||
|
}
|
||||||
|
|
||||||
if message.Video != nil {
|
if message.Video != nil {
|
||||||
return api.sendVideoMessage(chatID, message)
|
return api.sendVideoMessage(chatID, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if message.Voice != nil {
|
||||||
|
return api.sendVoiceMessage(chatID, message)
|
||||||
|
}
|
||||||
|
|
||||||
return api.sendTextMessage(chatID, message)
|
return api.sendTextMessage(chatID, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,8 +86,10 @@ func (api *botAPI) hydrateMessage(msg *tgbotapi.Message) app.Message {
|
|||||||
return app.Message{
|
return app.Message{
|
||||||
Text: text,
|
Text: text,
|
||||||
Image: api.hydrateImage(msg.Photo),
|
Image: api.hydrateImage(msg.Photo),
|
||||||
|
Audio: api.hydrateAudio(msg.Audio),
|
||||||
Video: api.hydrateVideo(msg.Video),
|
Video: api.hydrateVideo(msg.Video),
|
||||||
Sticker: api.hydrateSticker(msg.Sticker),
|
Sticker: api.hydrateSticker(msg.Sticker),
|
||||||
|
Voice: api.hydrateVoice(msg.Voice),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +115,14 @@ func (api *botAPI) sendPhotoMessage(chatID int64, message app.Message) error {
|
|||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *botAPI) sendAudioMessage(chatID int64, message app.Message) error {
|
||||||
|
audios := api.prepareAudio(message)
|
||||||
|
mediaMsg := tgbotapi.NewMediaGroup(chatID, audios)
|
||||||
|
|
||||||
|
_, err := api.bot.Send(mediaMsg)
|
||||||
|
return errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *botAPI) sendVideoMessage(chatID int64, message app.Message) error {
|
func (api *botAPI) sendVideoMessage(chatID int64, message app.Message) error {
|
||||||
video := api.prepareVideo(message)
|
video := api.prepareVideo(message)
|
||||||
mediaMsg := tgbotapi.NewMediaGroup(chatID, video)
|
mediaMsg := tgbotapi.NewMediaGroup(chatID, video)
|
||||||
@@ -113,6 +131,18 @@ func (api *botAPI) sendVideoMessage(chatID int64, message app.Message) error {
|
|||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *botAPI) sendVoiceMessage(chatID int64, message app.Message) error {
|
||||||
|
voiceMsg := tgbotapi.NewVoice(chatID, tgbotapi.FileID(message.Voice.FileID))
|
||||||
|
|
||||||
|
voiceMsg.Caption = message.Text
|
||||||
|
if message.UseMarkdown {
|
||||||
|
voiceMsg.ParseMode = tgbotapi.ModeMarkdown
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := api.bot.Send(voiceMsg)
|
||||||
|
return errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *botAPI) hydrateCommand(msg *tgbotapi.Message) *app.Command {
|
func (api *botAPI) hydrateCommand(msg *tgbotapi.Message) *app.Command {
|
||||||
if !msg.IsCommand() {
|
if !msg.IsCommand() {
|
||||||
return nil
|
return nil
|
||||||
@@ -150,6 +180,16 @@ func (api *botAPI) hydrateImage(photos []tgbotapi.PhotoSize) *app.Image {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *botAPI) hydrateAudio(audio *tgbotapi.Audio) *app.Audio {
|
||||||
|
if audio == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &app.Audio{
|
||||||
|
FileID: audio.FileID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (api *botAPI) hydrateVideo(video *tgbotapi.Video) *app.Video {
|
func (api *botAPI) hydrateVideo(video *tgbotapi.Video) *app.Video {
|
||||||
if video == nil {
|
if video == nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -171,6 +211,16 @@ func (api *botAPI) hydrateSticker(sticker *tgbotapi.Sticker) *app.Sticker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *botAPI) hydrateVoice(voice *tgbotapi.Voice) *app.Voice {
|
||||||
|
if voice == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &app.Voice{
|
||||||
|
FileID: voice.FileID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (api *botAPI) preparePhotos(message app.Message) []interface{} {
|
func (api *botAPI) preparePhotos(message app.Message) []interface{} {
|
||||||
photo := tgbotapi.NewInputMediaPhoto(tgbotapi.FileID(message.Image.FileID))
|
photo := tgbotapi.NewInputMediaPhoto(tgbotapi.FileID(message.Image.FileID))
|
||||||
photo.Caption = message.Text
|
photo.Caption = message.Text
|
||||||
@@ -185,6 +235,17 @@ func (api *botAPI) preparePhotos(message app.Message) []interface{} {
|
|||||||
return photos
|
return photos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *botAPI) prepareAudio(message app.Message) []interface{} {
|
||||||
|
audio := tgbotapi.NewInputMediaAudio(tgbotapi.FileID(message.Audio.FileID))
|
||||||
|
audio.Caption = message.Text
|
||||||
|
|
||||||
|
if message.UseMarkdown {
|
||||||
|
audio.ParseMode = tgbotapi.ModeMarkdown
|
||||||
|
}
|
||||||
|
|
||||||
|
return []interface{}{audio}
|
||||||
|
}
|
||||||
|
|
||||||
func (api *botAPI) prepareVideo(message app.Message) []interface{} {
|
func (api *botAPI) prepareVideo(message app.Message) []interface{} {
|
||||||
video := tgbotapi.NewInputMediaVideo(tgbotapi.FileID(message.Video.FileID))
|
video := tgbotapi.NewInputMediaVideo(tgbotapi.FileID(message.Video.FileID))
|
||||||
video.Caption = message.Text
|
video.Caption = message.Text
|
||||||
|
|||||||
Reference in New Issue
Block a user