Telegram Bot



QuebecRoundBot - Project Summary

Overview

QuebecRoundBot is an automated Telegram bot designed to monitor and notify about Quebec Immigration Program invitation rounds, as well as provide relevant news about the province through RSS feeds.

Problem It Solves

The project addresses the following needs:

  1. Tedious Manual Monitoring: Eliminates the need to constantly check the Quebec government’s official website for new immigration program invitation rounds.

  2. Centralized Information: Consolidates information from multiple RSS sources about Quebec into a single Telegram channel, facilitating access to relevant news.

  3. Real-Time Notifications: Provides automatic alerts when new invitations or news are published, allowing users to stay informed without active effort.

  4. Accessibility: Offers information in a structured and formatted way on Telegram, a familiar and accessible platform for most users.

Main Features

1. Interactive Telegram Bot

  • Main command: "quebec round" - retrieves and displays the latest invitation rounds

2. Invitation Web Scraping

  • Uses Puppeteer to download web pages from the Quebec government
  • Extracts detailed information from invitation rounds:
    • Invitation date
    • Volet (program category)
    • Number of invitations issued
    • Minimum required points
    • Specific eligibility criteria
  • Parses dates in French format and converts them to ISO format

3. Automatic Notification System

  • Detects new invitations by comparing with the MongoDB database
  • Sends formatted messages to the Telegram channel only for new invitations
  • Prevents duplicates through database existence verification

4. RSS News Aggregator

  • Fetches news from multiple configurable RSS sources:
    • Quebec News RSS
    • Estrie News RSS
  • Verifies if news has already been sent before publishing
  • Implements 30-second timeout between messages to avoid Telegram spam detection

5. Data Persistence

  • Stores invitations in MongoDB with structured schema:
    • Volet, date, points, number of invitations, criteria
  • Stores RSS news to prevent duplicates:
    • GUID, title, link, publication date

6. Automation via Cron

  • Executable update.sh script via cron jobs
  • Automatically updates:
    • Invitation rounds (npm run updateRounds)
    • RSS news (npm run updateRSSNews)
  • Logs all operations in logs/cron.log with timestamps
  • Location: update.sh:1-18

Technologies Used

Backend and Runtime

  • Node.js (v22.18.0): JavaScript runtime environment
  • TypeScript: JavaScript superset with static typing for greater robustness

Main Libraries

  • node-telegram-bot-api (v0.63.0): API to interact with Telegram
  • Puppeteer (v21.3.8): Browser automation for web scraping
  • Cheerio (v1.0.0-rc.12): jQuery-like HTML parser for Node.js
  • rss-parser (v3.13.0): RSS/Atom feed parser
  • Mongoose (v8.18.0): ODM (Object Data Modeling) for MongoDB

Utilities

  • dotenv (v17.2.2): Environment variable management
  • ts-node (v10.9.2): Direct TypeScript execution without prior compilation

Database

  • MongoDB: NoSQL database to store invitations and news

DevOps

  • Cron: Linux scheduler for periodic automatic execution
  • Bash: Automation scripts

Project Architecture

QuebecRoundBot/
├── src/
│   ├── index.ts                  # Main Telegram bot
│   ├── updateRounds.ts           # Script to update invitations
│   ├── postMessageTelegram.ts    # Message sending module
│   ├── sendAllInvitations.ts     # Mass invitation sending
│   ├── models/
│   │   ├── Invitations.ts        # Invitations schema
│   │   └── rssNews.ts            # RSS news schema
│   ├── rssNewsQuebec/
│   │   └── rssQuebec.ts          # RSS feed processor
│   ├── scrapper/
│   │   ├── scrapper.ts           # Main scraping logic
│   │   ├── getHtml.ts            # HTML download with Puppeteer
│   │   ├── formatter.ts          # Message formatting
│   │   └── helper.ts             # Helper functions
│   └── lib/
│       └── mongo.ts              # MongoDB connection
├── logs/
│   └── cron.log                  # Automatic execution log
├── update.sh                     # Cron update script
├── expanded_page.html            # Downloaded HTML for parsing
└── package.json                  # Project configuration

Workflow

Invitation Updates

  1. Puppeteer downloads the official web page (getHtml.ts)
  2. Saves the HTML in expanded_page.html
  3. Cheerio parses the HTML and extracts structured data (scrapper.ts)
  4. Compares with MongoDB database to detect new invitations
  5. Inserts only new invitations into MongoDB
  6. Sends formatted notification to Telegram channel

RSS News Updates

  1. Parses multiple configured RSS feeds
  2. Iterates over each feed item
  3. Verifies if the GUID already exists in MongoDB
  4. If new, inserts it into MongoDB
  5. Sends formatted news to Telegram channel
  6. Waits 30 seconds before the next message

Last update: October 14, 2025 Version: 1.0.0 Maintainer: @datanarch