Skip to content

meinside/telegram-janet-repl-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

telegram-janet-repl-bot

A Telegram Bot which works as a Janet REPL.

captured_20240115_1545

It will evaluate your messages and send the results back as replies.

How to configure

Build,

$ git clone https://github.com/meinside/telegram-janet-repl-bot.git
$ cd telegram-janet-repl-bot
$ jpm deps
$ jpm build

then create a config file:

$ cp config.json.sample config.json

and edit it:

{
  "token": "your:telegram-bot-token-here",
  "interval_seconds": 1,
  "allowed_telegram_usernames": ["allowed_telegram_username1", "allowed_telegram_username2"],
  "is_verbose": false
}

Now run with:

$ build/repl-bot config.json

How to run as a service

Linux/Systemd

Create a systemd service file:

$ vi /etc/systemd/system/telegram-janet-repl-bot.service

and fill it with:

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

[Service]
Type=simple
WorkingDirectory=/dir/to/telegram-janet-repl-bot
ExecStart=/path/to/telegram-janet-repl-bot/build/repl-bot /path/to/telegram-janet-repl-bot/config.json
Restart=always
RestartSec=5
DynamicUser=yes
ReadOnlyPaths=/
MemoryLimit=100M
NoExecPaths=/bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin

[Install]
WantedBy=multi-user.target

then make it autostart on reboots:

$ sudo systemctl enable telegram-janet-repl-bot.service

and start/stop it:

$ sudo systemctl start telegram-janet-repl-bot
$ sudo systemctl restart telegram-janet-repl-bot
$ sudo systemctl stop telegram-janet-repl-bot

Note

  • Functions/macros that print 'something' to stdout/stderr may return their ordinary results with the 'something' appended to them.
  • doc macro doesn't work as expected. Use doc-of function instead.

Warning

This bot accepts messages only from allowed telegram usernames,

but is not free from bad messages, (eg. intentional infinite loops, malicious shell commands, etc.)

so be careful not to blow up your servers :-)