Add feedback message controls for Telegram bot

Introduced configurable feedback message options for the Telegram bot in ApplicationProperties and settings.yml.template, allowing enabling/disabling of feedback messages for users and channels. Updated TelegramPipelineBot to respect the new feedback settings when sending messages.
This commit is contained in:
Ludy87 2025-12-18 18:16:16 +01:00
parent cded7cd92a
commit c9a28eef31
No known key found for this signature in database
GPG Key ID: 92696155E0220F94
3 changed files with 71 additions and 16 deletions

View File

@ -336,8 +336,8 @@ public class ApplicationProperties {
throw new UnsupportedProviderException(
"Logout from the provider "
+ registrationId
+ " is not supported. "
+ "Report it at https://github.com/Stirling-Tools/Stirling-PDF/issues");
+ " is not supported. Report it at"
+ " https://github.com/Stirling-Tools/Stirling-PDF/issues");
};
}
}
@ -537,10 +537,10 @@ public class ApplicationProperties {
@Override
public String toString() {
return """
Driver {
driverName='%s'
}
"""
Driver {
driverName='%s'
}
"""
.formatted(driverName);
}
}
@ -646,6 +646,44 @@ public class ApplicationProperties {
private List<Long> allowChannelIDs = new ArrayList<>();
private long processingTimeoutSeconds = 180;
private long pollingIntervalMillis = 2000;
private Feedback feedback = new Feedback();
@Data
public static class Feedback {
private General general = new General();
private Channel channel = new Channel();
private User user = new User();
@Data
public static class General {
private Boolean enabled = true; // set to 'true' to enable feedback messages
}
@Data
public static class Channel {
private Boolean noValidDocument =
false; // set to 'true' to deny feedback messages in channels (to avoid
// spam)
private Boolean processingError =
false; // set to 'true' to deny feedback messages in channels (to avoid
// spam)
private Boolean errorMessage =
false; // set to 'true' to deny error feedback messages in channels (to
// avoid spam)
}
@Data
public static class User {
private Boolean noValidDocument =
false; // set to 'true' to deny feedback messages to users (to avoid
// spam)
private Boolean processingError =
false; // set to 'true' to deny feedback messages to users (to avoid
// spam)
private Boolean errorMessage =
false; // set to 'true' to deny error feedback messages to users (to avoid
}
}
}
@Data

View File

@ -107,13 +107,17 @@ public class TelegramPipelineBot extends TelegramLongPollingBot {
if (update.hasMessage() && update.getMessage().hasText()) {
String message_text = update.getMessage().getText();
long chat_id = update.getMessage().getChatId();
if (message_text.equals("/start")) {
if ("/start".equals(message_text)) {
sendMessage(
chat_id,
"Welcome to the SPDF Telegram Bot!\n\n"
+ "To get started, please send me a PDF document that you would like to process."
+ " Make sure the document is in PDF format.\n\n"
+ "Once I receive your document, I'll begin processing it through the pipeline.");
"""
Welcome to the SPDF Telegram Bot!
To get started, please send me a PDF document that you would like to process.
Make sure the document is in PDF format.
Once I receive your document, I'll begin processing it through the pipeline.
""");
return;
}
}
@ -122,10 +126,11 @@ public class TelegramPipelineBot extends TelegramLongPollingBot {
handleIncomingFile(message);
return;
}
sendMessage(
chat.getId(),
"No valid file found in the message. Please send a document to process.");
if (telegramProperties.getFeedback().getGeneral().getEnabled()) {
sendMessage(
chat.getId(),
"No valid file found in the message. Please send a document to process.");
}
}
// ---------------------------
@ -237,7 +242,8 @@ public class TelegramPipelineBot extends TelegramLongPollingBot {
if (!hasJsonConfig(chatId)) {
sendMessage(
chatId,
"No JSON configuration file found in the pipeline inbox folder. Please contact the administrator.");
"No JSON configuration file found in the pipeline inbox folder. Please contact"
+ " the administrator.");
return;
}

View File

@ -124,6 +124,17 @@ telegram:
allowChannelIDs: [] # List of allowed Telegram channel IDs (e.g. [-1001234567890, -1009876543210]). Leave empty to allow all channels.
processingTimeoutSeconds: 180 # Maximum time in seconds to wait for processing a Telegram request
pollingIntervalMillis: 2000 # Interval in milliseconds between polling for new messages
feedback:
general:
enabled: true # set to 'true' to enable feedback messages
channel:
noValidDocument: false # set to 'true' to deny feedback messages in channels (to avoid spam)
processingError: false # set to 'true' to deny feedback messages in channels (to avoid spam)
errorMessage: false # set to 'true' to deny error messages in channels (to avoid spam)
user:
noValidDocument: false # set to 'true' to deny feedback messages to users (to avoid spam)
processingError: false # set to 'true' to deny feedback messages to users (to avoid spam)
errorMessage: false # set to 'true' to deny error messages to users (to avoid spam)
legal:
termsAndConditions: https://www.stirling.com/legal/terms-of-service # URL to the terms and conditions of your application (e.g. https://example.com/terms). Empty string to disable or filename to load from local file in static folder