Create your slack bot application
- Go to url your slack applications.
- Click button
Create New App
.
- Choose create an app
From scratch
.
- Input your bot name and choose your workspace.
- You will see your app in apps list.
Setting your custom slack command
- Go to your app setting page by clicking it's name that you create before.
- Go to
Slash Commands
on left side menu.
- Click button
Create New Command
to start your new command for bot. - Input your command information. In this guideline, I will create command to get time of the place that I input.
- Install app to worksapce that you want to use it.
- Go to
Basic Information
on left side menu. - Click
Install to Workspace
.
- Click
Allow
.
- After installing, you will see the app in your slack workspace
Create server to handle slack command.
- Prepare a backend server to handle command from slack. In this guideline I choose a simple API framework
express
and packagemoment-timezone
to support get current time with timezone.
- Use
ngrok
to support publish your host if you don't have public domain.
Please refer: Ngrok
Testing
- You can use slash command on any channel in your workspace.
- Try to use command with the city name that you define above.
- Use
- Result
- Use
Addition setting
- You can't send direct message (DM) to your bot by default.
- Please follow this setting to enable DM between you and bot.
- Go to your bot (app) setting.
- Select
App Home
on left side menu.
- Go to
Show Tabs
section.
- Check on checkbox
Allow users to send Slash commands and messages from the messages tab
.
- Now you can send DM to your bot. You may need to relogin to see the effect.
Summary
I hope this guideline will help you to create a bot (app) on slack with slash command easily.
Thanks for reading.