Phase 1 MVP — echo bot factory
All checks were successful
Docker Build / build-and-push-image (push) Successful in 1m8s

This commit is contained in:
2026-05-09 12:23:59 +02:00
commit ee832de089
28 changed files with 1376 additions and 0 deletions

74
setwebhook.go Normal file
View File

@@ -0,0 +1,74 @@
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"strings"
"time"
)
func runSetWebhook() {
slug := flag.String("slug", "", "bot slug (must match a key in bots.yaml)")
baseURL := flag.String("base-url", envOr("BASE_URL", ""), "public base URL of the gateway, e.g. https://tg.arcodange.fr")
dropPending := flag.Bool("drop-pending", true, "drop pending updates")
flag.Parse()
if *slug == "" {
log.Fatal("--slug required")
}
if *baseURL == "" {
log.Fatal("--base-url required (or set BASE_URL)")
}
envSlug := strings.ToUpper(strings.ReplaceAll(*slug, "-", "_"))
token := os.Getenv("BOT_" + envSlug + "_TOKEN")
secret := os.Getenv("BOT_" + envSlug + "_SECRET")
if token == "" || secret == "" {
log.Fatalf("BOT_%s_TOKEN and BOT_%s_SECRET must be set in env", envSlug, envSlug)
}
hookURL := strings.TrimSuffix(*baseURL, "/") + "/bot/" + *slug
tg := NewTelegramClient()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := tg.SetWebhook(ctx, token, SetWebhookParams{
URL: hookURL,
SecretToken: secret,
DropPendingUpdates: *dropPending,
AllowedUpdates: []string{"message", "edited_message", "callback_query"},
MaxConnections: 20,
}); err != nil {
log.Fatalf("setWebhook: %v", err)
}
info, err := tg.GetWebhookInfo(ctx, token)
if err != nil {
log.Fatalf("getWebhookInfo: %v", err)
}
fmt.Printf("webhook set: url=%s pending=%d last_err=%q\n", info.URL, info.PendingUpdateCount, info.LastErrorMessage)
}
func runDeleteWebhook() {
slug := flag.String("slug", "", "bot slug")
flag.Parse()
if *slug == "" {
log.Fatal("--slug required")
}
envSlug := strings.ToUpper(strings.ReplaceAll(*slug, "-", "_"))
token := os.Getenv("BOT_" + envSlug + "_TOKEN")
if token == "" {
log.Fatalf("BOT_%s_TOKEN must be set in env", envSlug)
}
tg := NewTelegramClient()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := tg.DeleteWebhook(ctx, token); err != nil {
log.Fatalf("deleteWebhook: %v", err)
}
fmt.Println("webhook deleted")
}