Create slack bot with slash command

Create slack bot with slash command

Huska

Create your slack bot application

  1. Go to url your slack applications.
    slack_01
  2. Click button Create New App.
    slack_02
  3. Choose create an app From scratch.
    slack_03
  4. Input your bot name and choose your workspace.
    slack_04
  5. You will see your app in apps list.
    slack_05

Setting your custom slack command

  1. Go to your app setting page by clicking it's name that you create before.
  2. Go to Slash Commands on left side menu.
    slack_06
  3. Click button Create New Command to start your new command for bot.
  4. Input your command information. In this guideline, I will create command to get time of the place that I input.
    slack_07
  5. Install app to worksapce that you want to use it.
  • Go to Basic Information on left side menu.slack_08
  • Click Install to Workspace.
    slack_09
  • Click Allow.
  1. After installing, you will see the app in your slack workspace
    slack_10

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 package moment-timezone to support get current time with timezone.
    slack_11
  • 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
      slack_12-1
    • Result
      slack_13

Addition setting

  • You can't send direct message (DM) to your bot by default.
    slack_14
  • Please follow this setting to enable DM between you and bot.
    1. Go to your bot (app) setting.
    2. Select App Home on left side menu.
      slack_15-1
    3. Go to Show Tabs section.
      slack_17-1
    4. Check on checkbox Allow users to send Slash commands and messages from the messages tab.
      slack_16-1
    5. Now you can send DM to your bot. You may need to relogin to see the effect.
      slack_18

Summary

I hope this guideline will help you to create a bot (app) on slack with slash command easily.
Thanks for reading.