mirror of
https://github.com/Kizuren/statusPage.git
synced 2026-01-09 07:59:48 +01:00
Added link property to endpoints and implemented telegram message sending api request.
This commit is contained in:
parent
96466747df
commit
fb24670358
2 changed files with 28 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ export default {
|
|||
{
|
||||
id : 'homepage', // optional
|
||||
name : 'Homepage',
|
||||
link : 'https://www.google.com', // optional
|
||||
url : 'https://www.google.com',
|
||||
request : { // fetch options
|
||||
method: 'GET',
|
||||
|
|
|
|||
27
watcher.js
27
watcher.js
|
|
@ -20,6 +20,23 @@ const checkContent = async (content, criterion) => {
|
|||
throw new Error('Invalid content check criterion.')
|
||||
}
|
||||
};
|
||||
const sendTelegramMessage = async (botToken, chatId, text) => {
|
||||
const url = `https://api.telegram.org/bot${botToken}/sendMessage`;
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
chat_id: chatId,
|
||||
text: text,
|
||||
}),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to send message: ${response.statusText}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
};
|
||||
|
||||
|
||||
while(true) {
|
||||
config.verbose && console.log('🔄 Pulse');
|
||||
|
|
@ -131,6 +148,16 @@ while(true) {
|
|||
if(endpointStatus.err) {
|
||||
console.log(`\t🔥 ${site.name || siteId} — ${endpoint.name || endpointId} [${endpointStatus.ttfb.toFixed(2)}ms]`);
|
||||
console.log(`\t→ ${endpointStatus.err}`);
|
||||
try {
|
||||
if(config.telegram?.botToken && config.telegram?.chatId) {
|
||||
/*await*/ sendTelegramMessage(config.telegram.botToken, config.telegram.chatId,
|
||||
`🔥 ERROR\n`+
|
||||
`${site.name || siteId} — ${endpoint.name || endpointId} [${endpointStatus.ttfb.toFixed(2)}ms]\n`
|
||||
`→ ${endpointStatus.err}`
|
||||
`\n→ ${endpoint.link || endpoint.url}\n`
|
||||
);
|
||||
}
|
||||
} catch(e) {console.error(e);}
|
||||
} else {
|
||||
let emoji = '🟢';
|
||||
if(endpointStatus.ttfb>config.responseTimeWarning)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue