Skip to content

Commit

Permalink
Add SendAudio method.
Browse files Browse the repository at this point in the history
  • Loading branch information
onrik committed Apr 21, 2016
1 parent e5037a5 commit 8e32f98
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
29 changes: 29 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
30 changes: 30 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down

0 comments on commit 8e32f98

Please sign in to comment.