Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

chore: added Slack command #1

Merged
merged 39 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e1fcde7
chore: added Slack command
karl-cardenas-coding Apr 1, 2023
663a31b
chore: added Slack handler
karl-cardenas-coding Apr 1, 2023
5a70e01
chore: added logic for multiple commnads and cache
karl-cardenas-coding Apr 2, 2023
403e0c0
chore: added logic for multiple commnads and cache
karl-cardenas-coding Apr 2, 2023
2e4501f
chore: updated redis logic
karl-cardenas-coding Apr 2, 2023
039a260
chore: added conversationId request logic
karl-cardenas-coding Apr 2, 2023
da2c91f
chore: handled 3 min req
karl-cardenas-coding Apr 2, 2023
172887b
chore: added more logic related to mendable
karl-cardenas-coding Apr 7, 2023
6488283
chore: updated Mendable API query
karl-cardenas-coding Apr 8, 2023
f1d0026
chore: logic cleanup
karl-cardenas-coding Apr 8, 2023
7e80982
fix: fixed handling logic related to question string
karl-cardenas-coding Apr 8, 2023
ee89b18
chore: seperated the slackcmds into their own package
karl-cardenas-coding Apr 9, 2023
50a9ee8
chore: added retry logic
karl-cardenas-coding Apr 9, 2023
1bd1980
chore: more error handling
karl-cardenas-coding Apr 9, 2023
f4731ec
tests: added test cases
karl-cardenas-coding Apr 10, 2023
8902e37
chore: added more test cases
karl-cardenas-coding Apr 10, 2023
e659875
test: added test case and fixed no results logic
karl-cardenas-coding Apr 10, 2023
a24c154
test: added test case and fixed no results logic
karl-cardenas-coding Apr 10, 2023
cfd93d6
test: added test case and fixed no results logic
karl-cardenas-coding Apr 10, 2023
42e39d2
fix: added ratings buttons
karl-cardenas-coding Apr 11, 2023
bceee64
fix: added actions handler
karl-cardenas-coding Apr 12, 2023
85558fa
chore: added header for ratings message
karl-cardenas-coding Apr 14, 2023
d676d45
chore: added header for ratings message
karl-cardenas-coding Apr 14, 2023
19051a1
chore: fixed duplicate 200 reply
karl-cardenas-coding Apr 14, 2023
eec2825
chore: end-end flow working
karl-cardenas-coding Apr 14, 2023
f47f773
docs: added more content to the README
karl-cardenas-coding Apr 14, 2023
b93ac1a
ci: added PR test workflow
karl-cardenas-coding Apr 14, 2023
6acb205
ci: added PR test workflow
karl-cardenas-coding Apr 14, 2023
d42b84d
chore: fixed ioutil
karl-cardenas-coding Apr 14, 2023
976a43f
ci: added missing GIthub secrets
karl-cardenas-coding Apr 14, 2023
094391f
ci: added missing GIthub secrets
karl-cardenas-coding Apr 14, 2023
16e3c24
ci: added missing GIthub secrets
karl-cardenas-coding Apr 14, 2023
96d32bb
chore: updated logic and added Terraform
karl-cardenas-coding Apr 15, 2023
b5f3c6f
tests: added test for cache
karl-cardenas-coding Apr 15, 2023
c07664f
tests: added test for cache
karl-cardenas-coding Apr 15, 2023
03c8ef8
tests: added test cases
karl-cardenas-coding Apr 15, 2023
f03c087
chore: added redis tls env variable
karl-cardenas-coding Apr 15, 2023
0ba39b1
chore: fixed Dockerfile issue
karl-cardenas-coding Apr 17, 2023
1c649a2
chore: added terraform deployment
karl-cardenas-coding Apr 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.csv
spectromate
.DS_STORE
node_modules/
static/
.github/
node_modules/
package*.json
.releaserc.yml
test/
*.csv
.husky/
CHANGELOG
README.md
data/
terraform/
docs/
8 changes: 8 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Describe the Change

This PR .....

## Review Changes


🎫 [Jira Ticket]()
36 changes: 36 additions & 0 deletions .github/workflows/gitleaks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: GitLeaks
on: [pull_request]

concurrency:
group: gitleaks-${{ github.ref }}
cancel-in-progress: true

jobs:
gitleaks-scan:
runs-on: ubuntu-latest
container:
image: gcr.io/spectro-dev-public/bulwark/gitleaks:latest
env:
REPO: ${{ github.event.repository.name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_CONFIG: config.toml
steps:

- name: run-bulwark-gitleaks-scan
shell: sh
env:
BRANCH: ${{ github.head_ref || github.ref_name }}
run: /workspace/bulwark -name CodeSASTGitLeaks -target $REPO -tags "branch:$BRANCH,options:--log-opts origin..HEAD"

- name: check-result
shell: sh
run: |
resultPath=./$REPO/gitleaks.json
cat $resultPath | grep -v \"Match\"\: | grep -v \"Secret\"\:
total_failed_tests=`cat $resultPath | grep \"Fingerprint\"\: | wc -l`
if [ "$total_failed_tests" -gt 0 ]; then
echo "GitLeaks validation check failed with above findings..."
exit 1
else
echo "GitLeaks validation check passed"
fi
129 changes: 129 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: Test & Validate

on:
pull_request:
types: ['synchronize', 'opened', 'reopened', 'ready_for_review']
branches:
- main

env:
GITHUB_TOKEN: ${{ github.token }}
MENDABLE_API_KEY: ${{secrets.MENDABLE_API_KEY}}
SLACK_SIGNING_SECRET: ${{secrets.SLACK_SIGNING_SECRET}}


concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true

jobs:
run-ci:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
if: ${{ !github.event.pull_request.draft }}
steps:
# If the condition above is not met, aka, the PR is not in draft status, then this step is skipped.
# Because this step is part of the critical path, omission of this step will result in remaining CI steps not gettinge executed.
# As of 8/8/2022 there is now way to enforce this beahvior in GitHub Actions CI.
- run: exit 0


linting:
needs: [run-ci]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: actions/setup-go@v4
with:
go-version: '1.20'
check-latest: true

- name: Lint Internal Package
uses: golangci/golangci-lint-action@v3
with:
args: --verbose --timeout 5m

test:
name: Test
needs: [run-ci,linting]
runs-on: ubuntu-latest
steps:

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
check-latest: true
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Go Tests
run: |
go test -race ./...

compile:
name: Compile validation
needs: [run-ci,linting]
runs-on: ubuntu-latest
steps:

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
check-latest: true
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: -v

- name: build
run: |
go build -race -ldflags="-X 'spectrocloud.com/spectromate/cmd.VersionString=1.0.0'" -o=spectromate -v

Docker:
needs: [run-ci,linting,test,compile]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: actions/setup-go@v4
with:
go-version: '1.20'
check-latest: true

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2


- name: Login to GHCR
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v4.0.0
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ github.repository }}:dev
build-args: |
VERSION=1.0.0
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*.so
*.dylib

# Environment variables
.env

# Test binary, built with `go test -c`
*.test

Expand All @@ -13,3 +16,14 @@

# Dependency directories (remove the comment below to include it)
# vendor/

data/
.DS_STORE
node_modules/
.terraform/
*.tfstate
*.tfstate.*.backup
*.tfstate.backup
spectromate
backend.tf
redis/
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.20.3-alpine3.17 as builder

LABEL org.opencontainers.image.source="http://spectrocloud.com/spectromate"
LABEL org.opencontainers.image.description "An API server with features to support Slack bots integration."

ARG VERSION

ADD ./ /source
RUN cd /source && \
adduser -H -u 1002 -D appuser appuser && \
go build -ldflags="-X 'spectrocloud.com/spectromate/cmd.VersionString=${VERSION}'" -o spectromate -v

FROM alpine:latest

COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder --chown=appuser:appuser /source/spectromate /usr/bin/

RUN apk -U upgrade && apk add bash jq git --no-cache && mkdir /packs && chown -R appuser:appuser /packs && \
mkdir -p /var/log/spectromate && chown -R appuser:appuser /var/log/spectromate
USER appuser

CMD ["/usr/bin/spectromate", ">>", "/var/log/spectromate.log", "2>&1"]
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
start:
@echo "Starting the application and ngrok..."
@docker compose up --detach
@ngrok http 3000 --log-level=debug > /dev/null & sleep 2
@echo "Ngrok URL: $$(curl -s localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url')"


stop:
@echo "Stopping the application and ngrok"
docker compose down
pkill ngrok

server:
@echo "Starting the server..."
go run main.go


make init:
@echo "Installing dependencies..."
go mod download
go install github.com/golang/mock/mockgen@v1.6.0
~/go/bin/mockgen -source=internal/cache.go -destination=mock/mock_cache.go -package=mock

75 changes: 73 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,73 @@
# docs-slack-bot
The home for the Spectro Cloud Slack Bot
# SpectroMate


<p align="center">The home of SpectroMate :robot: </p>

<p align="center">
<img src="/static/images/mascot.png" alt="drawing" width="250"/>
</p>


## Overview 👩‍🚀 🧑‍🚀 🧑🏿‍🚀

SpectroMate is an API server with extended functionality designed for Slack integration in the form of a bot. You can use SpectroMate to handle [slash commands](https://api.slack.com/interactivity/slash-commands), and [message actions](https://api.slack.com/reference/interaction-payloads). You can also use SpectroMate to handle non-slack-related events by creating API endpoints for other purposes.

SpectroMate is designed for deployment in [Palette](https://console.spectrocloud.com) using the Palette Dev Engine (PDE). Using simplifies the management and deployment of SpectroMate.

---

## Getting Started 🚀

To get started with Spectromate follow the steps outlined in the [Getting Started](./docs/getting-started.md) guide.

---

## API Endpoints 🕹️

The following endpoints are available.

| Description | Endpoint |
| ----------------------------------------------------------|-------------------|
| Used for health checks by external resources. | `/health` |
| A slack endpoint that can be used to handle slash commands.| `/slack` |
| A slack endpoint for handling slack message actions. | `/slack/actions` |


## Slack Commands 🛠️

The following Slack commands are available.

| Description | Command |
| ----------------------------------------------------------|-------------------|
| Displays information to the user for how to use SpectroMate. Invalid commands return the help response. | `/help` |
| Used to query the Mendable and ask documentation questions to a trained model.| `/ask` |
| Same as the `/ask` but responses are only visible to the user versus the entire channel. | `/pask` |


## Slack Actions 🪡

Spectromate supports the following actions.

| Description | Action |
| ----------------------------------------------------------|-------------------|
| Handles the possitive feedback button and submits the feedback to Mendable. | `ask_model_positive_feedback` |
| Handles the negavtive feedback button and submits the feedback to Mendable.| `ask_model_negative_feedback` |


## Architecture

The following is an architectural overview of SpectroMate.

![An architecture diagram with all the components that support SpectroMate](./static/images/infrastructure-architecture.png)


## Supported Features and Limitations

|Action| Supported | Notes |
|---|---|---|
| Slash command| ✅ | Supported through the `/slack` endpoint.|
| Message buttons | ✅| Supported through the `/slack/actions` endpoint.|
| Mentions | ❌ | Currently unavailable. |
| Health checks | ✅ | Supported through the `/health` endpoint.|
| Verify Slack signature| ✅ | Verification of Slack signature is applied to all Slack endpoints.|
| Metrics | ❌ | Currently unavailable. |
18 changes: 18 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.8'
services:
redis:
image: redis:7.0.5-alpine3.17
ports:
- "6379:6379"
command: redis-server --bind 0.0.0.0
volumes:
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf
- ./data:/data
restart: always
redis-cli:
image: redis:7.0.5-alpine3.17
depends_on:
- redis
entrypoint: redis-cli
tty: true
restart: always
Empty file added docs/getting-started.md
Empty file.
Loading