1
0
telegram/get_file.go

37 lines
1.2 KiB
Go
Raw Normal View History

2017-09-04 20:16:06 +00:00
package telegram
import json "github.com/pquerna/ffjson/ffjson"
2018-04-19 13:02:15 +00:00
// GetFileParameters represents data for GetFile method.
type GetFileParameters struct {
2018-10-12 11:44:27 +00:00
// File identifier to get info about
FileID string `json:"file_id"`
}
2017-09-04 20:16:06 +00:00
2017-10-06 07:55:54 +00:00
// GetFile get basic info about a file and prepare it for downloading. For the
// moment, bots can download files of up to 20MB in size. On success, a File
// object is returned. The file can then be downloaded via the link
// https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is
// taken from the response. It is guaranteed that the link will be valid for at
// least 1 hour. When the link expires, a new one can be requested by calling
// getFile again.
2017-09-04 20:16:06 +00:00
//
2017-10-06 07:55:54 +00:00
// Note: This function may not preserve the original file name and MIME type. You
// should save the file's MIME type and name (if available) when the File object
// is received.
2018-08-21 11:05:04 +00:00
func (bot *Bot) GetFile(fileID string) (file *File, err error) {
dst, err := json.Marshal(&GetFileParameters{FileID: fileID})
if err != nil {
2018-08-21 11:05:04 +00:00
return
}
2017-09-04 20:16:06 +00:00
2018-04-12 11:58:05 +00:00
resp, err := bot.request(dst, MethodGetFile)
2017-09-04 20:16:06 +00:00
if err != nil {
2018-08-21 11:05:04 +00:00
return
2017-09-04 20:16:06 +00:00
}
2018-08-21 11:05:04 +00:00
file = new(File)
err = json.Unmarshal(*resp.Result, file)
return
2017-09-04 20:16:06 +00:00
}