From 1bceea1ca532fa0d7107a1ad08549f7d41d42b5c Mon Sep 17 00:00:00 2001 From: Syfaro Date: Sat, 19 Sep 2015 10:46:20 -0500 Subject: [PATCH] new getFile and File types from Telegram Bot API update --- methods.go | 28 ++++++++++++++++++++++++++++ types.go | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/methods.go b/methods.go index 5b5ebeb..819509f 100644 --- a/methods.go +++ b/methods.go @@ -156,6 +156,11 @@ type UserProfilePhotosConfig struct { 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 @@ -946,6 +951,29 @@ func (bot *BotAPI) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserPro 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. // If a WebHook is set, this will not return any data! // diff --git a/types.go b/types.go index a2271e2..ccc5dce 100644 --- a/types.go +++ b/types.go @@ -171,6 +171,13 @@ type UserProfilePhotos struct { 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"`