This commit is contained in:
parent
d8f2c623a9
commit
bef96bcc0d
@ -10,6 +10,7 @@ import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.simple.domain.unit.AnswerText;
|
||||
import dev.struchkov.godfather.telegram.domain.ChatAction;
|
||||
import dev.struchkov.godfather.telegram.domain.ClientBotCommand;
|
||||
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
|
||||
import dev.struchkov.godfather.telegram.domain.attachment.CommandAttachment;
|
||||
import dev.struchkov.godfather.telegram.main.context.MailPayload;
|
||||
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
|
||||
@ -73,6 +74,11 @@ public class PersonalChatGPTUnit implements PersonUnitConfiguration {
|
||||
ClientBotCommand.builder()
|
||||
.key(Cmd.HELP)
|
||||
.description("help in use")
|
||||
.build(),
|
||||
|
||||
ClientBotCommand.builder()
|
||||
.key(Cmd.SUPPORT_DEV)
|
||||
.description("Support project development")
|
||||
.build()
|
||||
));
|
||||
}
|
||||
@ -105,9 +111,19 @@ public class PersonalChatGPTUnit implements PersonUnitConfiguration {
|
||||
.triggerCheck(mail -> mail.getFromPersonId().equals(appProperty.getTelegramId()))
|
||||
.answer(message -> {
|
||||
telegramService.executeAction(message.getFromPersonId(), ChatAction.TYPING);
|
||||
|
||||
final long countMessages = chatGptService.getCountMessages(chatInfo.getChatId());
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("Wait... Response is being generated...\nIt might take a long time ⏳");
|
||||
|
||||
if (countMessages > 40) {
|
||||
builder.append(Strings.escapeMarkdown("\n-- -- -- -- --\nWe recommend periodically clearing the conversation context (/clear_context). If this is not done, then the memory resources on your PC will run out."));
|
||||
}
|
||||
|
||||
final BoxAnswer answerWait = BoxAnswer.builder()
|
||||
.recipientPersonId(message.getFromPersonId())
|
||||
.message("Wait... Response is being generated...\nIt might take a long time ⏳")
|
||||
.message(builder.toString())
|
||||
.build();
|
||||
telegramSending.send(answerWait);
|
||||
final String answerText = chatGptService.sendNewMessage(chatInfo.getChatId(), message.getText());
|
||||
@ -178,6 +194,49 @@ public class PersonalChatGPTUnit implements PersonUnitConfiguration {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Unit(value = UnitName.SUPPORT, main = true)
|
||||
public AnswerText<Mail> support() {
|
||||
return AnswerText.<Mail>builder()
|
||||
.triggerCheck(
|
||||
mail -> {
|
||||
if (mail.getFromPersonId().equals(appProperty.getTelegramId())) {
|
||||
final List<Attachment> attachments = mail.getAttachments();
|
||||
final Optional<CommandAttachment> optCommand = Attachments.findFirstCommand(attachments);
|
||||
if (optCommand.isPresent()) {
|
||||
final CommandAttachment command = optCommand.get();
|
||||
return Cmd.SUPPORT_DEV.equals(command.getCommandType());
|
||||
}
|
||||
|
||||
final Optional<ButtonClickAttachment> optClick = Attachments.findFirstButtonClick(attachments);
|
||||
if (optClick.isPresent()) {
|
||||
final ButtonClickAttachment click = optClick.get();
|
||||
return Cmd.SUPPORT_DEV.equals(click.getRawCallBackData());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
)
|
||||
.answer(
|
||||
boxAnswer("""
|
||||
❤️ *Support Develop*
|
||||
|
||||
Sponsorship makes a project sustainable because it pays for the time of the maintainers of that project, a very scarce resource that is spent on developing new features, fixing bugs, improving stability, solving problems, and general support. *The biggest bottleneck in Open Source is time.*
|
||||
|
||||
TON: `struchkov-mark.ton`
|
||||
|
||||
BTC:
|
||||
`bc1pt49vnp43c4mktk6309zlq3020dzd0p89gc8d90zzn4sgjvck56xs0t86vy`
|
||||
|
||||
ETH (USDT, DAI, USDC):
|
||||
`0x7668C802Bd71Be965671D4Bbb1AD90C7f7f32921`
|
||||
|
||||
BNB (USDT, DAI, USDC):
|
||||
`0xDa41aC95f606850f2E01ba775e521Cd385AA7D03`
|
||||
""")
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Unit(value = UnitName.HELP, main = true)
|
||||
public AnswerText<Mail> help() {
|
||||
return AnswerText.<Mail>builder()
|
||||
|
@ -1,7 +1,9 @@
|
||||
package dev.struchkov.example.bot.unit;
|
||||
|
||||
import dev.struchkov.example.bot.conf.AppProperty;
|
||||
import dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
|
||||
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -23,17 +25,18 @@ public class StartNotify {
|
||||
final BoxAnswer boxAnswer = BoxAnswer.builder()
|
||||
.message(MessageFormat.format(
|
||||
"""
|
||||
Hello 👋
|
||||
Your personal ChatGPT bot has been successfully launched.
|
||||
|
||||
Use the help command to find out about the possibilities 🚀
|
||||
-- -- -- -- --
|
||||
🤘 Version: {0}
|
||||
👨💻 Developer: [https://mark.struchkov.dev/](Struchkov Mark)
|
||||
💊 Docs: https://docs.struchkov.dev/chatgpt-telegram-bot
|
||||
""",
|
||||
Hello 👋
|
||||
Your personal ChatGPT bot has been successfully launched.
|
||||
|
||||
Use the help command to find out about the possibilities 🚀
|
||||
-- -- -- -- --
|
||||
🤘 Version: {0}
|
||||
👨💻 Developer: [https://mark.struchkov.dev/](Struchkov Mark)
|
||||
💊 Docs: https://docs.struchkov.dev/chatgpt-telegram-bot
|
||||
""",
|
||||
appProperty.getVersion()
|
||||
))
|
||||
.keyBoard(InlineKeyBoard.inlineKeyBoard(SimpleButton.simpleButton("❤️ Support Develop", "support")))
|
||||
.payload(DISABLE_WEB_PAGE_PREVIEW, true)
|
||||
.build();
|
||||
boxAnswer.setRecipientIfNull(appProperty.getTelegramId());
|
||||
|
@ -9,5 +9,6 @@ public class Cmd {
|
||||
public static final String PROMPT = "prompt";
|
||||
public static final String GPT = "gpt";
|
||||
public static final String HELP = "help";
|
||||
public static final String SUPPORT_DEV = "support";
|
||||
|
||||
}
|
||||
|
@ -11,4 +11,6 @@ public class UnitName {
|
||||
public static final String PROMPT = "PROMPT";
|
||||
public static final String ACCESS_ERROR = "ACCESS_ERROR";
|
||||
|
||||
public static final String SUPPORT = "SUPPORT";
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user