Skip to content

A Telegram bot for generating screenshots with highlighted code

Notifications You must be signed in to change notification settings

Imangazaliev/syntax-highligter-bot

Repository files navigation

Syntax Highlighter Bot

A Telegram bot for generating screenshots with highlighted code.

How it works

There are two services - bot.py and screenshot-service.js.

  • bot.py - bot written in AIOgram
  • screenshot-service.js - a service for generating screenshots
  1. Bot requests the screenshot service to generate an image with code.
  2. Screenshot service in turn does:
    1. Highlights a code via highlight.js
    2. Load generated HTML and takes a screenshot via Puppeteer (headless Chrome driver)
    3. Saves generated screenshot to a directory and returns it's path.
  3. Bot sends generated image to a user.

Quick start

  1. Install dependencies:
# Python dependencies
$ poetry install
# JavaScript dependencies
$ npm i
  1. Copy .env.example to .env:
$ cp .env.example .env
  1. Specify a bot token in .env.
  2. Execute services:
# execute bot
$ poetry run bot.py
# execute bot (in another terminal)
$ node screenshot-service.js

If you are running a bot locally don't forget to start Telegram Bot API.

Development

For local development use Telegram Bot API.

Roadmap

  • Rate limiting
  • Use queue to limit the number of pages generated in parallel
  • Containerize

About

A Telegram bot for generating screenshots with highlighted code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published