feat: initial commit

This commit is contained in:
2026-04-16 19:39:02 +02:00
commit 50d1686b1e
44 changed files with 2089 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package telegram
import (
"context"
"fmt"
"io"
"net/http"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
type TelegramFileDownloader struct {
bot *tgbotapi.BotAPI
client *http.Client
}
func NewTelegramFileDownloader(bot *tgbotapi.BotAPI) *TelegramFileDownloader {
return &TelegramFileDownloader{
bot: bot,
client: &http.Client{},
}
}
func (d *TelegramFileDownloader) Download(ctx context.Context, fileID string) ([]byte, string, error) {
file, err := d.bot.GetFile(tgbotapi.FileConfig{FileID: fileID})
if err != nil {
return nil, "", fmt.Errorf("get file info: %w", err)
}
url := file.Link(d.bot.Token)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, "", fmt.Errorf("create download request: %w", err)
}
resp, err := d.client.Do(req)
if err != nil {
return nil, "", fmt.Errorf("download file: %w", err)
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, "", fmt.Errorf("read file body: %w", err)
}
return data, "audio/ogg", nil
}