Skip to content

An "empty" Hubot project that can be used to build your own Slack bot. Based on the Slack Bolt API.

License

Notifications You must be signed in to change notification settings

wehkamp/bot-zero

Repository files navigation

bot-zero

Hubot is a fantastic project that enabled us to build great bots. The bot-zero project aims to give you a cleaned up version with some examples that run on TypeScript (instead of Coffee-script). This bot uses the Slack Bolt.

License

Blog: https://medium.com/wehkamp-techblog/jump-starting-slack-bot-projects-bot-zero-991b9654585e

Getting started

In this secion we will create the Slack app and add the details to your .env file.

  1. Goto https://api.slack.com/apps?new_app=1
  2. Click From an app manifest
  3. Select your Workspace and click Next
  4. Click YAML, paste this code in the field and click Next
display_information:
  name: Jarvis
  description: Our DevOps bot.
  background_color: "#3d001d"
features:
  app_home:
    home_tab_enabled: false
    messages_tab_enabled: true
    messages_tab_read_only_enabled: false
  bot_user:
    display_name: Jarvis-Beta
    always_online: true
oauth_config:
  scopes:
    bot:
      - app_mentions:read
      - channels:join
      - channels:history
      - chat:write
      - im:write
      - im:history
      - im:read
      - users:read
      - groups:history
      - groups:write
      - groups:read
      - mpim:history
      - mpim:write
      - mpim:read
settings:
  event_subscriptions:
    bot_events:
      - app_mention
      - message.channels
      - message.im
      - message.groups
      - message.mpim
  interactivity:
    is_enabled: true
  org_deploy_enabled: false
  socket_mode_enabled: true
  token_rotation_enabled: false
  1. Click Create
  2. Click Install to Workspace
  3. Click Allow
  4. In the Settings > Basic Information screen, scroll down to App-Level Tokens and click Generate Token and Scopes
  5. Enter a Token Name: bot-zero
  6. Click Add scope
  7. Select connections:write
  8. Click the Generate button
  9. Copy the .example.env in the root of your project to .env
  10. Copy the Token and paste it in your .env file at HUBOT_SLACK_APP_TOKEN
  11. Click the Done button
  12. Goto Settings > Install App
  13. Copy Bot User OAuth Token and paste it in your .env file at HUBOT_SLACK_BOT_TOKEN

Running the project

This project supports dev containers, so you don't have to install nodejs to your environment.

  1. Make sure your .env file has the right tokens.
  2. Open a terminal and navigate to your bot directory (dev container opens in the right directory).
  3. Enter npm install to install the NodeJs packages.
  4. Start the bot using npm run dev.
  5. Enjoy!

Note: if you're using Ranger Desktop, you might encounter a mount error. Please consult: microsoft/vscode-remote-release#8172 It advises to downgrade Dev Containers to 0.266.1.

How to fork this project internally in Wehkamp

GitHub doesn't allow forks on the same organization which means you can't use the fork button for Wehkamp use. You can easily solve this by forking this manually.

Replace bot-zero-fork with your own repo and/or use https for cloning/remotes instead of ssh.

  1. Create a new repo under wehkamp.
  2. Clone bot-zero. git clone [email protected]:wehkamp/bot-zero.git bot-zero-fork
  3. Cd into fork cd bot-zero-fork
  4. Setup remotes.
    • git remote remove origin
    • git remote add upstream [email protected]:wehkamp/bot-zero.git
    • git remote add origin [email protected]:wehkamp/bot-zero-fork.git
    • git push origin master

You can now pull/push to your forked repo and the original bot-zero repo.

Pulling/updating

If you want to pull updates from the original bot-zero repo upstream you may use the command: git pull upstream master. This will get all commits from bot-zero master in your current branch.

Pushing

You can also push to the original bot-zero project with git push upstream whateverbranch and this will push all your commits to a branch on bot-zero. Be aware though, bot-zero is public and you may leak private info.

Good to know

Dev
Start the bot with npm run dev. It will start a watcher that will inspect your typescript files. Whenever something is changed, the bot is restarted. Add new scripts to the src/scripts directory. Every script have the following:

import { BotZero } from "../common/BotZero"

module.exports = (robot: BotZero) => {
  // your code goes here
}

Docker
If you want to run in Docker, execute the following:

docker build -t bot-zero .
docker run -e HUBOT_SLACK_TOKEN=xoxb-you-token-here -it bot-zero

Or, if you already have a .env, run Docker Compose:

docker-compose up --build --remove-orphans

Tech

We're using the following stack:

  • Node.js
  • TypeScript
  • Hubot
  • Bolt
  • NPM

About

An "empty" Hubot project that can be used to build your own Slack bot. Based on the Slack Bolt API.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published