Support for images

This commit is contained in:
HugeFrog24
2026-05-28 20:54:09 +02:00
parent 8c699ab70a
commit d97a2c3132
20 changed files with 1303 additions and 171 deletions
+4 -12
View File
@@ -8,8 +8,6 @@ import (
"io"
"mime/multipart"
"net/http"
tgbot "github.com/go-telegram/bot"
)
const (
@@ -56,17 +54,11 @@ func (b *Bot) generateSpeech(ctx context.Context, text string) (io.Reader, error
// ogen-generated encoder: AdditionalFormats (nil slice) is always written as an empty
// string with Content-Type: application/json, which ElevenLabs rejects with 400.
func (b *Bot) transcribeVoice(ctx context.Context, fileID string) (string, error) {
// 1. Resolve and download the voice file from Telegram.
fileInfo, err := b.tgBot.GetFile(ctx, &tgbot.GetFileParams{FileID: fileID})
// 1. Resolve and download the voice file from Telegram via the shared helper.
audioBytes, err := b.downloadTelegramFile(ctx, fileID)
if err != nil {
return "", fmt.Errorf("telegram GetFile error: %w", err)
return "", err
}
downloadURL := b.tgBot.FileDownloadLink(fileInfo)
audioResp, err := http.Get(downloadURL) //nolint:noctx
if err != nil {
return "", fmt.Errorf("voice download error: %w", err)
}
defer audioResp.Body.Close()
// 2. Build multipart body with binary audio — bypasses SDK encoding issues.
var buf bytes.Buffer
@@ -78,7 +70,7 @@ func (b *Bot) transcribeVoice(ctx context.Context, fileID string) (string, error
if err != nil {
return "", fmt.Errorf("multipart create file error: %w", err)
}
if _, err := io.Copy(part, audioResp.Body); err != nil {
if _, err := io.Copy(part, bytes.NewReader(audioBytes)); err != nil {
return "", fmt.Errorf("multipart copy error: %w", err)
}
if err := mw.Close(); err != nil {