Cache inline results and use fixed length ids (#25)

This commit is contained in:
Egor Cherniak 2023-08-22 17:26:56 +03:00 committed by GitHub
parent 3735efc270
commit 645dee5457
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 2 deletions

View File

@ -17,4 +17,5 @@ public class AlertBotProperties {
private String name;
@NotNull
private String chatId;
private Integer cacheOptionsSec = 0;
}

View File

@ -10,6 +10,7 @@ import dev.vality.alerting.mayday.UserAlert;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.thrift.TException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
@ -98,7 +99,7 @@ public class InlineHandler implements CommonHandler<AnswerInlineQuery> {
String description,
InputTextMessageContent inputTextMessageContent) {
InlineQueryResultArticle inlineQueryResultArticle = new InlineQueryResultArticle();
inlineQueryResultArticle.setId(id);
inlineQueryResultArticle.setId(DigestUtils.sha256Hex(id));
inlineQueryResultArticle.setTitle(id);
inlineQueryResultArticle.setDescription(description);
inlineQueryResultArticle.setInputMessageContent(inputTextMessageContent);

View File

@ -63,7 +63,7 @@ public class AlertBot extends TelegramLongPollingBot {
execute(sendMessage);
} else if (answer instanceof AnswerInlineQuery answerInlineQuery) {
answerInlineQuery.setIsPersonal(true);
answerInlineQuery.setCacheTime(0);
answerInlineQuery.setCacheTime(alertBotProperties.getCacheOptionsSec());
execute(answerInlineQuery);
}
}