To integrate your bot with Slack, you must first create a new Classic Slack App and a legacy bot.
Once created, go to the app's Basic Info tab and grab the Client ID and Client Secret. You'll need these in order complete an OAuth code grant flow as described at slack-ruby-bot-server. A successful flow will result in the receipt of an API token for the specific team that is granting access.
Alternatively, you can still generate a legacy API token for your app and use it for some interactions.
If you have a legacy API token, and would like to migrate to slack-ruby-bot-server, a brief migration guide is provided.
Set the SLACK_API_TOKEN environment variable using the token received above.
heroku config:add SLACK_API_TOKEN=...
Optional names for this bot.
heroku config:add SLACK_RUBY_BOT_ALIASES=":pong: table-tennis ping-pong"
Heroku free tier applications will idle. Either pay 7$ a month for the hobby dyno or use UptimeRobot or similar to prevent your instance from sleeping or pay for a production dyno.
Deploying on your self-hosted server is fairly easy, it's pretty much following the tutorial, but there are some configuration details to pay attention to.
- Change or add the
gem 'puma'
entry in yourGemfile
togem 'passenger'
andbundle
it- OPTIONAL: To use passenger for developing too, change the
Procfile
toweb: bundle exec passenger start
, to configure the local passenger you could provide an optionalPassenger.json
file (configuration options)
- OPTIONAL: To use passenger for developing too, change the
- If you want to keep your logs etc. in the correct folders, you could add empty
public/
,tmp/
andlog
directories. Passenger e.g. will automatically use them for local log files. - Make sure, the right ruby version is installed and your passenger is ready to go.
- Clone the repository on your server (You could create a separate user for this) and install the dependencies, by running
bundle install
(More information) - Edit the web-server configuration according to the examples below
PassengerMaxPreloaderIdleTime 0
orpassenger_max_preloader_idle_time 0;
makes sure to not automatically shut down the process after 5 minutesPassengerPreStart http://url:port
orpassenger_pre_start http://url:port
will startup the application instantly, without the first HTTP GET-request needed for passenger- To get the
/path/to/ruby
runpassenger-config about ruby-command
and copy the displayed path - Check the config (
nginx -t
) and restart the server withservice nginx restart
- Execute
passenger-status --verbose
to check if your app is working correctly - Optional: restart the passenger app via
passenger-config restart-app /var/www/bot
server {
listen 80;
server_name example.com;
root /var/www/bot/public;
passenger_enabled on;
passenger_ruby /path/to/ruby
passenger_max_preloader_idle_time 0;
passenger_app_type rack;
}
passenger_pre_start http://example.com:80/;
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/bot/public
PassengerRuby /path/to/ruby
PassengerMaxPreloaderIdleTime 0
<Directory /var/www/bot/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
PassengerPreStart http://example.com:80/