Skip to content

aanton/telegram-webpage-monitor-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@aanton/telegram-webpage-monitor-bot

Monitors a webpage detecting when a custom block/snippet has changed & sends a message to a Telegram chat using a Telegram bot.

Installation

npm install @aanton/telegram-webpage-monitor-bot

Usage

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);

Configuration parameters

  • name: Unique name, used in logs
  • url: Webpage URL to monitor
  • url: Local storage to save the block/snippet extracted from the webpage using the extractSnippet function
  • telegramBotToken: Telegram bot token
  • 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

About

Telegram bot that monitors a block of a webpage

Resources

Stars

Watchers

Forks

Packages

No packages published