How To Add Custom Slash Command To Slack
Slack is a team productivity tool that comes with many configurations and services meant for customization. I of the best of its customizable features are Slash Commands. Slash Commands are substantially keywords that perform a certain action when you enter them as letters with a preceding forrad slash symbol (/) in Slack.
Read Also: 10 Useful Slack Tools For Better Productivity
Built-in Slash commands
The current set of built-in Slash commands performs an array of predefined functions in Slack. For example, past entering the /away
Slash Control into the message input box, you tin can toggle the Status of your business relationship, as you tin see it on the gif below.
Custom Slash commands
You tin likewise create custom Slash commands in Slack. Custom Slash commands allow developers to brand secure HTTP requests to web applications or services, and receive relevant responses from them that are displayed as new Slack messages.
Recommended Reading: How to Ship Customized Letters to Slack from your Application
As an example, say there is a web service that returns the electric current score of a football game match in plain text. You lot tin can create a Slash control to make a secure HTTP request to that web service, and brandish the score received as the response text in the Slack message window.
Create a Slash command
To create a Slash command, enter the https://[yourTeam].slack.com/apps/build/custom-integration URL to your browser'southward accost bar, just supercede the [yourTeam] placeholder with the name of your Slack team, and click the Slash Commands option.
On the next screen, enter the keyword you want to employ for your Slack Command (don't utilise any space), and so click the Add Slash Command Integration push. You lot can after edit this keyword if yous want.
On the next screen, you can configure the settings for your Slash control. You need to enter the URL of the web awarding you want to send your request to. You lot can as well see a token value for the Slash command you've just created, which yous tin can use in your web server to validate the request sent by Slack.
Display the response
By default, the responses for the requests made by Slash commands are shown every bit apparently text in the message window. If you'd rather prove the messages in the Slack message format instead, the responses need to be in valid JSON format.
Likewise, past default, the response of a Slash Command is visible only to the user who entered that command, and not others in the channel. This tin only be changed if the response is a valid JSON conveying the property called "response_type"
with the value "in_channel"
, then all users in the channel tin can meet the response. The "text"
belongings holds the main text that will be shown in the bulletin.
// Instance JSON response { "response_type": "in_channel", "text": "..." }
As an case, I'll display an ASCII art chessboard in response to my custom /lets-play
Slash command I've created in the previous section, and so equally to demonstrate that you can display more complicated characters in the response every bit well. You can read more on Slack's message formatting in the Slack API docs.
Below, you can see a screenshot of the JSON response my example Slash command will display, or you lot can find the aforementioned JSON file on Github.
If you also desire line breaks in your message, use the \due north
new line character in the value of the "text"
holding.
Run the command
Become to a channel or to the DM message window in Slack, and enter the new Slash command into the message input field. If y'all had ticked the Bear witness this control in the autocomplete listing checkbox in your Slash control settings, you'll run across your control in the proposition list while typing.
If you hadn't and you want to update this settings now, you can render to your Slash control settings folio, and edit your configurations by clicking on the petty pencil icon right to the command.
Below yous can see a gif demo that demonstrates how my custom Slash command with the ASCII fine art chessboard works in Slack.
How To Add Custom Slash Command To Slack,
Source: https://www.hongkiat.com/blog/custom-slash-command-slack/#:~:text=To%20create%20a%20Slash%20command,click%20the%20Slash%20Commands%20option.
Posted by: boltonhicing.blogspot.com
0 Response to "How To Add Custom Slash Command To Slack"
Post a Comment