README.md in slack-ruby-bot-server-0.3.0 vs README.md in slack-ruby-bot-server-0.3.1
- old
+ new
@@ -11,11 +11,11 @@
A library that contains a [Grape](http://github.com/ruby-grape/grape) API serving a [Slack Ruby Bot](https://github.com/dblock/slack-ruby-bot) to multiple teams. This gem combines a web server, a RESTful API and multiple instances of [slack-ruby-bot](https://github.com/dblock/slack-ruby-bot). It integrates with the [Slack Platform API](https://medium.com/slack-developer-blog/launch-platform-114754258b91#.od3y71dyo). Your customers can use a Slack button to install the bot.
### Stable Release
-You're reading the documentation for the **stable** release of slack-ruby-bot-server, 0.3.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
+You're reading the documentation for the **stable** release of slack-ruby-bot-server 0.3.1. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
### Try Me
A demo version of the [sample app](sample_app) is running on Heroku at [slack-ruby-bot-server.herokuapp.com](https://slack-ruby-bot-server.herokuapp.com). Use the _Add to Slack_ button. The bot will join your team as _@slackbotserver_.
@@ -39,12 +39,38 @@
If you deploy to Heroku set `SLACK_CLIENT_ID` and `SLACK_CLIENT_SECRET` via `heroku config:add SLACK_CLIENT_ID=... SLACK_CLIENT_SECRET=...`.
### API
-This library implements a service manager, [SlackRubyBotServer::Service](lib/slack-ruby-bot-server/service.rb) that creates multiple instances of a bot server class, [SlackRubyBotServer::Server](lib/slack-ruby-bot-server/server.rb), one per team.
+This library implements an app, [SlackRubyBotServer::App](lib/slack-ruby-bot-server/app.rb), a service manager, [SlackRubyBotServer::Service](lib/slack-ruby-bot-server/service.rb) that creates multiple instances of a bot server class, [SlackRubyBotServer::Server](lib/slack-ruby-bot-server/server.rb), one per team.
+#### App
+
+The app instance checks for a working MongoDB connection, ensures database indexes, performs database migrations, sets up bot aliases and log levels. You can introduce custom behavior into the app lifecycle by subclassing `SlackRubyBotServer::App` and creating an instance of the child class in `config.ru`.
+
+```ruby
+class MyApp < SlackRubyBotServer::App
+ def prepare!
+ super
+ deactivate_sleepy_teams!
+ end
+
+ private
+
+ def deactivate_sleepy_teams!
+ Team.active.each do |team|
+ next unless team.sleepy?
+ team.deactivate!
+ end
+ end
+end
+```
+
+```ruby
+MyApp.instance.prepare!
+```
+
#### Service Manager
You can introduce custom behavior into the service lifecycle via callbacks. This can be useful when new team has been registered via the API or a team has been deactivated from Slack.
```ruby
@@ -84,21 +110,21 @@
#### Server Class
You can override the server class to handle additional events, and configure the service to use it.
```ruby
-class MyServerClass < SlackRubyBotServer::Server
+class MyServer < SlackRubyBotServer::Server
on :hello do |client, data|
# connected to Slack
end
on :channel_joined do |client, data|
# the bot joined a channel in data.channel['id']
end
end
SlackRubyBotServer.configure do |config|
- config.server_class = MyServerClass
+ config.server_class = MyServer
end
```
### Examples Using Slack Ruby Bot Server