Tools for developing bot for Telegram. Best used with Rails, but can be be used in standalone app. Supposed to be used in webhook-mode in production, and poller mode in development, but you can use poller in production if you want.
- Ligthweight client to bot API (with fast and thread-safe httpclient is under the hood.)
- Controller with message parser. Allows to write separate methods for each command.
- Middleware and routes helpers for production env.
- Poller with automatic source-reloader for development env.
- Rake tasks to update webhook urls.
Add this line to your application’s Gemfile:
And then execute:
Or install it yourself as:
telegram section into
From now clients will be accessible with
Telegram.bots[:auction]. Single bot can be accessed with
You can create clients manually with
Telegram::Bot.new(token, username). Username is optional and used only to parse commands with mentions.
Client has all available methods in underscored style (
answer_inline_query instead of
answerInlineQuery). All this methods just post given params to specific URL.
telegram_webhooks helper to add routes. It will create routes for bots at “telegram/#botbot.token” path.
For Rack applications you can also use
Telegram::Bot::Middleware or just call
.dispatch(bot, update) on controller.
Development & Debugging
rake telegram:bot:poller BOT=chat to run poller. It’ll automatically load changes without restart in development env. This task will not if you don’t use
You can run poller manually with
rake telegram:bot:set_webhook to update webhook url for all configured bots. Certificate can be specified with
After checking out the repo, run
bin/setup to install dependencies. Then, run
rake spec to run the tests. You can also run
bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/printercu/telegram-bot.