1
0
telegram/get_file.go

33 lines
1.0 KiB
Go
Raw Normal View History

2017-09-04 20:16:06 +00:00
package telegram
import (
json "github.com/pquerna/ffjson/ffjson"
http "github.com/valyala/fasthttp"
)
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.
2017-09-04 20:16:06 +00:00
func (bot *Bot) GetFile(file string) (*File, error) {
2017-12-13 14:07:57 +00:00
args := http.AcquireArgs()
defer http.ReleaseArgs(args)
2017-10-06 07:55:54 +00:00
args.Add("file_id", file)
2017-09-04 20:16:06 +00:00
2017-12-13 14:07:57 +00:00
resp, err := bot.request(nil, "getFile", args)
2017-09-04 20:16:06 +00:00
if err != nil {
return nil, err
}
var data File
err = json.Unmarshal(*resp.Result, &data)
return &data, err
}