- Add thumbnail preview with metadata (title, uploader, duration) before download - Auto-detect audio-only sites (Spotify, SoundCloud, etc.) and skip type selection - Add /download command for feature parity with UI button - Fix yt-dlp defer bug: StatusFailed was overwritten to StatusCompleted - Fix handleURLInput using editText with msgID=0 (now uses sendWithKB) - Fix filename detection: use job ID prefix for reliable file finding - Fix double answerCb between handleBackStep and handleDownloadPrompt - Fix runDownload unused msgID parameter - Fix context for download goroutine (use context.Background) - Remove unused startWebhook h parameter - Remove dead buildToggleKeyboard function - Add formatBytes, formatDuration, formatLabelForDisplay tests - Add IsAudioOnlyContent, MediaType.String tests - Add repo integration tests (users, preferences, quotas, history, delete) - Add cmd/bot tests (parseAllowedUsers, env helpers) - Add edge case tests for progress parser - Add zero/negative safety guard in formatDuration - Add .gitea, TODO.md, opencode.json to gitignore
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"net/http"
|
|
"os"
|
|
|
|
tgbot "github.com/go-telegram/bot"
|
|
)
|
|
|
|
func startWebhook(ctx context.Context, b *tgbot.Bot, webhookURL string) {
|
|
if _, err := b.DeleteWebhook(ctx, &tgbot.DeleteWebhookParams{}); err != nil {
|
|
slog.Warn("failed to delete webhook", "error", err)
|
|
}
|
|
|
|
if _, err := b.SetWebhook(ctx, &tgbot.SetWebhookParams{URL: webhookURL}); err != nil {
|
|
slog.Error("set webhook", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
listenAddr := getEnvDefault("BOT_LISTEN", ":8080")
|
|
tlsCert := os.Getenv("BOT_TLS_CERT")
|
|
tlsKey := os.Getenv("BOT_TLS_KEY")
|
|
|
|
if tlsCert != "" && tlsKey != "" {
|
|
slog.Info("starting HTTPS webhook", "addr", listenAddr)
|
|
go func() {
|
|
if err := http.ListenAndServeTLS(listenAddr, tlsCert, tlsKey, b.WebhookHandler()); err != nil {
|
|
slog.Error("HTTPS server", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
}()
|
|
} else {
|
|
slog.Info("starting HTTP webhook (TLS by reverse proxy)", "addr", listenAddr)
|
|
go func() {
|
|
if err := http.ListenAndServe(listenAddr, b.WebhookHandler()); err != nil {
|
|
slog.Error("HTTP server", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
}()
|
|
}
|
|
|
|
slog.Info("webhook registered", "url", webhookURL)
|
|
b.StartWebhook(ctx)
|
|
}
|