Skip to content

ilibel/rails_template

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Template for tiny Rails app with Telegram bot

Here you can find template for tiny Rails application with Telegram bot. The repository itself is generated with this template.

What do you get:

  • telegram-bot.
  • RSpec for tests.
  • Pry for debug.
  • Simple bot controller.

This is just a template bot and it doesn't have much commands to show. For more complex example see telegram_bot_app.

For non-Rails app here is another example.

Setup

Here is a command to generate smalles possible installation of rails. Choose yourself what railties to enable:

rails new app_name \
  --api \
  --skip-action-mailer \
  --skip-active-record \
  --skip-action-cable \
  --skip-test \
  -m https://raw.githubusercontent.com/telegram-bot-rb/rails_template/master/rails_template.rb

After setup:

  • Add this lines to bin/setup:

    puts "\n== Copying sample files =="
    system 'bin/copy_samples'
  • Setup bot config in config/secrets.yml.

  • Uncomment this line in spec/rails_helper.rb:

    Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
  • Optional. Uncomment default configuration in spec/spec_helper.rb.

  • Optional. If you don't use ActiveRecord, you may want to remove config/database.yml line from bin/copy_samples and .gitignore.

Development

bin/rails telegram:bot:poller

Deployment

  • Edit capistrano config.
  • Make sure to add config/secrets.yml (and config/database.yml if exists) to shared folder on servers.
  • Choose one of deployment ways:

Receiving webhooks

  • Setup domain in config/environments/production.yml:

    routes.default_url_options = {host: 'yourdomain.com', protocol: 'https'}
  • Deploy as usual Rails app.

Poller

This is an easier way, though not the 'right' one. You can simply run a rake task, or use something like this:

# bin/telegram_bot

#!/usr/bin/env ruby

begin
  ENV['BOT_POLLER_MODE'] = 'true'
  require_relative '../config/environment'
  Telegram::Bot::UpdatesPoller.start(ENV['BOT'].try!(:to_sym) || :default)
rescue Exception => e
  Rollbar.report_exception(e) if defined?(Rollbar) && !e.is_a?(SystemExit)
  raise
end

And define custom capistrano tasks or something else to run it.

There is sample task to manage such daemon in this repo at lib/capistrano/tasks/telegram_bot.rake.

License

MIT

About

Template for tiny Rails app with Telegram bot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%