Files
2026-05-21 08:40:16 +00:00

27 lines
598 B
Go

package telegram
import (
"context"
"fmt"
"io"
"net/http"
"strings"
)
func (c *Client) DownloadFilePath(ctx context.Context, filePath string) ([]byte, error) {
u := c.fileBaseURL + "/" + strings.TrimLeft(filePath, "/")
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
if err != nil {
return nil, err
}
resp, err := c.httpClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return nil, fmt.Errorf("download file: telegram returned %s", resp.Status)
}
return io.ReadAll(resp.Body)
}