{"id":15048081,"url":"https://github.com/github/chatops-controller","last_synced_at":"2025-05-16T14:08:04.560Z","repository":{"id":46943923,"uuid":"59038600","full_name":"github/chatops-controller","owner":"github","description":"A rails plugin to make creating chatops easy","archived":false,"fork":false,"pushed_at":"2024-12-08T02:56:06.000Z","size":52454,"stargazers_count":63,"open_issues_count":2,"forks_count":18,"subscribers_count":308,"default_branch":"master","last_synced_at":"2025-05-13T14:23:47.807Z","etag":null,"topics":["chatops","chatops-rpc"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/github.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-17T16:13:53.000Z","updated_at":"2025-04-22T23:28:03.000Z","dependencies_parsed_at":"2024-01-08T13:26:14.606Z","dependency_job_id":"56764fc4-5561-4d93-81f4-374a13e5b268","html_url":"https://github.com/github/chatops-controller","commit_stats":{"total_commits":156,"total_committers":20,"mean_commits":7.8,"dds":0.4487179487179487,"last_synced_commit":"33322579f02cf2c15dae834cd3ce5d902ffe4c55"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fchatops-controller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fchatops-controller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fchatops-controller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fchatops-controller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github","download_url":"https://codeload.github.com/github/chatops-controller/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatops","chatops-rpc"],"created_at":"2024-09-24T21:07:57.652Z","updated_at":"2025-05-16T14:07:59.550Z","avatar_url":"https://github.com/github.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chatops Controller\n\nRails helpers for easy and well-tested Chatops RPC. See the [protocol docs](docs/protocol-description.md)\nfor background information on Chatops RPC.\n\nA minimal controller example:\n\n```ruby\nclass ChatopsController \u003c ApplicationController\n  include ::Chatops::Controller\n\n  # The default chatops RPC prefix. Clients may replace this.\n  chatops_namespace :echo\n\n  chatop :echo,\n  /(?\u003ctext\u003e.*)?/,\n  \"\u003ctext\u003e - Echo some text back\" do\n    jsonrpc_success \"Echoing back to you: #{jsonrpc_params[:text]}\"\n  end\nend\n```\n\nSome routing boilerplate is required in `config/routes.rb`:\n\n```ruby\nRails.application.routes.draw do\n  # Replace the controller: argument with your controller's name\n  post \"/_chatops/:chatop\", controller: \"chatops\", action: :execute_chatop\n  get  \"/_chatops\" =\u003e \"chatops#list\"\nend\n```\n\nIt's easy to test:\n\n```ruby\nclass MyControllerTestCase \u003c ActionController::TestCase\n  include Chatops::Controller::TestCaseHelpers\n  before do\n    chatops_prefix \"echo\"\n    chatops_auth!\n  end\n\n  def test_it_works\n    chat \"echo foo bar baz\"\n    assert_equal \"foo bar baz\", chatop_response\n  end\nend\n```\n\nBefore you deploy, add the RPC authentication tokens to your app's environment,\nbelow.\n\nYou're all done. Try `.echo foo`, and you should see your client respond with\n`Echoing back to you: foo`.\n\nA hubot client implementation is available at\n\u003chttps://github.com/bhuga/hubot-chatops-rpc\u003e\n\n## Usage\n\n#### Namespaces\n\nEvery chatops controller has a namespace. All commands associated with this\ncontroller will be displayed with `.\u003cnamespace\u003e` in chat. The namespace is a\ndefault chatops RPC prefix and may be overridden by a client.\n\n```\nchatops_namespace :foo\n```\n\n#### Creating Chatops\n\nCreating a chatop is a DSL:\n\n```ruby\nchatop :echo,\n/(?\u003ctext\u003e.*)?/,\n\"\u003ctext\u003e - Echo some text back\" do\n  jsonrpc_success \"Echoing back to you: #{jsonrpc_params[:text]}\"\nend\n```\n\nIn this example, we've created a chatop called `echo`. The next argument is a\nregular expression with [named\ncaptures](http://ruby-doc.org/core-1.9.3/Regexp.html#method-i-named_captures).\nIn this example, only one capture group is available, `text`.\n\nThe next line is a string, which is a single line of help that will be displayed\nin chat for `.echo`.\n\nThe DSL takes a block, which is the code that will run when the chat robot sees\nthis regex. Arguments will be available in the `params` hash. `params[:user]`\nand `params[:room_id]` are special, and will be set by the client. `user` will\nalways be the login of the user typing the command, and `room_id` will be where\nit was typed.\nThe optional `mention_slug` parameter will provide the name to use to refer to\nthe user when sending a message; this may or may not be the same thing as the\nusername, depending on the chat system being used. The optional `message_id` parameter will provide a reference to the message that invoked the rpc.\n\nYou can return `jsonrpc_success` with a string to return text to chat. If you\nhave an input validation or other handle-able error, you can use\n`jsonrpc_failure` to send a helpful error message.\n\nChatops are regular old rails controller actions, and you can use niceties like\n`before_action` and friends. `before_action :echo, :load_user` for the above\ncase would call `load_user` before running `echo`.\n\n## Authentication\n\nAuthentication uses the Chatops v3 public key signing protocol. You'll need\ntwo environment variables to use this protocol:\n\n`CHATOPS_AUTH_PUBLIC_KEY` is the public key of your chatops client in PEM\nformat. This environment variable will be the contents of a `.pub` file,\nnewlines and all.\n\n`CHATOPS_AUTH_BASE_URL` is the base URLs of your servers as the chatops client\nsees it. This is specified as an environment variable since rails will trust\nclient headers about a forwarded hostname. For example, if your chatops client\nhas added the url `https://example.com/_chatops`, you'd set this to\n`https://example.com`. You can specify more than one base url divided by comma,\ne.g. `https://example.com,https://example2.com`\n\nYou can also optionally set `CHATOPS_AUTH_ALT_PUBLIC_KEY` to a second public key\nwhich will be accepted. This is helpful when rolling keys.\n\n## Rails compatibility\n\nThis gem is intended to work with rails 6.x and 7.x. If you find a version\nwith a problem, please report it in an issue.\n\n## Development\n\nChanges are welcome. Getting started:\n\n```\nscript/bootstrap\nscript/test\n```\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for contribution instructions.\n\n## Upgrading from early versions\n\nEarly versions of RPC chatops had two major changes:\n\n##### Using Rails' dynamic `:action` routing, which was deprecated in Rails 5.\n\nTo work around this, you need to update your router boilerplate:\n\nThis:\n\n```ruby\n  post  \"/_chatops/:action\", controller: \"chatops\"\n```\n\nBecomes this:\n\n```ruby\n  post  \"/_chatops/:chatop\", controller: \"chatops\" action: :execute_chatop\n```\n\n##### Adding a prefix\n\nVersion 2 of the Chatops RPC protocol assumes a unique prefix for each endpoint. This decision was made for several reasons:\n\n * The previous suffix-based system creates semantic ambiguities with keyword arguments\n * Prefixes allow big improvements to `.help`\n * Prefixes make regex-clobbering impossible\n\nTo upgrade to version 2, upgrade to version 2.x of this gem. To migrate:\n\n * Migrate your chatops to remove any prefixes you have:\n\n```ruby\n chatop :foo, \"help\", /ci build whatever/, do \"yay\" end\n```\n\nBecomes:\n\n```ruby\n chatop :foo, \"help\", /build whatever/, do \"yay\" end\n```\n\n * Update your tests:\n\n```ruby\n  chat \"ci build foobar\"\n```\n\nBecomes:\n\n```ruby\n  chat \"build foobar\"\n  # or\n  chatops_prefix \"ci\"\n  chat \"ci build foobar\"\n```\n\n##### Using public key authentication\n\nPrevious versions used a `CHATOPS_ALT_AUTH_TOKEN` as a shared secret. This form\nof authentication was deprecated and the public key form used above is now\nused instead.\n\n### License\n\nMIT. See the accompanying LICENSE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Fchatops-controller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub%2Fchatops-controller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Fchatops-controller/lists"}