@hoangnam.io/qa-tools
Version:
Logging, Error handling, Notifying for Express codebase
29 lines (24 loc) • 895 B
JavaScript
const axios = require("axios");
function sendNotifyToDiscord(config, message) {
if (!config || !config.url || !config.enable) return;
return axios.post(config.url, { content: message });
}
function sendNotifyToTelegram(config, message) {
if (!config || !config.url || !config.enable) return;
return axios.post(config.url, { chat_id: config.chatId, text: message });
}
function getNotifier({ discord = { url: null, enable: true }, telegram = { url: null, chatId: null, enable: true } }) {
return {
send: async (textMessage) => {
return Promise.allSettled([
sendNotifyToDiscord(discord, textMessage),
sendNotifyToTelegram(telegram, textMessage),
]);
// return Promise.all([
// sendNotifyToDiscord(discord, textMessage),
// sendNotifyToTelegram(telegram, textMessage),
// ]);
},
};
}
module.exports = { getNotifier };