diff --git a/client_helpers.go b/client_helpers.go new file mode 100644 index 0000000..4305c3e --- /dev/null +++ b/client_helpers.go @@ -0,0 +1,8 @@ +package tbot + +import "fmt" + +// FileURL returns file URL ready for download +func (c *Client) FileURL(file *File) string { + return fmt.Sprintf("%s/file/bot%s/%s", apiBaseURL, c.token, file.FilePath) +} diff --git a/examples/getfile/main.go b/examples/getfile/main.go index 874b9a0..014023e 100644 --- a/examples/getfile/main.go +++ b/examples/getfile/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "io" "log" "net/http" @@ -24,7 +23,7 @@ func main() { log.Println(err) return } - url := fmt.Sprintf("https://api.telegram.org/file/bot%s/%s", token, doc.FilePath) + url := client.FileURL(doc) resp, err := http.Get(url) if err != nil { log.Println(err)