diff --git a/src/main/java/dev/struchkov/example/bot/handler/InlineChoseHandler.java b/src/main/java/dev/struchkov/example/bot/handler/InlineChoseHandler.java index aae8072..8669b35 100644 --- a/src/main/java/dev/struchkov/example/bot/handler/InlineChoseHandler.java +++ b/src/main/java/dev/struchkov/example/bot/handler/InlineChoseHandler.java @@ -4,6 +4,7 @@ import dev.struchkov.example.bot.conf.AppProperty; import dev.struchkov.example.bot.service.InlineStorage; import dev.struchkov.godfather.main.domain.EventContainer; import dev.struchkov.godfather.simple.context.service.EventHandler; +import dev.struchkov.godfather.simple.domain.BoxAnswer; import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import dev.struchkov.openai.context.GPTClient; import dev.struchkov.openai.domain.common.GptMessage; @@ -16,10 +17,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.telegram.telegrambots.meta.api.objects.inlinequery.ChosenInlineQuery; +import java.text.MessageFormat; import java.util.List; import java.util.Optional; -import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer; +import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENABLE_MARKDOWN; @Slf4j @Component @@ -39,18 +41,22 @@ public class InlineChoseHandler implements EventHandler { if (appProperty.getTelegramIds().contains(personId)) { final Optional optRequest = inlineStorage.getQuery(chosenInlineQuery.getResultId()); if (optRequest.isPresent()) { - final String request = optRequest.get(); + final String question = optRequest.get(); final GptResponse gptResponse = gptClient.execute( GptRequest.builder() .model(GPT3Model.GPT_3_5_TURBO) - .message( - GptMessage.fromUser(request) - ) + .message(GptMessage.fromUser(question)) .build() ); final List choices = gptResponse.getChoices(); final String answer = choices.get(choices.size() - 1).getMessage().getContent(); - telegramSending.replaceInlineMessage(chosenInlineQuery.getInlineMessageId(), boxAnswer(answer)); + telegramSending.replaceInlineMessage( + chosenInlineQuery.getInlineMessageId(), + BoxAnswer.builder() + .message(MessageFormat.format("Your question to ChatGPT:\n{0}\n\nAnswer ChatGpt:\n{1}\n-- -- -- -- --\n[Launch your personal ChatGPT Telegram bot](https://docs.struchkov.dev/chatgpt-telegram-bot/en/latest/)", question, answer)) + .payload(ENABLE_MARKDOWN) + .build() + ); } } }