diff --git a/api.go b/api.go index f2ffead..be9197f 100644 --- a/api.go +++ b/api.go @@ -41,6 +41,35 @@ func NewSendPhotoParams(chatId int64, photo string, options *SendPhotoOptions) * return params } +// Send audio request params +type SendAudioOptions struct { + Duration int `json:"duration,omitempty"` + Performer string `json:"performer,omitempty"` + title string `json:"title,omitempty"` + DisableNotification bool `json:"disable_notification,omitempty"` + ReplyToMessageId int64 `json:"reply_to_message_id,omitempty"` + ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"` +} + +type SendAudioParams struct { + ChatId int64 `json:"chat_id"` + Audio string `json:"audio,omitempty"` + SendAudioOptions +} + +func NewSendAudioParams(chatId int64, audio string, options *SendAudioOptions) *SendAudioParams { + params := &SendAudioParams{ + ChatId: chatId, + Audio: audio, + } + + if options != nil { + params.SendAudioOptions = *options + } + + return params +} + type EditMessageTextOptions struct { ParseMode ParseMode `json:"parse_mode,omitempty"` DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"` diff --git a/bot.go b/bot.go index 81c405c..aeedaad 100644 --- a/bot.go +++ b/bot.go @@ -189,6 +189,36 @@ func (bot *Bot) SendPhotoFile(chatId int64, file io.ReadCloser, options *SendPho return message, err } +// Send exists audio by file_id +func (bot *Bot) SendAudio(chatId int64, audioId string, options *SendAudioOptions) (*Message, error) { + params := NewSendAudioParams(chatId, audioId, options) + + message := new(Message) + err := bot.post("sendAudio", params, message) + + return message, err +} + +// Send audio file +func (bot *Bot) SendAudioFile(chatId int64, file io.ReadCloser, options *SendAudioOptions) (*Message, error) { + params := NewSendAudioParams(chatId, "", options) + values, err := structToValues(params) + if err != nil { + return nil, err + } + + fileToSend := &FileToSend{ + File: file, + Fieldname: "audio", + Filename: "audio.mp3", + } + + message := new(Message) + err = bot.postMultipart("sendAudio", fileToSend, values, message) + + return message, err +} + // Use this method to forward messages of any kind. func (bot *Bot) ForwardMessage(chatId, fromChatId, messageId int64, disableNotification bool) (*Message, error) { params := map[string]interface{}{