Skip to content

Commit

Permalink
Add SendDocument method.
Browse files Browse the repository at this point in the history
  • Loading branch information
onrik committed Apr 23, 2016
1 parent b63d73d commit ccd571b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
29 changes: 28 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewSendPhotoParams(chatId int64, photo string, options *SendPhotoOptions) *
type SendAudioOptions struct {
Duration int `json:"duration,omitempty"`
Performer string `json:"performer,omitempty"`
title string `json:"title,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"`
Expand All @@ -70,6 +70,33 @@ func NewSendAudioParams(chatId int64, audio string, options *SendAudioOptions) *
return params
}

// Send document request params
type SendDocumentOptions struct {
Caption string `json:"caption,omitempty"`
DisableNotification bool `json:"disable_notification,omitempty"`
ReplyToMessageId int64 `json:"reply_to_message_id,omitempty"`
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
}

type SendDocumentParams struct {
ChatId int64 `json:"chat_id"`
Document string `json:"document,omitempty"`
SendDocumentOptions
}

func NewSendDocumentParams(chatId int64, document string, options *SendDocumentOptions) *SendDocumentParams {
params := &SendDocumentParams{
ChatId: chatId,
Document: document,
}

if options != nil {
params.SendDocumentOptions = *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 @@ -219,6 +219,36 @@ func (bot *Bot) SendAudioFile(chatId int64, file io.ReadCloser, options *SendAud
return message, err
}

// Send exists document by file_id
func (bot *Bot) SendDocument(chatId int64, documentId string, options *SendDocumentOptions) (*Message, error) {
params := NewSendDocumentParams(chatId, documentId, options)

message := new(Message)
err := bot.post("sendDocument", params, message)

return message, err
}

// Send file
func (bot *Bot) SendDocumentFile(chatId int64, documentName string, file io.ReadCloser, options *SendDocumentOptions) (*Message, error) {
params := NewSendDocumentParams(chatId, "", options)
values, err := structToValues(params)
if err != nil {
return nil, err
}

fileToSend := &FileToSend{
File: file,
Fieldname: "document",
Filename: documentName,
}

message := new(Message)
err = bot.postMultipart("sendDocument", 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 ccd571b

Please sign in to comment.