Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MaksimAbramchuk/ruby-telegram-bot-starter-kit
:airplane: Ruby Telegram boilerplate for creating awesome bots. Check out best tools from the world of bots - https://github.com/BotCube/awesome-bots
https://github.com/MaksimAbramchuk/ruby-telegram-bot-starter-kit
bot ruby telegram
Last synced: 12 days ago
JSON representation
:airplane: Ruby Telegram boilerplate for creating awesome bots. Check out best tools from the world of bots - https://github.com/BotCube/awesome-bots
- Host: GitHub
- URL: https://github.com/MaksimAbramchuk/ruby-telegram-bot-starter-kit
- Owner: MaksimAbramchuk
- Created: 2015-12-21T11:32:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-01-19T13:32:49.000Z (almost 2 years ago)
- Last Synced: 2024-08-10T20:03:14.476Z (3 months ago)
- Topics: bot, ruby, telegram
- Language: Ruby
- Homepage: https://github.com/BotCube/awesome-bots
- Size: 20.5 KB
- Stars: 233
- Watchers: 10
- Forks: 66
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-telegram-bots - ruby-telegram-bot-starter-kit - Ruby Telegram boilerplate for creating awesome bots (Ruby / PHP)
README
# Ruby Telegram Bot boilerplate
![Ruby and Telegram](https://hsto.org/files/914/1c2/d17/9141c2d17d074b8d8758a955f7fd575a.png)## UPD (20.06.2016)
I've created an awesome list of resources related to bots (from tutorials and SDKs to the events and people). Be sure to [check it out](https://github.com/BotCube/awesome-bots)![Awesome bots list](https://github.com/BotCube/awesome-bots)
If you want to use Webhooks API instead of long-polling, be able to save state and create more scalable and powerful bot read the article below.
[Full guide on creating statefull Telegram bot](https://botcube.co/blog/2017/02/04/full-guide-on-creating-telegram-bot-with-rails.html)
## 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](https://core.telegram.org/bots#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:
```ruby
def respond
on /^\/start/ do
answer_with_greeting_message
endon /^\/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:```sh
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:
```sh
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](https://core.telegram.org/bots#botfather) to the `secrets.yml` file and your database credentials to `database.yml`.
After this you need to create and migrate your database:
```sh
rake db:create db:migrate
```Great! Now you can easily start your bot just by running this command:
```sh
bin/bot
```## Directory layout
### Source
```sh
└── 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](https://github.com/atipugin/telegram-bot-ruby).
## 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