Feat(webhook-type): Initial webhook type support
This commit is contained in:
@@ -9,9 +9,9 @@ import (
|
||||
"git.samuelpua.com/telboon/webhook-everything/backend/internal/telegrampackage"
|
||||
)
|
||||
|
||||
func (env *Env) registerWebhook(shortCode string, text string) (bool, *string) {
|
||||
func (env *Env) registerWebhookRaw(shortCode string, text string) (bool, *string) {
|
||||
commandSplitted := telegrampackage.ParseTelegramBotCommand(text)
|
||||
if len(commandSplitted) > 0 && commandSplitted[0] == "/register-webhook" {
|
||||
if len(commandSplitted) > 0 && commandSplitted[0] == "/register_webhook_raw" {
|
||||
newWebhookID := genWebhookCode(6)
|
||||
baseURL, _ := url.Parse(env.HostURL)
|
||||
baseURL.Path = path.Join(baseURL.Path, "webhook")
|
||||
@@ -22,6 +22,29 @@ func (env *Env) registerWebhook(shortCode string, text string) (bool, *string) {
|
||||
var webhookRoute WebhookRoute
|
||||
webhookRoute.TelegramShortCode = shortCode
|
||||
webhookRoute.WebhookID = newWebhookID
|
||||
webhookRoute.WebhookType = "raw"
|
||||
env.DB.Create(&webhookRoute)
|
||||
|
||||
responseText := fmt.Sprintf("Your generated webhook URL is: %s", webhookURL)
|
||||
return true, &responseText
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (env *Env) registerWebhookBody(shortCode string, text string) (bool, *string) {
|
||||
commandSplitted := telegrampackage.ParseTelegramBotCommand(text)
|
||||
if len(commandSplitted) > 0 && commandSplitted[0] == "/register_webhook_body" {
|
||||
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
|
||||
webhookRoute.WebhookType = "body"
|
||||
env.DB.Create(&webhookRoute)
|
||||
|
||||
responseText := fmt.Sprintf("Your generated webhook URL is: %s", webhookURL)
|
||||
@@ -33,7 +56,7 @@ func (env *Env) registerWebhook(shortCode string, text string) (bool, *string) {
|
||||
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"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user