Feat(telegram): Added new controller to handle help and show
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user