@aanton/telegram-webpage-monitor-bot 中文文档教程
@aanton/telegram-webpage-monitor-bot
监视网页,检测自定义块/代码段何时更改 & 使用 Telegram 机器人向 Telegram 聊天发送消息。
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 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
@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 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