Added image extension detecting #58

Merged
romanskijdev merged 1 commits from fix-permissions into main 2026-07-12 19:18:35 +03:00
1 changed files with 18 additions and 1 deletions

View File

@ -11,6 +11,22 @@ import (
"github.com/sirupsen/logrus"
)
func detectImageExtension(data []byte) string {
contentType := http.DetectContentType(data)
switch contentType {
case "image/png":
return "photo.png"
case "image/jpeg":
return "photo.jpg"
case "image/webp":
return "photo.webp"
case "image/gif":
return "photo.gif"
default:
return "photo.jpg"
}
}
// SendPhoto отправляет фото по URL, пути к файлу или base64
func (c *Client) SendPhoto(chatID int64, source string, caption string, opts ...MessageOptions) (*SentMessage, error) {
var photo tgbotapi.RequestFileData
@ -23,7 +39,8 @@ func (c *Client) SendPhoto(chatID int64, source string, caption string, opts ...
if err != nil {
return nil, fmt.Errorf("tgkit: decode base64: %w", err)
}
photo = tgbotapi.FileBytes{Name: "photo.jpg", Bytes: data}
fileName := detectImageExtension(data)
photo = tgbotapi.FileBytes{Name: fileName, Bytes: data}
default:
photo = tgbotapi.FilePath(source)
}