Skip to content

Commit

Permalink
Publish code to Github.
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavpandeyvpz committed May 13, 2024
0 parents commit 49a1077
Show file tree
Hide file tree
Showing 26 changed files with 1,400 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.env
/*.sqlite
/config.yml
/ngrok.yml
/slack.yml
/consulate
/tmp
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NGROK_AUTHTOKEN=
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

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

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

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

# Go workspace file
go.work

# app specific files
/.env
/*.sqlite
/config.yml
/ngrok.yml
/slack.yml
/consulate
/tmp
82 changes: 82 additions & 0 deletions Consulate.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"info": {
"_postman_id": "1bfa868e-565d-45f6-8b67-ebf27624ead5",
"name": "Consulate",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "16000625"
},
"item": [
{
"name": "Submit enquiry",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "name",
"value": "John F. Doe",
"type": "text"
},
{
"key": "email",
"value": "john.f@doefamily.com",
"type": "text"
},
{
"key": "",
"value": "+919876543210",
"type": "text"
},
{
"key": "message",
"value": "I want to know about that ugly software on your website.",
"type": "text",
"disabled": true
}
]
},
"url": {
"raw": "{{BaseUrl}}/enquiries",
"host": [
"{{BaseUrl}}"
],
"path": [
"enquiries"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
}
],
"variable": [
{
"key": "BaseUrl",
"value": "http://127.0.0.1:8080",
"type": "string"
}
]
}
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.21

RUN curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN go build -o consulate

EXPOSE 8080

HEALTHCHECK --interval=1m --timeout=5s \
CMD curl -f http://127.0.0.1:8080/ping || exit 1

CMD ["./consulate"]
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<h1 align="center">consulate</h1>

[![Screenshot](https://raw.githubusercontent.com/vaibhavpandeyvpz/consulate/main/screenshot.png)](https://raw.githubusercontent.com/vaibhavpandeyvpz/consulate/main/screenshot.png)

<p align="center">
Headless enquiry management system in <a href="https://go.dev/">Go</a> built on <a href="https://slack.com/intl/en-in/">Slack</a> and <a href="https://exotel.com/">Exotel</a> for inbound marketing teams.
Record collected enquiries, place and record outbound calls, store follow-ups etc.
</p>

## Development

Make sure you have [Docker](https://www.docker.com/) installed on your workstation.
For the IDE, I highly recommend using [GoLand](https://www.jetbrains.com/go/) i.e., my go to choice for [Go](https://go.dev) development.

Firstly, download or clone the project using [Git](https://git-scm.com/) and then run following commands in project folder:

```shell
# create .env file in project
cp .env.dist .env

# update NGROK_AUTHTOKEN in .env

# create app config file
cp config.dist.yml config.yml

# update values in config.yml

# create ngrok config file
cp ngrok.dist.yml ngrok.yml

# update ngrok domain in ngrok.yml

# create Slack app manifest
cp slack.dist.yml slack.yml

# update ngrok domain in slack.yml

# start all services
docker compose up -d
```

Go to [api.slack.com](https://api.slack.com/), create a new app using provided manifest and install it on a [Slack](https://slack.com/intl/en-in/) workspace.
Once done, get the **signing secret** as well as **bot access token** to update in `.env` file and restart the services using below command:

```shell
# stop running services
docker compose down

# restart services
docker compose up -d
```

## Deployment

For deployment, using [Docker](https://www.docker.com/) is the easiest way to go.
There's a bundled `Dockerfile` that builds and exposes the server on port `8080` (can be configured using `PORT` environment variable).

To build the container for deployment, use below command:

```shell
docker build -t consulate .
```
21 changes: 21 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"consulate/routes"
"github.com/gin-gonic/gin"
"net/http"
)

func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
r.POST("/enquiries", routes.StoreEnquiry)
r.POST("/exotel/callback", routes.ExotelCallback)
r.POST("/slack/interaction", routes.SlackInteraction)
r.POST("/slack/options", routes.SlackOptions)
r.Run()
}
20 changes: 20 additions & 0 deletions config.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
database:
path: enquiries.sqlite

exotel:
domain: api.exotel.com
account_sid:
api_key:
api_token:
called_id:
status_callback: "https://<ngrok_domain>/exotel/callback"

recipients:
- USER_ID_1
- USER_ID_2

slack:
bot_token:
channels:
enquiries:
signing_secret:
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3"

services:
app:
build: .
command: sh -c "$(go env GOPATH)/bin/air"
env_file:
- .env
ports:
- "8080:8080"
volumes:
- .:/app

ngrok:
command: start --all --config /etc/ngrok.yml
env_file:
- .env
image: ngrok/ngrok
ports:
- "4040:4040"
restart: unless-stopped
volumes:
- ./ngrok.yml:/etc/ngrok.yml
56 changes: 56 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module consulate

go 1.21

require (
github.com/ggwhite/go-masker v1.1.0
github.com/gin-gonic/gin v1.9.1
github.com/gookit/config/v2 v2.2.5
github.com/samber/lo v1.39.0
github.com/slack-go/slack v0.12.5
gorm.io/driver/sqlite v1.5.5
gorm.io/gorm v1.25.10
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-yaml v1.11.2 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/gookit/goutil v0.6.15 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 49a1077

Please sign in to comment.