### Start Application with Foreman (Shell) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Executes the foreman start command to boot the application, typically defined in a Procfile. The output shows the process starting and the web server listening on a specific port. ```shell $ foreman start 07:44:47 web.1 | started with pid 59258 07:44:50 web.1 | * Listening on tcp://0.0.0.0:5000 ``` -------------------------------- ### Handle Service Callbacks (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Demonstrates how to register callbacks on the `SlackRubyBotServer::Service` instance. The example shows handling the `:started` event, which is triggered when a new team is registered, providing access to the `team` object and its `server`. ```Ruby instance = SlackRubyBotServer::Service.instance instance.on :started do |team, error| # a new team has been registered # team.server is available end ``` -------------------------------- ### Running Tests and Installing Dependencies Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/RELEASING.md Installs required Ruby gems using Bundler and executes the default Rake task, typically running the test suite, to verify the project's state before a release. ```shell bundle install rake ``` -------------------------------- ### Instantiate Custom App Class (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Demonstrates how to get an instance of a custom subclass of `SlackRubyBotServer::App` and invoke its `prepare!` method. This is required after subclassing the app class. ```Ruby MyApp.instance.prepare! ``` -------------------------------- ### Subclass SlackRubyBotServer::Server (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Illustrates how to subclass `SlackRubyBotServer::Server` to handle additional Slack events. The example shows handling the `:hello` event (connection established) and `:channel_joined` event. ```Ruby class MyServerClass < 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 ``` -------------------------------- ### Configuring PostgreSQL Database Connection (YAML) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Example YAML configuration for PostgreSQL database connections in development, test, and production environments. This file defines connection parameters like adapter, pool size, timeout, encoding, and database names. ```YAML default: &default adapter: postgresql pool: 10 timeout: 5000 encoding: unicode development: <<: *default database: bot_development test: <<: *default database: bot_test production: <<: *default database: bot ``` -------------------------------- ### Subclass SlackRubyBotServer::App (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Shows how to subclass `SlackRubyBotServer::App` to add custom initialization logic. The example overrides the `prepare!` method to call the parent method and then execute a custom `deactivate_sleepy_teams!` method. ```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 ``` -------------------------------- ### Adding ActiveRecord/PostgreSQL Dependencies to Gemfile (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Include these gems in your Gemfile to use ActiveRecord with PostgreSQL for storing teams with slack-ruby-bot-server. This setup requires `otr-activerecord` and `pagy_cursor` for pagination. ```Ruby gem 'pg' gem 'activerecord', require: 'active_record' gem 'slack-ruby-bot-server' gem 'otr-activerecord' gem 'pagy_cursor' ``` -------------------------------- ### Registering SlackRubyBotServer Lifecycle Callbacks (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Demonstrates how to register custom callback functions for various lifecycle events of the SlackRubyBotServer service instance, such as starting, stopping, creating, deactivating, and handling errors for teams. ```ruby instance = SlackRubyBotServer::Service.instance instance.on :started, :stopped do |team| # team has been started or stopped end instance.on :created do |team, error, options| # a new team has been registered end instance.on :deactivated do |team, error, options| # an existing team has been deactivated in Slack end instance.on :error do |team, error, options| # an error has occurred end ``` -------------------------------- ### Creating Add to Slack Button with State Parameter (HTML) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Provides an example of an HTML anchor tag for the 'Add to Slack' button, including dynamic Ruby code (`<%= ... %>`) to generate the OAuth authorization URL, scope, client ID, and an optional 'state' parameter for security. ```html ... ``` -------------------------------- ### Instantiate and Prepare Custom App (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Creates a singleton instance of the custom MyApp class and calls its prepare! method. This is typically done in the application's configuration or boot process (config.ru) to initialize the custom app logic. ```ruby MyApp.instance.prepare! ``` -------------------------------- ### Reverting README to Indicate Next Version Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/RELEASING.md Shows how to revert the README.md file content to indicate that the documentation is for the upcoming, unreleased version, linking to the last stable release. ```markdown ## Stable Release You're reading the documentation for the **next** release of slack-ruby-bot-server. Please see the documentation for the [last stable release, v2.0.1](https://github.com/slack-ruby/slack-ruby-bot-server/blob/v2.0.1/README.md) unless you're integrating with HEAD. See [UPGRADING](UPGRADING.md) when upgrading from an older version. See [MIGRATING](MIGRATING.md) for help with migrating Legacy Slack Apps to Granular Scopes. ``` -------------------------------- ### Committing Next Version Preparation Files Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/RELEASING.md Stages the modified README.md, CHANGELOG.md, and version file, commits them with a message indicating preparation for the next iteration, and pushes the changes. ```shell git add README.md CHANGELOG.md lib/slack-ruby-bot-server/version.rb git commit -m "Preparing for next development iteration, 2.0.2." git push origin master ``` -------------------------------- ### Committing Release Preparation Files Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/RELEASING.md Stages the modified README.md and CHANGELOG.md files, commits them with a descriptive message, and pushes the changes to the remote master branch. ```shell git add README.md CHANGELOG.md git commit -m "Preparing for release, 2.0.1." git push origin master ``` -------------------------------- ### Executing the Gem Release Task Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/RELEASING.md Runs the Rake task configured to build the gem package, create a Git tag, push commits and tags, and publish the gem to RubyGems.org. ```shell rake release ``` -------------------------------- ### Modifying README for Stable Release Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/RELEASING.md Illustrates how to update the README.md file to inform users that the documentation corresponds to a specific stable release version. ```markdown ## Stable Release You're reading the documentation for the **stable** release of slack-ruby-bot-server, 2.0.1. See [UPGRADING](UPGRADING.md) when upgrading from an older version. ``` -------------------------------- ### Adding Next Version Entry to CHANGELOG Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/RELEASING.md Provides the template for adding a new entry in the CHANGELOG.md file to track changes for the subsequent development version. ```markdown ### 2.0.2 (Next) * Your contribution here. ``` -------------------------------- ### Handle 'ping' App Mention (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/MIGRATING.md Defines a Ruby class that inherits from SlackRubyBotServer::Events::AppMentions::Mention to specifically respond to 'ping' mentions by posting 'pong' back to the channel. ```Ruby class Ping < SlackRubyBotServer::Events::AppMentions::Mention mention 'ping' def self.call(data) client = Slack::Web::Client.new(token: data.team.token) client.chat_postMessage(channel: data.channel, text: 'pong') end end ``` -------------------------------- ### Establishing ActiveRecord Connection from YAML Config (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Ruby code to read a PostgreSQL database configuration from a YAML file, parse it using ERB and YAML, and establish an ActiveRecord database connection based on the current RACK_ENV. This is typically done in the application's startup code. ```Ruby yml = ERB.new(File.read(File.expand_path('config/postgresql.yml', __dir__))).result db_config = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1') ::YAML.safe_load(yml, aliases: true)[ENV['RACK_ENV']] else ::YAML.safe_load(yml, [], [], true)[ENV['RACK_LOAD']] end ActiveRecord::Base.establish_connection(db_config) ``` -------------------------------- ### Configure SlackRubyBotServer for App Mentions (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/MIGRATING.md Configures the slack-ruby-bot-server gem to use OAuth v2 and specifies the necessary scopes for handling app mentions and sending messages. ```Ruby SlackRubyBotServer.configure do |config| config.oauth_version = :v2 config.oauth_scope = ['app_mentions:read', 'im:history', 'chat:write'] end ``` -------------------------------- ### Add ActiveRecord Dependency (Gemfile) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Adds the necessary gems to a Gemfile for using `slack-ruby-bot-server` with ActiveRecord, specifically with PostgreSQL. Requires the database driver (`pg`), `activerecord`, and `slack-ruby-bot-server` gems in that order. ```Gemfile gem 'pg' gem 'activerecord', require: 'active_record' gem 'slack-ruby-bot-server' ``` -------------------------------- ### Configuring SlackRubyBotServer Service Timers (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Demonstrates how to set up periodic tasks using the SlackRubyBotServer service instance's timer methods (`every`, `once_and_every`), allowing execution of code at specified intervals (e.g., hourly, minute, second, or custom seconds). ```ruby instance = SlackRubyBotServer::Service.instance instance.every :hour do Team.each do |team| begin # do something with every team once an hour rescue StandardError end end end instance.once_and_every :minute do # called once on start, then every minute end instance.every :minute do # called every minute end instance.every :second do # called every second end instance.every 30 do # called every 30 seconds end ``` -------------------------------- ### Expose Local Port with ngrok (Shell) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Uses the ngrok command-line tool to create a public tunnel to the local HTTP server running on port 5000, providing a public HTTPS URL for external access, necessary for receiving webhooks from Slack on localhost. ```shell $ ngrok http 5000 Forwarding https://ddfd97f80615.ngrok.io -> http://localhost:5000 ``` -------------------------------- ### Configure SlackRubyBotServer for Generic Messages (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/MIGRATING.md Configures the slack-ruby-bot-server gem to use OAuth v2 and specifies a broader set of scopes required for handling various message types in different channel types. ```Ruby SlackRubyBotServer.configure do |config| config.oauth_version = :v2 config.oauth_scope = ['chat:write', 'im:history', 'mpim:history', 'channels:history', 'groups:history'] end ``` -------------------------------- ### Replace cursor_pagination Gem with pagy_cursor (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Add the `pagy_cursor` gem to your Gemfile when upgrading to version 2.0.0 or later if you are using ActiveRecord for pagination. This replaces the abandoned `cursor_pagination` gem. ```Ruby gem 'pagy_cursor' ``` -------------------------------- ### Subclass SlackRubyBotServer::App for Custom Behavior (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Defines a custom application class MyApp that inherits from SlackRubyBotServer::App. It overrides the prepare! method to include additional logic, such as deactivating inactive teams, demonstrating how to extend the default app lifecycle. ```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 ``` -------------------------------- ### Configuring Custom HTML View Paths in Slack Ruby Bot Server Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md This snippet demonstrates how to add custom directories to the view paths used by Slack Ruby Bot Server. This allows applications to override or extend the default HTML templates provided by the library, such as those for the 'Add to Slack' button workflow. ```Ruby SlackRubyBotServer.configure do |config| config.view_paths << File.expand_path(File.join(__dir__, 'public')) end ``` -------------------------------- ### Add Mongoid Dependency (Gemfile) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Adds the necessary gems to a Gemfile for using `slack-ruby-bot-server` with Mongoid. Requires both `mongoid` and `slack-ruby-bot-server` gems. ```Gemfile gem 'mongoid' gem 'slack-ruby-bot-server' ``` -------------------------------- ### Updating CHANGELOG Release Date Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/RELEASING.md Shows the format for updating the date associated with the release version entry in the CHANGELOG.md file. ```markdown ### 2.0.1 (2023/02/20) ``` -------------------------------- ### Configure Custom Server Class (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Configures `slack-ruby-bot-server` to use a custom server class instead of the default one. This allows the service to use the event handlers defined in the custom class. ```Ruby SlackRubyBotServer.configure do |config| config.server_class = MyServerClass end ``` -------------------------------- ### Adding MongoDB Dependencies to Gemfile (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Add these gems to your Gemfile to use MongoDB with Mongoid as the ODM for storing teams with slack-ruby-bot-server. This includes gems for pagination and scrolling. ```Ruby gem 'mongoid' gem 'kaminari-mongoid' gem 'mongoid-scroll' gem 'slack-ruby-bot-server' ``` -------------------------------- ### Handle Generic Slack Message Events (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/MIGRATING.md Configures the SlackRubyBotServer::Events module to listen for generic 'message' events, including logic to filter out specific subtypes or messages sent by the bot itself before processing. ```Ruby SlackRubyBotServer::Events.configure do |config| config.on :event, 'event_callback', 'message' do |event| # SlackShellbot::Commands::Base.logger.info event next true if event['event']['subtype'] # updates, etc. next true if event['authorizations'][0]['user_id'] == event['event']['user'] # self team = Team.where(team_id: event['team_id']).first next true unless team data = Slack::Messages::Message.new(event['event']) # handles event data here true end end ``` -------------------------------- ### Configure SlackRubyBotServer OAuth and Scopes (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Configures the SlackRubyBotServer instance by setting the OAuth version to v2 and specifying the required scopes for the bot, such as reading channels and writing messages. ```ruby SlackRubyBotServer.configure do |config| config.oauth_version = :v2 config.oauth_scope = ['channels:read', 'chat:write'] end ``` -------------------------------- ### Configure OAuth v1 and Scopes (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Configure `slack-ruby-bot-server` to use OAuth version 1 and specify the required scopes, such as 'bot', when upgrading classic apps that use the extracted RTM support (`slack-ruby-bot-server-rtm`). ```Ruby SlackRubyBotServer.configure do |config| config.oauth_version = :v1 config.oauth_scope = ['bot'] end ``` -------------------------------- ### Overriding SlackRubyBotServer Service Class (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Shows how to define a custom service class that inherits from `SlackRubyBotServer::Service` and configure the server to use it, allowing the addition of custom methods or behavior to the service instance. ```ruby class MyService < SlackRubyBotServer::Service def url 'https://www.example.com' end end SlackRubyBotServer.configure do |config| config.service_class = MyService end SlackRubyBotServer::Service.instance # MyService SlackRubyBotServer::Service.instance.url # https://www.example.com ``` -------------------------------- ### Disallow All User Agents (robots.txt) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/public/robots.txt Configures the robots.txt file to prevent all web crawlers (identified by '*') from accessing any part of the site (indicated by '/'). This is typically used to restrict access to development or private sites. ```text User-Agent: * Disallow: / ``` -------------------------------- ### Add Activated User Fields to Team Model (ActiveRecord Migration) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Create an ActiveRecord migration to add the `bot_user_id`, `activated_user_id`, and `activated_user_access_token` columns to the `teams` table. This is required when upgrading to version 0.10.0 or later if using ActiveRecord. ```Ruby class AddActivatedFields < ActiveRecord::Migration[5.0] def change add_column :teams, :bot_user_id, :string add_column :teams, :activated_user_id, :string add_column :teams, :activated_user_access_token, :string end end ``` -------------------------------- ### Add OAuth Fields to Team Model (ActiveRecord Migration) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Create an ActiveRecord migration to add the `oauth_scope` and `oauth_version` columns to the `teams` table. This is required when upgrading to version 1.2.0 or later if using ActiveRecord. ```Ruby class AddOauthFields < ActiveRecord::Migration[5.0] def change add_column :teams, :oauth_scope, :string add_column :teams, :oauth_version, :string, default: 'v1', null: false end end ``` -------------------------------- ### Validating OAuth State Parameter in Creating Callback (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Illustrates how to access and validate the 'state' parameter passed during the OAuth flow within the `:creating` lifecycle callback of the SlackRubyBotServer service, raising an error if the state does not match the expected value. ```ruby instance = SlackRubyBotServer::Service.instance instance.on :creating do |team, error, options| raise "Unauthorized response" unless options[:state] == auth end ``` -------------------------------- ### Generating HMAC SHA256 Hex Digest (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/README.md Shows how to generate an HMAC SHA256 hexadecimal digest using the OpenSSL library in Ruby, typically used for data integrity or authentication purposes like validating the 'state' parameter in OAuth. ```ruby auth = OpenSSL::HMAC.hexdigest("SHA256", "key", "data") ``` -------------------------------- ### Disable Ping Worker Configuration (Ruby) Source: https://github.com/slack-ruby/slack-ruby-bot-server/blob/master/UPGRADING.md Configures `slack-ruby-bot-server` to disable the automatic ping worker introduced in version 0.7.0. This worker checks bot status and restarts disconnected bots. Set `enabled` to `false` to turn it off. ```Ruby SlackRubyBotServer.configure do |config| config.ping = { enabled: false } end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.