diff --git a/core/lib/external/tgkit/media.go b/core/lib/external/tgkit/media.go index 2fd0c07..ff3cfd3 100644 --- a/core/lib/external/tgkit/media.go +++ b/core/lib/external/tgkit/media.go @@ -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) }