Feat(telegram): Added new controller to handle help and show
All checks were successful
Webhook-Everything/Webhook-Everything/pipeline/head This commit looks good

This commit is contained in:
2022-09-10 00:40:10 +08:00
parent a54bdd3f90
commit b3644f05e6
7 changed files with 36 additions and 4 deletions

View File

@@ -1,2 +1,3 @@
.git
_postgres_data
_postgres_data
_docker_mnt

1
.gitignore vendored
View File

@@ -10,6 +10,7 @@
# Dev Postgres
_postgres_data
_docker_mnt
# ---> Go
# Binaries for programs and plugins

View File

@@ -30,6 +30,8 @@ func WebhookEverythingRoutes(db *gorm.DB, telegramEnv *telegrampackage.Env, host
// Telegram handlers
env.TelegramEnv.AddTelegramHandlerFunc(env.registerWebhook)
env.TelegramEnv.AddTelegramHandlerFunc(env.displayHelp)
env.TelegramEnv.AddTelegramHandlerFunc(env.showRoutes)
return r
}

View File

@@ -30,6 +30,34 @@ func (env *Env) registerWebhook(shortCode string, text string) (bool, *string) {
return false, nil
}
func (env *Env) displayHelp(shortCode string, text string) (bool, *string) {
commandSplitted := telegrampackage.ParseTelegramBotCommand(text)
if len(commandSplitted) > 0 && commandSplitted[0] == "/help" {
responseText := "/register -> Register for a chat ID\n/register-webhook -> Register for a web hook\n/show -> Show existing webhooks"
return true, &responseText
}
return false, nil
}
func (env *Env) showRoutes(shortCode string, text string) (bool, *string) {
commandSplitted := telegrampackage.ParseTelegramBotCommand(text)
if len(commandSplitted) > 0 && commandSplitted[0] == "/show" {
var results []WebhookRoute
env.DB.Where(&WebhookRoute{WebhookID: shortCode}).Find(&results)
responseText := "The following webhook URLs were previously registered:"
for _, curr := range results {
baseURL, _ := url.Parse(env.HostURL)
baseURL.Path = path.Join(baseURL.Path, "webhook")
baseURL.Path = path.Join(baseURL.Path, "routes")
baseURL.Path = path.Join(baseURL.Path, curr.WebhookID)
webhookURL := baseURL.String()
responseText += fmt.Sprintf("%s\n", webhookURL)
}
return true, &responseText
}
return false, nil
}
func genWebhookCode(n int) string {
var letters = []rune("abcdefghijklmnopqrstuvwxyz1234567890")
runeCode := make([]rune, n)

View File

@@ -18,7 +18,7 @@ services:
image: postgres
restart: always
volumes:
- "./_postgres_data:/var/lib/postgresql/data"
- "./_docker_mnt/_postgres_data:/var/lib/postgresql/data"
environment:
- "POSTGRES_USER=${DB_USER}"
- "POSTGRES_PASSWORD=${DB_PASS}"

View File

@@ -2,5 +2,5 @@
echo $ATHENA_DEPLOYMENT_SSH_KEY | base64 -d > /tmp/ssh-key
chmod 600 /tmp/ssh-key
rsync -v -e "ssh -o StrictHostKeyChecking=no -i /tmp/ssh-key -p 777" -a --exclude="_postgres_data" --delete . samuel@athena.gaia:~/webhook-everything || true
rsync -v -e "ssh -o StrictHostKeyChecking=no -i /tmp/ssh-key -p 777" -a --exclude="_docker_mnt/_postgres_data" --delete . samuel@athena.gaia:~/webhook-everything || true
ssh -p 777 -o StrictHostKeyChecking=no -i /tmp/ssh-key samuel@athena.gaia "cd /home/samuel/webhook-everything && docker-compose up --build -d"

View File

@@ -1,6 +1,6 @@
docker rm -f dev_postgres
docker run -d \
-v `pwd`/_postgres_data:/var/lib/postgresql/data \
-v `pwd`/_docker_mnt/_postgres_data:/var/lib/postgresql/data \
-e POSTGRES_USER=testuser \
-e POSTGRES_PASSWORD=testpassword \
-e POSTGRES_DB=testdb \