@aanton/telegram-webpage-monitor-bot 中文文档教程

发布于 3年前 浏览 15 项目主页 更新于 3年前

@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 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
  • 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 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
  • 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
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文