Feat(Initial): Initial Go codebase
All checks were successful
Webhook-Everything/Webhook-Everything/pipeline/head This commit looks good
All checks were successful
Webhook-Everything/Webhook-Everything/pipeline/head This commit looks good
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package webhookeverything
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
"git.samuelpua.com/telboon/webhook-everything/backend/internal/telegrampackage"
|
||||
)
|
||||
|
||||
func (env *Env) registerWebhook(shortCode string, text string) (bool, *string) {
|
||||
commandSplitted := telegrampackage.ParseTelegramBotCommand(text)
|
||||
if len(commandSplitted) > 0 && commandSplitted[0] == "/register-webhook" {
|
||||
newWebhookID := genWebhookCode(6)
|
||||
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, newWebhookID)
|
||||
webhookURL := baseURL.String()
|
||||
|
||||
var webhookRoute WebhookRoute
|
||||
webhookRoute.TelegramShortCode = shortCode
|
||||
webhookRoute.WebhookID = newWebhookID
|
||||
env.DB.Create(&webhookRoute)
|
||||
|
||||
responseText := fmt.Sprintf("Your generated webhook URL is: %s", webhookURL)
|
||||
return true, &responseText
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func genWebhookCode(n int) string {
|
||||
var letters = []rune("abcdefghijklmnopqrstuvwxyz1234567890")
|
||||
runeCode := make([]rune, n)
|
||||
for i := range runeCode {
|
||||
runeCode[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
return string(runeCode)
|
||||
}
|
||||
Reference in New Issue
Block a user