Skip to content

Commit

Permalink
Merge pull request #52 from yanzay/file-url-helper
Browse files Browse the repository at this point in the history
Add FileURL helper to Client.
  • Loading branch information
yanzay committed Nov 16, 2019
2 parents f702897 + d4fde29 commit feb7865
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 8 additions & 0 deletions 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)
}
3 changes: 1 addition & 2 deletions examples/getfile/main.go
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"io"
"log"
"net/http"
Expand All @@ -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)
Expand Down

0 comments on commit feb7865

Please sign in to comment.