Minor cleanup to notifications

This commit is contained in:
Jason House
2020-08-05 19:17:56 +09:00
parent ecb248d638
commit bb9e3538e2
4 changed files with 17 additions and 4 deletions

View File

@@ -13,5 +13,5 @@ package com.jasonhhouse.gaps.notifications;
public interface NotificationAgent {
boolean isEnabled();
void sendMessage(String level, String message);
void sendMessage(String level, String title, String message);
}

View File

@@ -41,7 +41,7 @@ public class TelegramNotificationAgent implements NotificationAgent {
}
@Override
public void sendMessage(String level, String message) {
public void sendMessage(String level, String title, String message) {
HttpUrl url = new HttpUrl.Builder()
.scheme("https")
@@ -50,7 +50,7 @@ public class TelegramNotificationAgent implements NotificationAgent {
.addPathSegment("sendMessage")
.build();
String telegramMessage = String.format("{\"chat_id\":\"%s\", \"text\":\"%s\", \"parse_mode\":\"HTML\"}", chatId, message);
String telegramMessage = String.format("{\"chat_id\":\"%s\", \"text\":\"%s\", \"parse_mode\":\"HTML\"}", chatId, String.format("<strong>%s</strong>\n%s", title, message));
LOGGER.info("telegramMessage {}", telegramMessage);
RequestBody body = RequestBody.create(telegramMessage, MediaType.get("application/json"));

View File

@@ -22,4 +22,6 @@ public interface Notification {
void recommendedMoviesSearchFailed(PlexServer plexServer, PlexLibrary plexLibrary, String error);
void recommendedMoviesSearchFinished(PlexServer plexServer, PlexLibrary plexLibrary);
void test();
}

View File

@@ -22,7 +22,10 @@ public class NotificationService implements Notification {
@Override
public void plexServerConnectSuccessful(PlexServer plexServer) {
notificationAgents.forEach(notificationAgent -> notificationAgent.sendMessage("INFO", String.format("<strong>Automatic Search</strong>\nConnection to Plex Server %s Successful", plexServer.getFriendlyName())));
notificationAgents
.stream()
.filter(NotificationAgent::isEnabled)
.forEach(notificationAgent -> notificationAgent.sendMessage("INFO", "Automatic Search", String.format("Connection to Plex Server %s Successful", plexServer.getFriendlyName())));
}
@Override
@@ -59,4 +62,12 @@ public class NotificationService implements Notification {
public void recommendedMoviesSearchFinished(PlexServer plexServer, PlexLibrary plexLibrary) {
}
@Override
public void test() {
notificationAgents
.stream()
.filter(NotificationAgent::isEnabled)
.forEach(notificationAgent -> notificationAgent.sendMessage("DEBUG", "Gaps Test", "Test Successful"));
}
}