Skip to content

Commit

Permalink
Add sendVideo method.
Browse files Browse the repository at this point in the history
  • Loading branch information
onrik committed Jul 7, 2016
1 parent 6e09896 commit e9c418f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,36 @@ func NewSendStickerParams(chatId int64, sticker string, options *SendStickerOpti
return params
}

// Send video request params
type SendVideoOptions struct {
Duration int `json:"duration,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
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 SendVideoParams struct {
ChatId int64 `json:"chat_id"`
Video string `json:"video,omitempty"`
SendVideoOptions
}

func NewSendVideoParams(chatId int64, video string, options *SendVideoOptions) *SendVideoParams {
params := &SendVideoParams{
ChatId: chatId,
Video: video,
}

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

// Send exists video by file_id
func (bot *Bot) SendVideo(chatId int64, videoId string, options *SendVideoOptions) (*Message, error) {
params := NewSendVideoParams(chatId, videoId, options)

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

return message, err
}

// Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
func (bot *Bot) SendVideoFile(chatId int64, file io.ReadCloser, options *SendVideoOptions) (*Message, error) {
params := NewSendVideoParams(chatId, "", options)
values, err := structToValues(params)
if err != nil {
return nil, err
}

fileToSend := &FileToSend{
File: file,
Fieldname: "video",
Filename: "video.mp4",
}

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

Please sign in to comment.