/coinbot

A decision maker for Telegram

Primary LanguageJavaScript

XO code style

CoinBot is a tiny bot for Telegram, that helps you with random decisions. It works inline and inside the chat.

Usage

Name Command Parameter
Flip a coin /coin -
Roll a dice /dice [Sides of the dice]
Choose from list /list Item1, Item2, ...

Examples

/coinTails

/dice5

/dice 2624

/list Pizza, Sushi, BurgerSushi

Inline:

@coinbot npm, yarnyarn

Development

CoinBot was built with extensibility in mind. That's why it's based on the following principles and technologies:

  • Based on Telegraf – A modern framework for Telegram bots.
  • Commands are modular – They are split into individual files and work inside the chat & inline on the fly.
  • Website updates automatically – It's built with Next.js and reads the same files the bot is using. If you add command to the bot, it will also be on the website.

Run it locally

After you cloned the repository to your computer, you can run it with npm run dev*.

This command will start the bot itself AND the website on port 3000. It's also possible to start only one of them with either npm run dev:bot or npm run dev:web.

* You have to set the environment variable TOKEN to your Telgram Bot Token in order for it to work. You can obtain it from the BotFather.

Run it in production

Same rules apply as above, but for a production environment I suggest to use npm run build and npm start. :bot and :web can also be applied on those two commands.

Writing a new command

To get started, I would suggest to take a look at the files in the commands/ directory. Every command is described with a function that returns an Object.

Example

export default query => ({
  title: 'Demo',
  trigger: 'demo',
  enabled: true,
  message: `This is a demo. Given query: ${query}`,
  description: `Random item`,
  parameter: 'Example',
  thumb: 'list.png'
})

Options

Key Type Required Description
title String YES Title/Name of the command.
trigger String YES The actual command to trigger it. (Without the /)
enabled Boolean YES If false the command will be hidden from inline mode and return an error in chat mode. This is useful if your command only works with a certain query.
message String YES The result of the command. This will be returned when it runs.
description String YES Description for the website, /start and inline mode.
parameter String - Example parameter. Should be in brackets if it's optional. Will be displayed if enabled is set to false
thumb String - Thumbnail for inline mode and website. Image should be placed inside static/thumbs/