feat: Add AI-generated congratulation after book creation

This commit is contained in:
2025-02-16 19:03:57 +03:00
parent dc1ac12213
commit f3356758c7
@@ -26,6 +26,7 @@ public class BookCreationServiceImpl implements BookCreationService {
private final TelegramClientService telegramClientService;
private final BookRepository bookRepository;
private final BookCommonService bookCommonService;
private final OpenRouterService openRouterService;
@Override
public void handleNewAddRequest(BotUser user, String text) {
@@ -90,6 +91,24 @@ public class BookCreationServiceImpl implements BookCreationService {
String message = String.format("✅ Книга успешно добавлена!\n\n%s",
bookCommonService.formatBookDetails(book));
telegramClientService.sendMessageWithMarkdown(user, message);
// Генерируем и отправляем поздравление
try {
String prompt = String.format("Придумай креативное поздравление с прочтением книги \"%s\". " +
"Учитывай что пользователь поставил оценку %d/10. " +
"Используй эмоджи и Markdown разметку. Будь кратким.",
cache.getTitle(), cache.getRating());
String congrat = openRouterService.getChatResponse(
prompt,
TextRole.RECOMMENDER
);
telegramClientService.sendMessageWithMarkdown(user, "🎉 *Поздравляю с прочтением!*\n\n" + congrat);
} catch (Exception e) {
log.error("Error generating congratulation for user {}", user.getId(), e);
telegramClientService.sendMessage(user, "📚 Спасибо за добавление книги!");
}
}
default -> {