Refactored notification messsages into an array of acceptable types.
This commit is contained in:
1 parent
c4168a5d75
commit
afc9d46bd7
1 file changed
+11
-9
@@ -1,5 +1,12 @@
|
|||||||
const SERVICE_NAME = "NotificationService";
|
const SERVICE_NAME = "NotificationService";
|
||||||
const TELEGRAM_API_BASE_URL = "https://api.telegram.org/bot";
|
const TELEGRAM_API_BASE_URL = "https://api.telegram.org/bot";
|
||||||
|
const PLATFORM_TYPES = ['telegram', 'slack', 'discord'];
|
||||||
|
|
||||||
|
const MESSAGE_FORMATTERS = {
|
||||||
|
telegram: (messageText, chatId) => ({ chat_id: chatId, text: messageText }),
|
||||||
|
slack: (messageText) => ({ text: messageText }),
|
||||||
|
discord: (messageText) => ({ content: messageText })
|
||||||
|
};
|
||||||
|
|
||||||
class NotificationService {
|
class NotificationService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
@@ -39,16 +46,11 @@ class NotificationService {
|
|||||||
monitor.url
|
monitor.url
|
||||||
);
|
);
|
||||||
|
|
||||||
if (platform === 'telegram') {
|
if (!PLATFORM_TYPES.includes(platform)) {
|
||||||
return { chat_id: chatId, text: messageText };
|
return undefined;
|
||||||
}
|
}
|
||||||
if (platform === 'slack') {
|
|
||||||
return { text: messageText };
|
return MESSAGE_FORMATTERS[platform](messageText, chatId);
|
||||||
}
|
|
||||||
if (platform === 'discord') {
|
|
||||||
return { content: messageText };
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user