All Projects → github → chatops-controller

github / chatops-controller

Licence: MIT license
A rails plugin to make creating chatops easy

Programming Languages

ruby
36898 projects - #4 most used programming language
HTML
75241 projects
CSS
56736 projects
shell
77523 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to chatops-controller

Hanu
Golang Framework for writing Slack bots
Stars: ✭ 128 (+120.69%)
Mutual labels:  chatops
Slacknimate
👯 Realtime text animation for Slack chatops
Stars: ✭ 250 (+331.03%)
Mutual labels:  chatops
slash-heroku
/heroku commands for slack
Stars: ✭ 37 (-36.21%)
Mutual labels:  chatops
Lita Slack
A Slack adapter for Lita.
Stars: ✭ 138 (+137.93%)
Mutual labels:  chatops
Errbot
Errbot is a chatbot, a daemon that connects to your favorite chat service and bring your tools and some fun into the conversation.
Stars: ✭ 2,605 (+4391.38%)
Mutual labels:  chatops
Chat-Bot-Security-Checklist
Chat Bot Security Checklist
Stars: ✭ 20 (-65.52%)
Mutual labels:  chatops
Hubcommander
A Slack bot for GitHub organization management -- and other things too
Stars: ✭ 1,149 (+1881.03%)
Mutual labels:  chatops
trax
Simple time tracker designed for ChatOps
Stars: ✭ 40 (-31.03%)
Mutual labels:  chatops
Slash Command Dispatch
A GitHub action that facilitates "ChatOps" by creating repository dispatch events for slash commands
Stars: ✭ 231 (+298.28%)
Mutual labels:  chatops
cogy
Cog commands from your Rails app
Stars: ✭ 20 (-65.52%)
Mutual labels:  chatops
Flottbot
A chatbot framework written in Go. All configurations are made in YAML files, or inside scripts written in your favorite language.
Stars: ✭ 175 (+201.72%)
Mutual labels:  chatops
Sactive Bot
😈 An extensible chat bot framework. sactive-bot is an evolution of the open source hubot project. - https://www.shipengqi.top/sactive-bot .
Stars: ✭ 212 (+265.52%)
Mutual labels:  chatops
isolex
Chat bot able to speak natural language and markup, prompt to complete commands, and offer localized help. Configured with schema-validated YAML, features JWT authentication with granular RBAC, and SQL persistence.
Stars: ✭ 15 (-74.14%)
Mutual labels:  chatops
Lita
ChatOps for Ruby.
Stars: ✭ 1,663 (+2767.24%)
Mutual labels:  chatops
cog-helm
A Helm chart to deploy Cog on Kubernetes
Stars: ✭ 17 (-70.69%)
Mutual labels:  chatops
Showcase Ansible Chatops
Vagrant Demo showing ChatOps with Ansible
Stars: ✭ 71 (+22.41%)
Mutual labels:  chatops
ansible-hubot
💬 Ansible role for Hubot
Stars: ✭ 63 (+8.62%)
Mutual labels:  chatops
gort
Gort is a chatbot framework designed from the ground up for chatops.
Stars: ✭ 381 (+556.9%)
Mutual labels:  chatops
flixctl
A toolkit for controlling the infrastructure necessary for a true MaSaS (Movies and Shows as a Service) architecture.
Stars: ✭ 43 (-25.86%)
Mutual labels:  chatops
speakerboxxx
Configurable GitHub organization hooks for Slack teams
Stars: ✭ 20 (-65.52%)
Mutual labels:  chatops

Chatops Controller

Rails helpers for easy and well-tested Chatops RPC. See the protocol docs for background information on Chatops RPC.

A minimal controller example:

class ChatopsController < ApplicationController
  include ::Chatops::Controller

  # The default chatops RPC prefix. Clients may replace this.
  chatops_namespace :echo

  chatop :echo,
  /(?<text>.*)?/,
  "<text> - Echo some text back" do
    jsonrpc_success "Echoing back to you: #{jsonrpc_params[:text]}"
  end
end

Some routing boilerplate is required in config/routes.rb:

Rails.application.routes.draw do
  # Replace the controller: argument with your controller's name
  post "/_chatops/:chatop", controller: "chatops", action: :execute_chatop
  get  "/_chatops" => "chatops#list"
end

It's easy to test:

class MyControllerTestCase < ActionController::TestCase
  include Chatops::Controller::TestCaseHelpers
  before do
    chatops_prefix "echo"
    chatops_auth!
  end

  def test_it_works
    chat "echo foo bar baz"
    assert_equal "foo bar baz", chatop_response
  end
end

Before you deploy, add the RPC authentication tokens to your app's environment, below.

You're all done. Try .echo foo, and you should see your client respond with Echoing back to you: foo.

A hubot client implementation is available at https://github.com/hubot-scripts/hubot-chatops-rpc

Usage

Namespaces

Every chatops controller has a namespace. All commands associated with this controller will be displayed with .<namespace> in chat. The namespace is a default chatops RPC prefix and may be overridden by a client.

chatops_namespace :foo

Creating Chatops

Creating a chatop is a DSL:

chatop :echo,
/(?<text>.*)?/,
"<text> - Echo some text back" do
  jsonrpc_success "Echoing back to you: #{jsonrpc_params[:text]}"
end

In this example, we've created a chatop called echo. The next argument is a regular expression with named captures. In this example, only one capture group is available, text.

The next line is a string, which is a single line of help that will be displayed in chat for .echo.

The DSL takes a block, which is the code that will run when the chat robot sees this regex. Arguments will be available in the params hash. params[:user] and params[:room_id] are special, and will be set by the client. user will always be the login of the user typing the command, and room_id will be where it was typed. The optional mention_slug parameter will provide the name to use to refer to the user when sending a message; this may or may not be the same thing as the username, depending on the chat system being used. The optional message_id parameter will provide a reference to the message that invoked the rpc.

You can return jsonrpc_success with a string to return text to chat. If you have an input validation or other handle-able error, you can use jsonrpc_failure to send a helpful error message.

Chatops are regular old rails controller actions, and you can use niceties like before_action and friends. before_action :echo, :load_user for the above case would call load_user before running echo.

Authentication

Authentication uses the Chatops v3 public key signing protocol. You'll need two environment variables to use this protocol:

CHATOPS_AUTH_PUBLIC_KEY is the public key of your chatops client in PEM format. This environment variable will be the contents of a .pub file, newlines and all.

CHATOPS_AUTH_BASE_URL is the base URL of your server as the chatops client sees it. This is specified as an environment variable since rails will trust client headers about a forwarded hostname. For example, if your chatops client has added the url https://example.com/_chatops, you'd set this to https://example.com.

You can also optionally set CHATOPS_AUTH_ALT_PUBLIC_KEY to a second public key which will be accepted. This is helpful when rolling keys.

Rails compatibility

This gem is intended to work with rails 6.x and 7.x. If you find a version with a problem, please report it in an issue.

Development

Changes are welcome. Getting started:

script/bootstrap
script/test

See CONTRIBUTING.md for contribution instructions.

Upgrading from early versions

Early versions of RPC chatops had two major changes:

Using Rails' dynamic :action routing, which was deprecated in Rails 5.

To work around this, you need to update your router boilerplate:

This:

  post  "/_chatops/:action", controller: "chatops"

Becomes this:

  post  "/_chatops/:chatop", controller: "chatops" action: :execute_chatop
Adding a prefix

Version 2 of the Chatops RPC protocol assumes a unique prefix for each endpoint. This decision was made for several reasons:

  • The previous suffix-based system creates semantic ambiguities with keyword arguments
  • Prefixes allow big improvements to .help
  • Prefixes make regex-clobbering impossible

To upgrade to version 2, upgrade to version 2.x of this gem. To migrate:

  • Migrate your chatops to remove any prefixes you have:
 chatop :foo, "help", /ci build whatever/, do "yay" end

Becomes:

 chatop :foo, "help", /build whatever/, do "yay" end
  • Update your tests:
  chat "ci build foobar"

Becomes:

  chat "build foobar"
  # or
  chatops_prefix "ci"
  chat "ci build foobar"
Using public key authentication

Previous versions used a CHATOPS_ALT_AUTH_TOKEN as a shared secret. This form of authentication was deprecated and the public key form used above is now used instead.

License

MIT. See the accompanying LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].