Slash commands in Slack
Messages that begin with a slash (/) are commands that behave differently from regular messages. When we begin a message with a slash, it behaves as a command, which in turn triggers an action. For example, Using the "topic" command to change your current channel's topic to "Hello!" by typing /topic Hello!. Slack allows you to register custom slash commands, which can take parameters and perform an action.
In our demonstration, we will create a slash command to accept an URL and Catchpoint node ID. Then run an object test on the specified Catchpoint node and display the result in the Slack channel.

With the above slash command, we run a Catchpoint Object test. The results for this command will return the response/status code of requests.

The input for the command should be the URL followed by the Catchpoint node ID. The URL should begin with a protocol example http:// or https://. To get the Catchpoint node ID, go to the Nodes page in the Catchpoint portal.
Create a new Slack application
To create a custom slash command, begin by creating a Slack application. Follow this link to create a slack application.

Provide an App Name, select your Development Slack Workspace and click on Create App.
Once we create an app, follow the below steps to set up the custom command.
-
Under Basic Information, select Slash Commands from Add features and functionality.

-
Click on Create a new command.
-
Fill out details in regards to the custom command and click Save.
The "Request URL" should be pointing to the server where the code resides. For this demonstration, my code is hosted locally and will be using ngrok to make it accessible online.

- Install your newly created app to your workspace.
- Go to Settings --> Basic Information
- Expand install your app to your workspace and Install the app
- Click Authorize to complete the process
Setting up the environment with node.js
-
Install node.js on your system, you can install it from: https://nodejs.org/en/
-
To begin, create a folder where we will place all the project files.
-
Open Terminal and navigate to the newly created folder and run the command below. This will ask you to fill in the basic details about the project, fill them and save them. Once the changes are saved it will create a package.json file in that folder.
npm init -
For this project we will depend on a couple of dependencies, to install their type in the below commands.
npm install express npm install body-parser npm install http npm install https npm install request npm install valid-url -
Create a file called index.js, the file name should be same as the one mentioned in package.json, in the main field.
-
Copy and paste the code from the attached file and save it.
-
In the index.js file update the client key, secret and port number variables values.

-
Run the below command to run your project.
Make your project accessible online
Right now our project is accessible locally, in order for it to talk to slack we will be using ngrok. Ngrok creates a tunnel from the public internet to a port on your local machine. You can give this URL to anyone to allow them to try out a website you're developing without doing any deployment. You can install ngrok from this URL: https://ngrok.com/
Install ngrok in your system and open a separate terminal and enter the following command. In the current project, we are listening to port 3000.
ngrok http 3000

Fetch the highlighted URL from your terminal and update the “Request URL” under the Slack slash command configuration page.
Finally, we are ready to go to Slack and run our custom slash command.
/catchpointrun http://www.google.com 275