What it is
Rubydium is a framework for building Telegram bots. Built on top of telegram-bot-ruby API wrapper, it aims to provide tools for building your bots with minimum boilerplate.
It's far from being done, but all the code in the examples directory is functional and mostly covered with specs.
Installation
CLI tool for creating and setting up new projects is planned. For now:
- Create your project:
mkdir example_bot && cd example_bot
- Install the gem:
- Add this gem to the Gemfile:
bundle init && echo 'gem "rubydium"' >> Gemfile
bundle install
- Or install system-wide:
gem install rubydium
- Create your main file:
touch example_bot.rb
- See the examples directory for bot examples.
Configuring the bot
There's two main ways to write your config. With a block:
ExampleBot.configure do |config|
config.token = "1234567890:long_alphanumeric_string_goes_here"
config.bot_username = "ends_with_bot"
config.owner_username = "thats_you"
config.privileged_usernames = %w[
your_friend your_chat_moderator
]
end
Or with a hash:
ExampleBot.config = {
token: "1234567890:long_alphanumeric_string_goes_here",
bot_username: "ends_with_bot",
owner_username: "thats_you",
privileged_usernames: %w[
your_friend your_chat_moderator
]
}
The hash variant also means you can pass in any valid Ruby hash, regardless of where it comes from. For example, you can set the same values, if you parse
example_bot/config.json
:
{
"token": "1234567890:long_alphanumeric_string_goes_here",
"bot_username": "ends_with_bot",
"owner_username": "thats_you",
"privileged_usernames": [
"your_friend",
"your_chat_moderator"
]
}
example_bot/example_bot.rb
:
require "json"
ExampleBot.config = JSON.load_file("./config.json")
example_bot/config.yaml
token: 1234567890:long_alphanumeric_string_goes_here
bot_username: ends_with_bot
owner_username: thats_you
privileged_usernames:
- your_friend
- your_chat_moderator
example_bot/example_bot.rb
:
require "yaml"
ExampleBot.config = YAML.load_file("./config.yaml")