Skip to content

Not rails application

printercu edited this page Nov 18, 2017 · 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. Better use some router and mount on some secret endpoint.
run Telegram::Bot::Middleware.new(bot, WebhooksController)

Note about considering Rails

Here are some advantages of Rails:

  • First of all is hot 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 to fat by default. However this is not critical: middleware stack can be simply cleared from unused items, and unused railties can be simply removed.

I you still think that using Rails is an overkill for simple bot app, for the last resort you can just use custom config.ru with little stack for production.

Clone this wiki locally