Skip to content

Repository files navigation

Roll Robot

https://telegram.me/rollrobot https://telegram.me/edloidas

A Telegram bot that can roll the dice like no one before.

About

Roll Robot is a telegram bot used for common "roll the dice" purposes which is working on group chats.

Description

Roll the dice like no one before. Generate random numbers by default RPG pattern (x)d(y)±(n).

Bot recognizes several commands and can be used in inline mode:

@rollrobot [notation] -- inline request, recognizes both notations /roll [notation] -- default roll, recognizes both notations /full [notation] -- same to '/roll', but shows roll for each dice /random -- 'd100' roll

Notation:

  1. Classic
    [count]d[dice]±[modifier]
  2. World of Darkness
    [count]d[dice][!]>[success]f[fail]
  3. Simplfied (classic, space separated)
    [count] [dice] [modifier]
  4. Single-valued
    [dice] where ...
  • count -- number of rolls
  • dice -- dice type
  • modifier -- value, that will be added or subtracted from result
  • ! -- sign, indicating to repeat
  • success -- minimum roll value, that counts as success
  • fail -- maximum roll value, that counts as fail

Examples:

/roll 20 ➜ 'd20'
/roll 2 10 -1 ➜ result of '2d10-1'
/roll 4d8+3 ➜ result of '4d8+3'
/wod 6d10!>6f1 ➜ number of successes for '6d10!>6f1'
/random ➜ 'd100'

Rate the bot, if you like it.

Your ideas on improvement are welcome.

Stack

Cloudflare Workers, TypeScript, Bun, grammY, and roll-parser.

Deployment

The bot runs on Cloudflare Workers using Telegram webhooks.

Cloudflare requires these encrypted Worker secrets:

Key Description
TOKEN Token generated by BotFather.
WEBHOOK_SECRET Random value used to authenticate Telegram webhook requests.

The Worker exposes GET /health and accepts authenticated Telegram POST requests at /webhook. It does not register or modify the Telegram webhook during deployment.

Cloudflare setup

Install the dependencies, authenticate Wrangler, generate a Telegram-compatible secret, and store both secrets in Cloudflare:

bun install
bunx wrangler login
openssl rand -hex 32
bunx wrangler secret put TOKEN
bunx wrangler secret put WEBHOOK_SECRET

Create an ignored .env file in the repository root. Bun loads it automatically for telegram:configure, and Wrangler uses it for local Worker development:

TOKEN=0123456789:replace-with-telegram-bot-token
WEBHOOK_SECRET=replace-with-a-random-webhook-secret
WEBHOOK_URL=https://rollrobot.<account-subdomain>.workers.dev/webhook

Keep .env local. It does not upload secrets to Cloudflare; the wrangler secret put commands above are still required for the deployed Worker.

Run the Worker locally, then deploy it when /health and webhook authentication have been verified:

bun run worker:dev
bun run worker:deploy

After deployment, update WEBHOOK_URL in .env with the actual Worker URL and configure Telegram:

bun run telegram:configure
curl "https://api.telegram.org/bot<telegram-bot-token>/getWebhookInfo"

The setup command registers message, inline_query, and chosen_inline_result updates. It preserves queued updates unless DROP_PENDING_UPDATES=true is explicitly set. Test private, group, supergroup, and inline requests after configuration, then monitor the Worker logs for errors.

About

A Telegram bot that can roll the dice like no one before.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages