{"componentChunkName":"component---src-templates-blog-post-js","path":"/blog/dropin-chatops-turning-existing-workflows-and-scripts-into-slack-commands","result":{"data":{"allGhostPost":{"edges":[{"node":{"title":"Dropin ChatOps: turning existing workflows and scripts into Slack Commands","html":"

Dropin is a minimalist Slack slash command integration with one purpose: bridging the gap between Slack and existing shell scripts and programs.

\n

Dropin runs specific commands and sends their output back to Slack. This allows you to add your existing scripts to Slack without having to build a specific integration around them—for most kinds of use-cases, Dropin will Just Work™ out of the box.

\n

Dropin supports basic authorization in the form of whitelisted channels and user IDs.

\n

How to Add Dropin to your Slack Team

\n

Prerequisites

\n\n

Configuring Slack

\n

Start by creating a new Slack slash command here. Fill out these fields:

\n\n

Installing Dropin

\n

Dropin is released as a static binary. You can download the latest release from the releases page on GitHub. Once you've done so, place the binary wherever you want: /usr/local/bin, /opt/dropin, etc. Set proper permissions by running:

\n
sudo chown root:root /path/to/dropin\nsudo chmod 755 /path/to/dropin\n
\n

Configuring Dropin

\n

Dropin uses a config file to store the Slack connection info and other settings as well as the chatops commands. Start by setting the global settings:

\n
team = "Slack Team ID"\ntoken = "Slack Token"\nlistenaddress = "127.0.0.1:4000"\ntimeout = "3m"\n
\n

timeout is the global timeout value for chatops commands. Commands that exceed the timeout limit will be canceled. This default value can be overriden per individual command.

\n

Set up authorization:

\n
[[users]]\n    name = "user name"\n    id = "user ID"\n\n[[channels]]\n    name = "channel name"\n    id = "channel ID"\n
\n

Helpful links:

\n\n

Add a Command

\n

To add a command, add a section like this to the config file:

\n
[[commands]]\n    name = "test"\n    description = "This is a test command"\n    executable = "/bin/echo"\n    chdir = "/tmp"\n    args = ["test"]\n
\n

With this command, running /chatops test will return test—the output of running /bin/echo test.

\n

Available options are:

\n\n

Another example command:

\n
[[commands]]\n    name = "sleep"\n    description = "This command should fail"\n    executable = "/bin/sleep"\n    chdir = "/tmp"\n    args = ["5"]\n    takesArguments = false\n    timeout = "2s"\n
\n

HTTPS

\n

It's always recommended for web services to communicate over HTTPS instead of plain HTTP. While Slack allows you to run slash commands over HTTP, Dropin can easily be put behind an HTTPS proxy. We'll use Caddy but you can use whichever web server you like (Nginx, traefik, etc.).

\n

First, set Dropin to listen locally, e.g. localhost:4000. You can use any port you like as long as it's not used by another process and is over 1024.

\n

Add the following to your Caddyfile and Caddy will take care of the rest.

\n
yourdomain.com {\n    tls your-email-address-here\n    proxy / http://localhost:4000\n}\n
\n

Set Slack to use https://yourdomain.com/ as the slash command URL and you'll be all set.

\n

Running Dropin as a System Service

\n

You can use the following Systemd service unit file to run Dropin as a service. All chatops commands will be run as the same user that is running Dropin so pick one that works for you. If your commands don't need any special privileges, you can always use nouser as the user and nogroup as the group.

\n
[Unit]\nDescription=dropin-chatops for Slack\nAfter=network-online.target\n\n[Service]\nRestart=on-failure\n\nUser=dropin\nGroup=dropin\n\nExecStart=/opt/dropin/dropin -config /opt/dropin/dropin.toml\n\n[Install]\nWantedBy=multi-user.target\n
\n

Replace /opt/dropin/dropin with the path to the Dropin binary, and /opt/dropin/dropin.toml with the path to config file.

\n

Save the file in /etc/systemd/system/dropin.service and enable it:

\n
sudo systemctl daemon-reload\nsudo systemctl start dropin\nsudo systemctl enable dropin\n
\n","published_at":"2018-09-04T12:17:08.000+03:00","slug":"dropin-chatops-turning-existing-workflows-and-scripts-into-slack-commands","tags":[],"plaintext":"Dropin [https://github.com/kamaln7/dropin-chatops] is a minimalist Slack slash\ncommand integration with one purpose: bridging the gap between Slack and\nexisting shell scripts and programs.\n\nDropin runs specific commands and sends their output back to Slack. This allows\nyou to add your existing scripts to Slack without having to build a specific\nintegration around them—for most kinds of use-cases, Dropin will Just Work™ out\nof the box.\n\nDropin supports basic authorization in the form of whitelisted channels and user\nIDs.\n\nHow to Add Dropin to your Slack Team\nPrerequisites\n * A Linux server (I hear DigitalOcean [https://kmln.sr/do] have some good\n cloud servers 😉)\n * A domain name. A subdomain will work too. (required by Slack)\n\nConfiguring Slack\nStart by creating a new Slack slash command here\n[https://digitalocean.slack.com/apps/A0F82E8CA-slash-commands]. Fill out these\nfields:\n\n * Command\n * URL: https://yourdomain.com\n * Method: POST\n * Token: Slack will auto-generate one for you\n * Tick Show this command in the autocomplete list if you like\n\nInstalling Dropin\nDropin is released as a static binary. You can download the latest release from \nthe releases page on GitHub\n[https://github.com/kamaln7/dropin-chatops/releases/latest]. Once you've done\nso, place the binary wherever you want: /usr/local/bin, /opt/dropin, etc. Set\nproper permissions by running:\n\nsudo chown root:root /path/to/dropin\nsudo chmod 755 /path/to/dropin\n\n\nConfiguring Dropin\nDropin uses a config file to store the Slack connection info and other settings\nas well as the chatops commands. Start by setting the global settings:\n\nteam = \"Slack Team ID\"\ntoken = \"Slack Token\"\nlistenaddress = \"127.0.0.1:4000\"\ntimeout = \"3m\"\n\n\ntimeout is the global timeout value for chatops commands. Commands that exceed\nthe timeout limit will be canceled. This default value can be overriden per\nindividual command.\n\nSet up authorization:\n\n[[users]]\n name = \"user name\"\n id = \"user ID\"\n\n[[channels]]\n name = \"channel name\"\n id = \"channel ID\"\n\n\nHelpful links:\n\n * What is the simplest way to find a slack team ID and a channel ID?\n [https://stackoverflow.com/questions/40940327/what-is-the-simplest-way-to-find-a-slack-team-id-and-a-channel-id]\n\nAdd a Command\nTo add a command, add a section like this to the config file:\n\n[[commands]]\n name = \"test\"\n description = \"This is a test command\"\n executable = \"/bin/echo\"\n chdir = \"/tmp\"\n args = [\"test\"]\n\n\nWith this command, running /chatops test will return test—the output of running\n /bin/echo test.\n\nAvailable options are:\n\n * name name, passed to the slash command. No spaces allowed\n * description description\n * executable = \"/bin/sleep\"\n * chdir the working directory to run the command in\n * args an array of arguments passed to the command\n * takesArguments boolean. if true, any arguments passed to the slash command\n will be appended to the original command\n * timeout an optional override of the global timeout limit\n\nAnother example command:\n\n[[commands]]\n name = \"sleep\"\n description = \"This command should fail\"\n executable = \"/bin/sleep\"\n chdir = \"/tmp\"\n args = [\"5\"]\n takesArguments = false\n timeout = \"2s\"\n\n\nHTTPS\nIt's always recommended for web services to communicate over HTTPS instead of\nplain HTTP. While Slack allows you to run slash commands over HTTP, Dropin can\neasily be put behind an HTTPS proxy. We'll use Caddy [https://caddyserver.com] \nbut you can use whichever web server you like (Nginx, traefik, etc.).\n\nFirst, set Dropin to listen locally, e.g. localhost:4000. You can use any port\nyou like as long as it's not used by another process and is over 1024.\n\nAdd the following to your Caddyfile and Caddy will take care of the rest.\n\nyourdomain.com {\n tls your-email-address-here\n proxy / http://localhost:4000\n}\n\n\nSet Slack to use https://yourdomain.com/ as the slash command URL and you'll be\nall set.\n\nRunning Dropin as a System Service\nYou can use the following Systemd service unit file to run Dropin as a service.\nAll chatops commands will be run as the same user that is running Dropin so pick\none that works for you. If your commands don't need any special privileges, you\ncan always use nouser as the user and nogroup as the group.\n\n[Unit]\nDescription=dropin-chatops for Slack\nAfter=network-online.target\n\n[Service]\nRestart=on-failure\n\nUser=dropin\nGroup=dropin\n\nExecStart=/opt/dropin/dropin -config /opt/dropin/dropin.toml\n\n[Install]\nWantedBy=multi-user.target\n\n\nReplace /opt/dropin/dropin with the path to the Dropin binary, and \n/opt/dropin/dropin.toml with the path to config file.\n\nSave the file in /etc/systemd/system/dropin.service and enable it:\n\nsudo systemctl daemon-reload\nsudo systemctl start dropin\nsudo systemctl enable dropin","meta_description":null}}]}},"pageContext":{"slug":"dropin-chatops-turning-existing-workflows-and-scripts-into-slack-commands","prev":"docker-registry-becomes-unavailable-and-returns-503","next":"securing-internal-services-behind-oauth2-with-caddy"}},"staticQueryHashes":["3649515864"]}