mirror of
https://github.com/HugeFrog24/go-telegram-bot.git
synced 2026-06-29 22:07:12 +00:00
Support for images
This commit is contained in:
+4
-12
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user