Chatops Controller banner
github github

Chatops Controller

Development community

Description

A rails plugin to make creating chatops easy

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

Chatops Controller

Rails helpers for easy and well-tested Chatops RPC. See the [protocol docs](docs/protocol-description.md) 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,
  /(?.*)?/,
  " - 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

Usage

Namespaces

Every chatops controller has a namespace. All commands associated with this controller will be displayed with `.` 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,
/(?.*)?/,
" - 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 cap