From b6e63b5a80928b08691004512ab95a88a867e621 Mon Sep 17 00:00:00 2001
From: Mikhail Petrov <azalio@azalio.net>
Date: Tue, 31 Dec 2024 16:04:50 +0300
Subject: [PATCH] Fix caption (#3)

* refactor: Set caption to enhancedPrompt in HandleCommand

* fix: Ensure caption length is within Telegram limits
---
 internal/service/bot_service.go | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/internal/service/bot_service.go b/internal/service/bot_service.go
index f0314d4..99b818e 100644
--- a/internal/service/bot_service.go
+++ b/internal/service/bot_service.go
@@ -115,6 +115,12 @@ func (s *BotServiceImpl) HandleCommand(ctx context.Context, command string, args
 			})
 			// Fallback to the original prompt in case of error
 			enhancedPrompt = args
+			caption = enhancedPrompt
+			
+			// Ensure caption length is within Telegram limits
+			if len(caption) > 1024 {
+				caption = caption[:1024]
+			}
 		}
 
 		// Generate an image using the enhanced prompt
@@ -147,6 +153,10 @@ func (s *BotServiceImpl) SendPhoto(ctx context.Context, chatID int64, photo []by
 		Bytes: photo,
 	})
 
+	// Ensure caption length is within Telegram limits
+	if len(caption) > 1024 {
+		caption = caption[:1024]
+	}
 	photoMsg.Caption = caption
 
 	_, err := s.Bot.Send(photoMsg)