Project

mos-eisley

0.0
No commit activity in last 3 years
No release in over 3 years
A Ruby based HTTP server for Slack app actions, commands, events, and making web API calls.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.1
~> 2.0
~> 1.7
 Project Readme

mos-eisley

Gem Version Code Climate security

A Ruby based Slack app server. It provides API endpoints to Slack as well as functions to access Slack API and manages events with handlers you create.

Environment

Getting Started

Install the gem.

gem install mos-eisley

Create a configuration file and register some handlers. Handlers are your code that gets executed when events are received from Slack. See below for more details.

Run Mos Eisley.

mos-eisley -c config.rb start

Setup

Configuration File

This is a standard Ruby file and anything can go in it. It'll be executed at the very beginning of app launch, before the HTTP server is started. Here is an example.

# Configure application logging
MosEisley.logger = Logger.new(STDOUT)
MosEisley.logger.level = Logger::DEBUG

# Main configuration block (MosEisley namespace can be abbrv. to ME)
ME::Config.setup do |c|
  # User custom data
  c.user = {my_data1: 'Something', my_data2: 'Somethingelse'}

  # HTTP server (Sinatra) settings
  c.dump_errors = true
  c.logging = true

  # Your handlers
  c.handler_paths = [
    'handlers'
  ]

  # Slack info
  c.verification_token = 'vErIf1c4t0k3n5'
  c.bot_access_token = 'xoxb-1234567890-b0t4cCe5sToK3N'
end

Handlers

Define handlers, also a Ruby file, and they'll be executed as incoming Slack events are processed. You can define as many handlers as you want. You'll store the file(s) in the directory you've identified in the configuration file above.

There are 3 types of handlers you can define: :action, :command, :event, which corresponds to the MosEisley endpoints accordingly.

ME::Handler.add(:event, 'debug') do |e, h|
  e.event.each { |k, v| puts "#{k}: #{v}" }
  h.stop unless e.for_me?
end

Slack

Create an app in Slack to setup a bot. Following features can be setup.

  • Interactive Components – Request URL should be set to MosEisley's /action endpoint.
  • Slash Commands – Request URL should be set to MosEisley's /command endpoint.
  • OAuth & Permission – This is where you get the Bot User OAuth Access Token you need to set in the configuration file.
  • Event Subscription – Request URL should be set to MosEisley's /event endpoint. You'll likely Subscribe to Bot Events of app_mention or any of the message.* events.

CLI Usage

To see help:

$ mos-eisley -h
Usage: mos-eisley [options] {start|stop}
  -c, --config=<s>     Load config from file
  -d, --daemonize      Run in the background
  -l, --log=<s>        Log output to file
  -P, --pid=<s>        Store PID to file
  -p, --port=<i>       Use port (default: 4567)

The minimum to start a server:

$ mos-eisley -c config.rb start