Coder Social home page Coder Social logo

ruby-telegram-bot-starter-kit's Introduction

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

Defining responses

Use the on method in message_responder.rb like in the example below:

def respond
  on /^\/start/ do
    answer_with_greeting_message
  end

  on /^\/command (.+)/ do |arg| #supports up to two arguments but it is easily extendable
    # do your stuff
  end
end

Running the bot

For the first you need to install gems required to start a bot:

bundle install

Then 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

ruby-telegram-bot-starter-kit's People

Contributors

maksimabramchuk avatar aaronsama avatar sergey-alekseev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.