-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from GlueOps/feat/setting-up-axios
Feat/setting up axios
- Loading branch information
Showing
25 changed files
with
1,183 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Publish to GHCR.io | ||
|
||
on: [push] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build_tag_push_to_ghcr: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | ||
|
||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3 | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0 | ||
|
||
- name: Log into registry ${{ env.REGISTRY }} | ||
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=branch,prefix= | ||
type=ref,event=tag,prefix= | ||
type=sha,format=short,prefix= | ||
type=sha,format=long,prefix= | ||
- name: Build and push Docker image | ||
id: build-and-push | ||
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0 | ||
with: | ||
context: . | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
provenance: false | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,117 @@ | ||
# slackbot-developer-workspaces | ||
|
||
This is the source code for a Slack bot. It is coded in Javascript using bolt. | ||
It has three components: bot, command-handler, and server. The bot is set up | ||
to run in socket mode. The server is a heart-beat monitor and runs on port 5000, | ||
while the bolt server listens on port 3000 by default. Read more in | ||
|
||
# Installation | ||
### Dependencies | ||
- Docker installed | ||
- Slack App setup | ||
- Hetzner Account and configured with API Token in the cloud projects | ||
- Tailscale Account and configured with API Token to install, add, remove machines | ||
|
||
### Steps | ||
1. pull down the latest image from ghcr | ||
|
||
2. You can then run the bot `docker run --env-file <path-to-.env-file -d -p 5000:5000 -p 3000:3000 --name slack-bot <ghcr image>` | ||
**If you change the bolt port or the server port, make sure to update that in the docker command** | ||
|
||
3. You can find an example.env file in bot/example.env. Steps to generate all the tokens required and set up the bot are below. | ||
|
||
# Compile | ||
If you would like to change the source code, or compile the slack Bot yourself: | ||
|
||
1. Download the latest Slack Bot release | ||
|
||
2. extract the zip folder. You can make modifications to the source code here. | ||
|
||
3. Compile the bot code | ||
`docker build -t <DOCKER_IMAGE_NAME> .` | ||
|
||
4. You can then run the bot `docker run --env-file <path-to-.env-file -d -p 5000:5000 -p 3000:3000 --name slack-bot <ghcr image>` | ||
**If you change the bolt port or the server port, make sure to update that in the docker command** | ||
|
||
5. You can find an example.env file in bot/example.env. Steps to generate all the tokens required and set up the bot are below. | ||
|
||
## Set up Slack App | ||
1. You will need to create a [slack app](https://api.slack.com/apps) | ||
|
||
2. In the app creation progress, create new app from a manifest: | ||
|
||
```json | ||
{ | ||
"display_information": { | ||
"name": "Dev Bot" | ||
}, | ||
"features": { | ||
"bot_user": { | ||
"display_name": "Dev Bot", | ||
"always_online": true | ||
} | ||
}, | ||
"oauth_config": { | ||
"scopes": { | ||
"bot": [ | ||
"channels:history", | ||
"chat:write", | ||
"groups:history", | ||
"im:history", | ||
"mpim:history", | ||
"users:read.email", | ||
"users:read" | ||
] | ||
} | ||
}, | ||
"settings": { | ||
"event_subscriptions": { | ||
"bot_events": [ | ||
"message.channels", | ||
"message.groups", | ||
"message.im", | ||
"message.mpim" | ||
] | ||
}, | ||
"interactivity": { | ||
"is_enabled": true | ||
}, | ||
"org_deploy_enabled": false, | ||
"socket_mode_enabled": true, | ||
"token_rotation_enabled": false | ||
} | ||
} | ||
``` | ||
|
||
3. Once you have created your Slack App, in the App credentials under Basic information, | ||
you will find your signing secret. | ||
|
||
4. Scroll down to App-Level-Tokens and generate a token with connections:write scope. This will be your app token | ||
|
||
5. In the left bar settings menu, Select Install App. This will generate your bot token for you. | ||
|
||
## Set up Hetzner | ||
1. Navigate to hetzner [cloud](https://console.hetzner.cloud/projects) | ||
|
||
2. Create a project. | ||
|
||
3. Once in the project, select security from the left menu bar options. | ||
|
||
4. Select API tokens and generate an API Token with Read & Write permissions. This will be your hetzner api token. | ||
|
||
## Set up Tailscale | ||
1. Navigate to tailscale [admin console](https://login.tailscale.com/admin/machines) | ||
|
||
2. In the top menu bar, click DNS. This will give you your Tailnet name. | ||
|
||
3. In the top menu bar select Settings. | ||
|
||
4. In the left menu bar select keys. | ||
|
||
5. Generate an auth key: you will need to give it a description, and select Reusable. The key must be rotated and has a max expiration of 90 days, but can be shortened. Leave Ephemeral, and Tags unchecked and generate the key. This will be your tailscale auth key. | ||
|
||
6. Generate an API acess token: you will need to give it a description. The key must be rotated and has a max expiration of 90 days, but can be shortened. This will be your Tailscale api token. | ||
|
||
# Adding Bot commands | ||
The bot is set up with a command handler to process text commands with a prefix of ! i.e. !vm. It currently does not support slash commands. | ||
The bot has some built in example commands found in bot/src/commands. To register a new command, create a file command.js in either the bot/src/commands, or command-handler/src/commands with `myCommand.js` being the command you want to register. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
SIGNING_SECRET=<SLACK Bot signing Secret> | ||
BOT_TOKEN=<Slack Bot Token> | ||
APP_TOKEN=<Slack Bot App Token> | ||
BOLT_PORT=3000 | ||
SERVER_PORT=5000 | ||
HETZNER_API_TOKEN=<Hetzner API Token> | ||
TAILSCALE_API_TOKEN=<Tailscale API Token> | ||
TAILSCALE_AUTH_KEY=<Tailscale Auth Key> | ||
TAILSCALE_TAILNET_NAME=<Tailscale Tailnet Name> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logger from "command-handler/src/util/logger.js"; | ||
|
||
const log = logger(); | ||
|
||
export default { | ||
description: 'creates a button', | ||
|
||
button: ({ handler, body, response }) => { | ||
log.info("Clicked the button", body.user) | ||
response({ | ||
text: `<@${body.user.id}> clicked the Button` | ||
}) | ||
}, | ||
|
||
run: ({ response, message }) => { | ||
|
||
response({ | ||
blocks: [ | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": `Hey there <@${message.user}>!` | ||
}, | ||
"accessory": { | ||
"type": "button", | ||
"text": { | ||
"type": "plain_text", | ||
"text": "Click Me" | ||
}, | ||
"action_id": "button_click" | ||
} | ||
} | ||
], | ||
text: `Hey there <@${message.user}>!` | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ export default { | |
run: ({ response }) => { | ||
|
||
response({ | ||
content: `pong` | ||
text: `pong` | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.