Skip to content

Deployment

Max Melentiev edited this page Nov 22, 2022 · 3 revisions

Here are described two basic ways to deploy your bot.

Webhooks

Pros:

  • Scalable.
  • No need to manage separate process for bot.

Cons:

  • Requires HTTPS on server. P.S. Telegram supports self-signed certificates.

Setup for rails app

  • Setup domain in config/environments/production.rb:
    routes.default_url_options = {host: 'yourdomain.com', protocol: 'https'} # https is necessary!
  • Deploy as usual Rails app.
  • Run rake telegram:bot:set_webhook RAILS_ENV=production to update webhook url for all configured bots. Self-signed certificate can be provided with CERT=path/to/cert.pem.
  • Re-run this rake task each time domain, bot token or self-signed sertificate changes.

Not rails application

  • Deploy app as usual.
  • Run bot.set_webhook(url: your_url [, cert: File.open('self/signed/cert')]) for each bot.
  • Re-run previous step each time webhook url or self-signed sertificate changes.

Poller

Pros:

  • No need to setup HTTPS.

Cons:

  • Not scalable: only one process can poll for updates at the moment.
  • Requires separate process for bot (harder to deploy).

Rails app

  • Create ruby file that runs poller (in some cases rake task will be enough).
  • Use any process manager (upstart, init.d, god, daemons gem) to start/stop/restart poller.
  • Deploy as usual.

See example using daemons gem.

Not rails application

Same as rails app, just set controller class for each poller explicitly.