/ruby-telegram-bot-boilerplate

:airplane: Ruby Telegram boilerplate for creating awesome bots

Primary LanguageRuby

Ruby Telegram Bot boilerplate

Ruby and Telegram

Features

  • Ability to save some data to a local database (Postgres by default)
  • Automatic logging of received and sent message
  • Easy internationalization using i18n gem
  • Already created class for creating custom keyboards
  • Database logging
  • Separate classes for all the functional, so it's very easy to customize something

Usage

Running the bot

For the first you need to create secrets.yml where your bot unique token will be stored and database.yml where database credentials will be stored. I've already created samples for you, so you can easily do:

cp config/database.yml.sample config/database.yml
cp config/secrets.yml.sample config/secrets.yml

Then you need to fill your Telegram bot unique token to the secrets.yml file and your database credentials to database.yml.

After this you need to create and migrate your database:

rake db:create db:migrate

Great! Now you can easily start your bot just by running this command:

bin/bot

Directory layout

Source

└── ruby-telegram-bot-boilerplate
    ├── bin                              # executables folder
    │   └── bot                          # main executable file
    ├── config                           # folder with configs
    │   ├── database.yml.sample          # sample database configuration
    │   ├── secrets.yml.sample           # sample credentials file
    │   └── locales.yml                  # file with i18n locales
    ├── db                               # database related stuff
    │   ├── migrate                      # migrations
    │   └── 001_create_users.rb          # migration for creating table 'users'
    ├── lib                              # helper libs folder
    │   ├── app_configurator.rb          # class for application configuration
    │   ├── database_connector.rb        # class for connecting to database
    │   ├── message_responder.rb         # main class for responding to message
    │   ├── message_sender.rb            # simple class just for message sending
    │   └── reply_markup_formatter.rb    # class for creating custom keyboards
    ├── models                           # database models folder
    │   └── user.rb                      # active record User model
    ├── Gemfile                          # Gemfile
    ├── Gemfile.lock                     # Gemfile.lock
    ├── README.md                        # Readme file
    └── Rakefile                         # Rakefile with tasks for database management

Some more specific info you can also find here.

Contributing

If you have some proposals how to improve this boilerplate feel free to open issues and send pull requests!

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request