Skip to content

Not rails application

printercu edited this page Jan 9, 2019 · 4 revisions
require 'telegram/bot'

class WebhooksController < Telegram::Bot::UpdatesController
  def start!(*)
    respond_with :message, text: 'Hello!'
  end
end

TOKEN = 'secret:token'
bot = Telegram::Bot::Client.new(TOKEN)

# poller-mode
require 'logger'
logger = Logger.new(STDOUT)
poller = Telegram::Bot::UpdatesPoller.new(bot, WebhooksController, logger: logger)
poller.start

# OR
# rack-app for webhook mode. See https://rack.github.io/ for details.
# Make sure to run `set_webhook` passing valid url.
map "/#{TOKEN}" do
  run Telegram::Bot::Middleware.new(bot, WebhooksController)
end

Considering Rails

Here are some advantages of Rails:

  • First of all is hot code reload.
  • Bootstrap system with configuration files and initializers.
  • Autoloading classes.
  • A lot of tools and integrations.
  • And much more.

While the only disadvantage I see is that it may be too "heavy" by default. However this is not critical: middleware stack can be simply cleared from unused items, and unused railties can be simply removed. Poller-mode is not affected by rails at all (except insignificantly longer start time).

If you still think that using Rails is an overkill for simple bot app, for the last resort you can use custom config.ru with little stack for production while using rails in development.

Clone this wiki locally