README.md in telegram-bot-0.12.4 vs README.md in telegram-bot-0.13.0
- old
+ new
@@ -128,10 +128,13 @@
can represent actions as separate methods keeping source much more readable and supportable.
New instance of controller is instantiated for each update.
This way every update is processed in isolation from others.
+Bot controllers like usual rails controllers provides features like callbacks,
+`rescue_from` and instrumentation.
+
```ruby
class Telegram::WebhookController < Telegram::Bot::UpdatesController
# use callbacks like in any other controllers
around_action :with_locale
@@ -323,33 +326,41 @@
```ruby
# This one handles `set_value:%{something}`.
def set_value_callback_query(new_value = nil, *)
save_this(value)
- answer_callback_query('Saved!)
+ answer_callback_query('Saved!')
end
# And this one is for `make_cool:%{something}`
def make_cool_callback_query(thing = nil, *)
do_it(thing)
- answer_callback_query("#{thing} is cool now! Like a callback query context.")
+ answer_callback_query("#{thing} is cool now! Like a callback query context.")
end
```
### Routes in Rails app
-There is `telegram_webhooks` helper for rails app to define routes for webhooks.
+There is `telegram_webhook` helper for rails app to define routes for webhooks.
It defines routes at `telegram/#{bot.token}` and connects bots with controller.
-For more options see [examples in wiki](https://github.com/telegram-bot-rb/telegram-bot/wiki/Routes-helpers-in-details).
```ruby
-# Create routes for all Telegram.bots using single controller:
-telegram_webhooks TelegramController
+# Most off apps would require
+telegram_webhook TelegramController
+# which is same as
+telegram_webhook TelegramController, :default
# Use different controllers for each bot:
-telegram_webhooks chat: TelegramChatController,
- auction: TelegramAuctionController
+telegram_webhook TelegramChatController, :chat
+telegram_webhook TelegramAuctionController, :auction
+
+# Defined route is named and its name depends on `Telegram.bots`.
+# For single bot it will use 'telegram_webhook',
+# for multiple bots it uses bot's key in the `Telegram.bots` as prefix
+# (eg. `chat_telegram_webhook`).
+# You can override this with `as` option:
+telegram_webhook TelegramController, as: :custom_telegram_webhook
```
#### Processesing updates
To process update with controller call `.dispatch(bot, update)` on it.
@@ -358,11 +369,11 @@
- Use webhooks with routes helper (described above).
- Use `Telegram::Bot::Middleware` with rack ([example in wiki](https://github.com/telegram-bot-rb/telegram-bot/wiki/Not-rails-application)).
- Use poller (described in the next section).
To run action without update (ex., send notifications from jobs),
-you can call `#process` directly. In this case controller can be initialized
+you can call `#process` directly. In this case controller can be initialized
with `:from` and/or `:chat` options instead of `update` object:
```ruby
controller = ControllerClass.new(bot, from: telegram_user, chat: telegram_chat)
controller.process(:welcome, *args)
@@ -372,11 +383,11 @@
Use `rake telegram:bot:poller` to run poller in rails app. It automatically loads
changes without restart in development env.
Optionally pass bot id in `BOT` envvar (`BOT=chat`) to specify bot to run poller for.
-This task requires `telegram_webhooks` helper to be used as it connects bots with controller.
+This task requires `telegram_webhook` helper to be used as it connects bots with controller.
To run poller in other cases use:
```ruby
Telegram::Bot::UpdatesPoller.start(bot, controller_class)
```
@@ -521,10 +532,10 @@
- Client will not return API response.
- Sending files is not available in async mode, because they can not be serialized.
## Development
-After checking out the repo, run `bin/setup` to install dependencies.
+After checking out the repo, run `bin/setup` to install dependencies and git hooks.
Then, run `appraisal 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`,