Monitors a webpage detecting when a custom block/snippet has changed & sends a message to a Telegram chat using a Telegram bot.
npm install @aanton/telegram-webpage-monitor-bot
const path = require('path');
const cheerio = require('cheerio');
const monitorWebpage = require('@aanton/telegram-webpage-monitor-bot');
monitorWebpage({
name: 'first-link-monitor',
url: 'https://mydomain.com',
storage: path.resolve(__dirname + '/.storage'),
telegramBotToken: ...,
telegramChatId: ...,
telegramSendMessageOptions: {},
extractSnippet: function(html) {
const $ = cheerio.load(html);
return $("a[href*='www.mydomain.com']").first().attr("href");
})
.then(JSON.stringify)
.then(console.log)
.catch(console.log);
name
: Unique name, used in logsurl
: Webpage URL to monitorurl
: Local storage to save the block/snippet extracted from the webpage using theextractSnippet
functiontelegramBotToken
: Telegram bot token- Create a Telegram bot using BotFather
telegramChatId
: Telegram chat identifier- It can be a private conversation with the bot (you must send previously a message to the bot), a group conversation (the bot must be a member) or a channel conversation (the bot must be an administrator member)
- The chat identifier can be obtained using @ChannelIdBot
telegramSendMessageOptions
: Optional telegram message options- Use it for enable HTML/Markdown format, disable links preview or disable notifications
extractSnippet
: Function that extracts the snippet from the webpage HTML