telegram-d2-bot

command module
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

telegram-d2-bot

A telegram bot which answers with rendered .svg files in .png format.

Using d2lang/d2 for generating diagrams from messages, and rendering them to .png with d2's built-in pure-Go renderer (no headless browser).

Screenshot 2022-12-19 at 14 31 53

Configuration

$ cp config.json.sample config.json

and edit:

{
  "allowed_ids": ["telegram_username_1", "telegram_username_2"],
  "monitor_interval": 5,
  "theme_id": 0,
  "sketch": false,
  "is_verbose": false,

  "bot_token": "xxxxxxxxyyyyyyyy-1234567"
}
  • bot_token can be obtained from bot father
  • allowed_ids are ids of allowed telegram users who can get responses from this bot
  • monitor_interval is the polling interval (in seconds) from telegram API
  • theme_id can be retrieved from these files (= 0 for default)
  • sketch is whether to render results in sketched style
  • is_verbose is whether to print verbose messages
Using Infisical

You can use Infisical for retrieving your bot token and api key:

{
  "allowed_ids": ["telegram_username_1", "telegram_username_2"],
  "monitor_interval": 5,
  "theme_id": 0,
  "sketch": false,
  "is_verbose": false,

  "infisical": {
    "client_id": "012345-abcdefg-987654321",
    "client_secret": "aAbBcCdDeEfFgG0123456789xyzwXYZW",

    "project_id": "012345abcdefg",
    "environment": "dev",
    "secret_type": "shared",

    "bot_token_key_path": "/path/to/your/KEY_TO_BOT_TOKEN",
  }
}

Other Dependencies

None. Rendering is done in-process by d2's native renderer.

For labels in scripts which d2's bundled fonts don't cover (Hangul, CJK, …), install a system font such as Noto Sans CJK; d2's font fallback picks it up from the host.

Build and Run

$ go build
$ ./telegram-d2-bot config.json

Run as a service

systemd

Create a file named /etc/systemd/system/telegram-d2-bot.service:

[Unit]
Description=Telegram D2 Bot
After=syslog.target
After=network.target

[Service]
Type=simple
User=ubuntu
Group=ubuntu
WorkingDirectory=/dir/to/telegram-d2-bot
ExecStart=/dir/to/telegram-d2-bot/telegram-d2-bot [CONFIG_FILEPATH]
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

and make it run automatically on booting:

$ sudo systemctl enable telegram-d2-bot.service
$ sudo systemctl start telegram-d2-bot.service

Todos

  • Add more configurable options.
  • Support uploading .d2 files.
  • Respond with .png files.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址