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.
Blog: https://medium.com/wehkamp-techblog/jump-starting-slack-bot-projects-bot-zero-991b9654585e
In this secion we will create the Slack app and add the
details to your .env
file.
- Goto https://api.slack.com/apps?new_app=1
- Click From an app manifest
- Select your Workspace and click Next
- 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
- Click Create
- Click Install to Workspace
- Click Allow
- In the Settings > Basic Information screen, scroll down to App-Level Tokens and click Generate Token and Scopes
- Enter a Token Name: bot-zero
- Click Add scope
- Select connections:write
- Click the Generate button
- Copy the
.example.env
in the root of your project to.env
- Copy the Token and paste it in your
.env
file atHUBOT_SLACK_APP_TOKEN
- Click the Done button
- Goto Settings > Install App
- Copy
Bot User OAuth Token
and paste it in your.env
file atHUBOT_SLACK_BOT_TOKEN
This project supports dev containers, so you don't have to install nodejs to your environment.
- Make sure your
.env
file has the right tokens. - Open a terminal and navigate to your bot directory (dev container opens in the right directory).
- Enter
npm install
to install the NodeJs packages. - Start the bot using
npm run dev
. - 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
.
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.
- Create a new repo under wehkamp.
- Clone bot-zero.
git clone [email protected]:wehkamp/bot-zero.git bot-zero-fork
- Cd into fork
cd bot-zero-fork
- 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.
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.
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.
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
We're using the following stack:
- Node.js
- TypeScript
- Hubot
- Bolt
- NPM