Closed soaska closed 4 minutes ago
Ig I need to override var named FileEndpoint
But how
I think you can add FileEndpoint to FileConfig structure, but it will change endpint globally
Using local Telegram API, don't forget to set TELEGRAM_LOCAL=1. Now all files will be stored at /var/lib/telegram-bot-api. Then if you make a GetFile request, the API will return the path to the file in that location. So you need to mount /var/lib/telegram-bot-api to your program when you need to use the local Telegram API and get the path like this:
func getTelegramFile(bot *tgbotapi.BotAPI, fileID string) (string, error) {
//file, err := bot.GetFile(tgbotapi.FileConfig{FileID: fileID})
CallUrl := fmt.Sprintf("%s/bot%s/getFile?file_id=%s", api_endpoint, bot.Token, fileID)
resp, err := http.Get(CallUrl)
if err != nil {
return "", fmt.Errorf("http error: %v", err)
}
defer resp.Body.Close()
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf(“response interpretation error: %v", err)
}
fileResponse := &FileResponse{}
err = json.Unmarshal(responseBody, fileResponse)
if err != nil {
return "", fmt.Errorf("JSON interpretation error: %v", err)
}
if fileResponse.OK {
filePath, ok := fileResponse.Result["file_path"]
if !ok || filePath == "" {
return "", fmt.Errorf("path not found")
}
return filePath.(string), nil
} else {
return "", fmt.Errorf("error getting path: %v", resp.StatusCode)
}
}
Hi~ I want to download large files from telegram. Telegram api docs says that I need own bot api. So:
In my code I define bot like this:
And I'm trying to download files like this:
This function gives error "Bad Request: file is too big" when calling bot.GetFile. Is there a proper way to do that?