Slack is a crew productiveness device that includes many configurations and services and products supposed for personalization. One of the crucial absolute best of its customizable options are Slash Commands. Slash Instructions are necessarily key phrases that carry out a undeniable motion whilst you input them as messages with a previous ahead slash image (/) in Slack.

Integrated Slash instructions

The present set of built-in Slash commands plays an array of predefined purposes in Slack. As an example, through coming into the /away Slash Command into the message enter field, you’ll be able to toggle the Standing of your account, as you’ll be able to see it at the gif underneath.

Slack command, awaySlack command, away

Customized Slash instructions

You’ll additionally create tradition Slash instructions in Slack. Customized Slash instructions permit builders to make safe HTTP requests to internet packages or services and products, and obtain related responses from them which can be displayed as new Slack messages.

For instance, say there’s a internet carrier that returns the present rating of a soccer fit in simple textual content. You’ll create a Slash command to make a safe HTTP request to that internet carrier, and show the rating gained because the reaction textual content within the Slack message window.

Create a Slash command

To create a Slash command, input the https://[yourTeam].slack.com/apps/construct/custom-integration URL on your browser’s deal with bar, simply substitute the [yourTeam] placeholder with the identify of your Slack crew, and click on the Slash Instructions choice.

Create new commandCreate new command

At the subsequent display, input the key phrase you wish to have to make use of in your Slack Command (don’t use any house), then click on the Upload Slash Command Integration button. You’ll later edit this key phrase if you wish to have.

New Slash command formNew Slash command form

At the subsequent display, you’ll be able to configure the settings in your Slash command. You want to go into the URL of the internet software you wish to have to ship your request to. You’ll additionally see a token worth for the Slash command you’ve simply created, which you’ll be able to use on your internet server to validate the request despatched through Slack.

Slash command integration settingsSlash command integration settings

Show the reaction

By way of default, the responses for the requests made through Slash instructions are proven as simple textual content within the message window. For those who’d reasonably display the messages within the Slack message structure as a substitute, the responses want to be in legitimate JSON structure.

Additionally, through default, the reaction of a Slash Command is visual handiest to the person who entered that command, and no longer others within the channel. This may handiest be modified if the reaction is a sound JSON wearing the valuables referred to as "response_type" with the price "in_channel", then all customers within the channel can see the reaction. The "textual content" assets holds the principle textual content that might be proven within the message.

// Instance JSON reaction
{
	"response_type": "in_channel",
	"textual content": "..."
}

For instance, I’ll show an ASCII artwork chessboard according to my tradition /lets-play Slash command I’ve created within the earlier segment, so that you can show that you’ll be able to show extra difficult characters within the reaction as smartly. You’ll learn extra on Slack’s message formatting in the Slack API docs.

Underneath, you’ll be able to see a screenshot of the JSON reaction my instance Slash command will show, or you’ll be able to to find the similar JSON document on Github.

Sample JSONSample JSON

For those who additionally need line breaks on your message, use the n new line persona within the worth of the "textual content" assets.

Run the command

Move to a channel or to the DM message window in Slack, and input the brand new Slash command into the message enter box. For those who had ticked the Display this command within the autocomplete record checkbox on your Slash command settings, you’ll see your command within the recommendation record whilst typing.

For those who hadn’t and you wish to have to replace this settings now, you’ll be able to go back on your Slash command settings web page, and edit your configurations through clicking at the little pencil icon proper to the command.

Underneath you’ll be able to see a gif demo that demonstrates how my tradition Slash command with the ASCII artwork chessboard works in Slack.

slash command demo

The publish How to Create Custom Slash Commands in Slack seemed first on Hongkiat.

WordPress Website Development Source: https://www.hongkiat.com/blog/custom-slash-command-slack/

[ continue ]