Skip to content

Commit a2fae00

Browse files
committed
Configure placeholder message when a file needs to be processed
1 parent 251eefb commit a2fae00

2 files changed

Lines changed: 29 additions & 33 deletions

File tree

src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static com.github.stickerifier.stickerify.telegram.Answer.FILE_ALREADY_VALID;
99
import static com.github.stickerifier.stickerify.telegram.Answer.FILE_READY;
1010
import static com.github.stickerifier.stickerify.telegram.Answer.FILE_TOO_LARGE;
11+
import static com.github.stickerifier.stickerify.telegram.Answer.PROCESSING;
1112
import static com.pengrad.telegrambot.model.request.ParseMode.MarkdownV2;
1213
import static java.util.HashSet.newHashSet;
1314
import static java.util.concurrent.Executors.newThreadPerTaskExecutor;
@@ -23,14 +24,15 @@
2324
import com.pengrad.telegrambot.TelegramBot;
2425
import com.pengrad.telegrambot.TelegramException;
2526
import com.pengrad.telegrambot.UpdatesListener;
26-
import com.pengrad.telegrambot.model.LinkPreviewOptions;
2727
import com.pengrad.telegrambot.model.Update;
2828
import com.pengrad.telegrambot.model.request.ReplyParameters;
29+
import com.pengrad.telegrambot.model.request.richmessages.InputRichMessage;
2930
import com.pengrad.telegrambot.request.BaseRequest;
3031
import com.pengrad.telegrambot.request.GetFile;
3132
import com.pengrad.telegrambot.request.GetUpdates;
3233
import com.pengrad.telegrambot.request.SendDocument;
33-
import com.pengrad.telegrambot.request.SendMessage;
34+
import com.pengrad.telegrambot.request.richmessages.SendRichMessage;
35+
import com.pengrad.telegrambot.request.richmessages.SendRichMessageDraft;
3436
import com.pengrad.telegrambot.response.BaseResponse;
3537
import org.slf4j.event.Level;
3638

@@ -54,6 +56,7 @@ public record Stickerify(TelegramBot bot, Executor executor) implements UpdatesL
5456
private static final StructuredLogger LOGGER = new StructuredLogger(Stickerify.class);
5557
private static final String BOT_TOKEN = System.getenv("STICKERIFY_TOKEN");
5658
private static final ThreadFactory VIRTUAL_THREAD_FACTORY = Thread.ofVirtual().name("Virtual-", 0).factory();
59+
private static final InputRichMessage PROCESSING_MESSAGE = new InputRichMessage().html(PROCESSING.getText());
5760

5861
/**
5962
* Instantiate the bot processing requests with virtual threads.
@@ -127,8 +130,11 @@ private void answerFile(TelegramRequest request, TelegramFile file) {
127130

128131
private void answerFile(TelegramRequest request, String fileId) {
129132
Set<Path> pathsToDelete = newHashSet(2);
133+
var processingMessage = new SendRichMessageDraft(request.getChatId(), 1, PROCESSING_MESSAGE);
130134

131135
try {
136+
execute(processingMessage);
137+
132138
var originalFile = retrieveFile(fileId);
133139
pathsToDelete.add(originalFile.toPath());
134140

@@ -209,12 +215,9 @@ private void answerText(TelegramRequest request) {
209215
}
210216

211217
private void answerText(Answer answer, TelegramRequest request) {
212-
var previewOptions = new LinkPreviewOptions().isDisabled(answer.isDisableLinkPreview());
213-
214-
var answerWithText = new SendMessage(request.getChatId(), answer.getText())
218+
var answerWithText = new SendRichMessage(request.getChatId(), new InputRichMessage().markdown(answer.getText()))
215219
.replyParameters(new ReplyParameters(request.getMessageId()))
216-
.parseMode(MarkdownV2)
217-
.linkPreviewOptions(previewOptions);
220+
.disableNotification(true);
218221

219222
try {
220223
execute(answerWithText);

src/main/java/com/github/stickerifier/stickerify/telegram/Answer.java

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,53 @@
66
public enum Answer {
77

88
HELP("""
9-
Send me the media you want to convert and I will take care of the rest\\.
9+
Send me the media you want to convert and I will take care of the rest.
1010
1111
Based on what you send, I will answer the following:
12-
\\- the converted media, if you sent a supported file \\(images, gifs, standard and video stickers are supported\\)
13-
\\- no file, if you sent a media already suiting Telegram's requirements
14-
\\- an error message, if you sent either an unsupported or a corrupted file
15-
\\- an informative message for any message without a file
12+
- the converted media, if you sent a supported file (images, gifs, standard and video stickers are supported)
13+
- no file, if you sent a media already suiting Telegram's requirements
14+
- an error message, if you sent either an unsupported or a corrupted file
15+
- an informative message for any message without a file
1616
17-
Once the file is ready, head to [Stickers](https://t.me/Stickers) to create a new sticker\\.
17+
Once the file is ready, head to [Stickers](https://t.me/Stickers) to create a new sticker.
1818
"""),
1919
FILE_READY("""
2020
Your sticker file is ready\\!
2121
Head to [Stickers](https://t.me/Stickers) to create a new sticker\\.
2222
"""),
2323
FILE_ALREADY_VALID("""
24-
The media you sent was already suitable to be a Telegram sticker\\.
25-
Send it to [Stickers](https://t.me/Stickers) to add it as a new sticker\\.
24+
The media you sent was already suitable to be a Telegram sticker.
25+
Send it to [Stickers](https://t.me/Stickers) to add it as a new sticker.
2626
"""),
2727
FILE_TOO_LARGE("""
28-
The file can't be converted because Telegram bots can't handle files larger than 20 MB at the moment: please send a smaller one\\.
28+
The file can't be converted because Telegram bots can't handle files larger than 20 MB at the moment: please send a smaller one.
2929
"""),
3030
ABOUT("""
31-
This bot is open source, check it out on [Github](https://github.com/Stickerifier/Stickerify)\\.
31+
This bot is open source, check it out on [Github](https://github.com/Stickerifier/Stickerify).
3232
33-
Looking for sticker packs? Try [MeminiCustom](https://t.me/addstickers/MeminiCustom) and [VideoMemini](https://t.me/addstickers/VideoMemini)\\!
33+
Looking for sticker packs? Try [MeminiCustom](https://t.me/addstickers/MeminiCustom) and [VideoMemini](https://t.me/addstickers/VideoMemini)!
3434
"""),
3535
ERROR("""
36-
The file conversion was unsuccessful: only images, gifs, standard and video stickers are supported\\.
36+
The file conversion was unsuccessful: only images, gifs, standard and video stickers are supported.
3737
38-
If you think it should have worked, please report the issue on [Github](https://github.com/Stickerifier/Stickerify/issues/new/choose)\\.
39-
""", true),
38+
If you think it should have worked, please report the issue on [Github](https://github.com/Stickerifier/Stickerify/issues/new/choose).
39+
"""),
4040
PRIVACY_POLICY("""
41-
You can view our privacy policy by visiting [this link](https://stickerifier.github.io/Stickerify/PRIVACY_POLICY.html)\\.
41+
You can view our privacy policy by visiting [this link](https://stickerifier.github.io/Stickerify/PRIVACY_POLICY.html).
4242
43-
If you have any questions or concerns, feel free to reach out to us\\.
43+
If you have any questions or concerns, feel free to reach out to us.
44+
"""),
45+
PROCESSING("""
46+
<tg-thinking>Processing file...</tg-thinking>
4447
""");
4548

4649
private final String text;
47-
private final boolean disableLinkPreview;
4850

4951
Answer(String text) {
50-
this(text, false);
51-
}
52-
53-
Answer(String text, boolean disableLinkPreview) {
5452
this.text = text;
55-
this.disableLinkPreview = disableLinkPreview;
5653
}
5754

5855
public String getText() {
5956
return text;
6057
}
61-
62-
public boolean isDisableLinkPreview() {
63-
return disableLinkPreview;
64-
}
6558
}

0 commit comments

Comments
 (0)