new getFile and File types from Telegram Bot API update
Syfaro syfaro@foxpaw.in
Sat, 19 Sep 2015 10:46:20 -0500
2 files changed,
35 insertions(+),
0 deletions(-)
M
methods.go
→
methods.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.go
→
types.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"`