How to Create Custom Slash Commands in Slack

Slack is a team capability tool that comes with many configurations and services meant for customization. One of a best of a customizable facilities are Slash Commands. Slash Commands are radically keywords that perform a certain movement when we enter them as messages with a preceding brazen condense pitch (/) in Slack.

10 Productivity Tools to Do More with Slack

10 Productivity Tools to Do More with Slack

Since a launch in 2013, Slack has grown to turn a tip group communication tool. Its accessibility across…Read more

Built-in Slash commands

The stream set of built-in Slash commands performs an array of predefined functions in Slack. For instance, by entering a /away Slash Command into a summary submit box, you can toggle a Status of your account, as we can see it on a gif below.

Custom Slash commands

You can also create tradition Slash commands in Slack. Custom Slash commands concede developers to make secure HTTP requests to web applications or services, and receive applicable responses from them that are displayed as new Slack messages.

As an example, contend there is a web use that earnings a stream measure of a football compare in plain text. You can emanate a Slash authority to make a secure HTTP request to that web service, and arrangement a measure received as a response text in a Slack summary window.

Create a Slash command

To emanate a Slash command, enter a https://[yourTeam] URL to your browser’s residence bar, usually replace a [yourTeam] placeholder with a name of your Slack team, and click a Slash Commands option.

On a subsequent screen, enter a keyword we wish to use for your Slack Command (don’t use any space), afterwards click a Add Slash Command Integration button. You can later revise this keyword if we want.

On a subsequent screen, we can configure a settings for your Slash command. You need to enter a URL of a web application we wish to send your ask to. You can also see a token value for a Slash authority you’ve usually created, that we can use in your web server to validate a request sent by Slack.

Display a response

By default, a responses for a requests done by Slash commands are shown as plain text in a summary window. If you’d rather uncover a messages in a Slack summary format instead, a responses need to be in valid JSON format.

Also, by default, a response of a Slash Command is visible usually to a user who entered that command, and not others in a channel. This can usually be altered if a response is a current JSON carrying a skill called "response_type" with a value "in_channel", afterwards all users in a channel can see a response. The "text" skill holds a categorical text that will be shown in a message.

// Example JSON response
	"response_type": "in_channel",
	"text": "..."

As an example, I’ll arrangement an ASCII art chessboard in response to my tradition /lets-play Slash authority I’ve combined in a prior section, so as to denote that we can display some-more difficult characters in a response as well. You can review some-more on Slack’s summary formatting in a Slack API docs.

Below, we can see a screenshot of a JSON response my instance Slash authority will display, or we can find a same JSON record on Github.

If we also want line breaks in your message, use a n new line character in a value of a "text" property.

Run a command

Go to a channel or to a DM summary window in Slack, and enter a new Slash command into a summary submit field. If we had ticked a Show this authority in a autocomplete list checkbox in your Slash authority settings, you’ll see your authority in a idea list while typing.

If we hadn’t and we wish to refurbish this settings now, we can lapse to your Slash authority settings page, and revise your configurations by clicking on a small pencil idol right to a command.

Below we can see a gif demo that demonstrates how my custom Slash command with a ASCII art chessboard works in Slack.

Add Comment