all repos — telegram-bot-api @ 1bceea1ca532fa0d7107a1ad08549f7d41d42b5c

Golang bindings for the Telegram Bot API

new getFile and File types from Telegram Bot API update
Syfaro syfaro@foxpaw.in
Sat, 19 Sep 2015 10:46:20 -0500
commit

1bceea1ca532fa0d7107a1ad08549f7d41d42b5c

parent

3ce6dbabe0265880bdde5cacbb961673bcf55174

2 files changed, 35 insertions(+), 0 deletions(-)

jump to
M methods.gomethods.go

@@ -156,6 +156,11 @@ Offset int

Limit int } +// FileConfig has information about a file hosted on Telegram +type FileConfig struct { + FileID string +} + // UpdateConfig contains information about a GetUpdates request. type UpdateConfig struct { Offset int

@@ -944,6 +949,29 @@ log.Printf("getUserProfilePhotos resp: %+v\n", profilePhotos)

} return profilePhotos, nil +} + +// GetFile returns a file_id required to download a file. +// +// Requires FileID. +func (bot *BotAPI) GetFile(config FileConfig) (File, error) { + v := url.Values{} + v.Add("file_id", config.FileID) + + resp, err := bot.MakeRequest("getFile", v) + if err != nil { + return File{}, err + } + + var file File + json.Unmarshal(resp.Result, &file) + + if bot.Debug { + log.Printf("getFile req : %+v\n", v) + log.Printf("getFile resp: %+v\n", file) + } + + return file, nil } // GetUpdates fetches updates.
M types.gotypes.go

@@ -171,6 +171,13 @@ TotalCount int `json:"total_count"`

Photos []PhotoSize `json:"photos"` } +// File contains information about a file to download from Telegram +type File struct { + FileID string `json:"file_id"` + FileSize int `json:"file_size"` + FilePath string `json:"file_path"` +} + // ReplyKeyboardMarkup allows the Bot to set a custom keyboard. type ReplyKeyboardMarkup struct { Keyboard [][]string `json:"keyboard"`