Skip to content

Commit

Permalink
Server: added parameter telegram:chatID
Browse files Browse the repository at this point in the history
  • Loading branch information
olton committed Dec 22, 2021
1 parent 472644e commit 37e6f3b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions server/helpers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const getDefaultConfig = (extConfig = {}) => {
"tokenInfo": "",
"tokenAlert": "",
"chatID": "",
"chatIDInfo": "",
"chatIDAlert": ""
},
"discord": {
Expand Down
11 changes: 4 additions & 7 deletions server/helpers/messangers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const fetch = require("node-fetch")
const {hostname} = require("os")
const {parseTelegramChatIDs} = require("./parsers.js");
const {logging} = require("./logs");
const {isset} = require("./isset");

const sendToDiscord = (url, message, {username = "Mina Monitor", avatar_url = ""} = {}) => {
const params = {
Expand All @@ -27,9 +25,8 @@ const sendToTelegram = (message, {token, recipients}) => {
if (!token || !recipients) return

const TELEGRAM_URL = TELEGRAM_BOT_URL.replace("%TOKEN%", token)
const ids = parseTelegramChatIDs(recipients)

for (const id of ids) {
for (const id of recipients) {
const url = TELEGRAM_URL.replace("%CHAT_ID%", id).replace("%MESSAGE%", message)
fetch(encodeURI(url)).catch((e)=>{
logging("Error! Can't send message to telegram")
Expand All @@ -46,7 +43,7 @@ const sendTo = (check, message, isAlert = false) => {
logging(message)

if (telegramConfig && (check === 'OK' || alertToTelegram.includes(check))) {
let {token = "", tokenInfo = "", tokenAlert = "", chatIDInfo = "", chatIDAlert = ""} = telegramConfig
let {token = "", tokenInfo = "", tokenAlert = "", chatID = "", chatIDInfo = "", chatIDAlert = ""} = telegramConfig

if (token) {
if (!tokenInfo) tokenInfo = token
Expand All @@ -57,9 +54,9 @@ const sendTo = (check, message, isAlert = false) => {
if (tokenAlert && !tokenInfo) tokenInfo = tokenAlert

if (isAlert) {
sendToTelegram(signedMessage, {token: tokenAlert, recipients: chatIDAlert})
sendToTelegram(signedMessage, {token: tokenAlert, recipients: parseTelegramChatIDs(chatID).concat(parseTelegramChatIDs(chatIDAlert))})
} else {
sendToTelegram(signedMessage, {token: tokenInfo, recipients: chatIDInfo})
sendToTelegram(signedMessage, {token: tokenInfo, recipients: parseTelegramChatIDs(chatID).concat(parseTelegramChatIDs(chatIDInfo))})
}
}

Expand Down

0 comments on commit 37e6f3b

Please sign in to comment.