From 3ca1d2c4370e8e79aba3940d5c8fe115960b75a8 Mon Sep 17 00:00:00 2001 From: Murilo Ijanc Date: Sun, 26 Jul 2026 15:18:21 -0300 Subject: Initial import --- main.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..36aecab --- /dev/null +++ b/main.go @@ -0,0 +1,50 @@ +// Command cepis-telegram is the official Telegram bot for https://cep.is. +// +// It answers a bare CEP in a private chat, "/cep " in groups and channels, +// and inline queries anywhere. Updates arrive by long polling, so the process +// needs no inbound port, no public hostname and no webhook secret. +// +// Configuration is environment-only; see the config package. +package main + +import ( + "context" + "errors" + "log/slog" + "os" + "os/signal" + "syscall" + + "cep.is/telegrambot/internal/app" + "cep.is/telegrambot/internal/config" +) + +func main() { + if err := run(); err != nil { + slog.New(slog.NewJSONHandler(os.Stdout, nil)).Error("fatal", slog.String("error", err.Error())) + os.Exit(1) + } +} + +func run() error { + cfg, err := config.Load() + if err != nil { + if errors.Is(err, config.ErrMissingToken) { + return errors.New(config.EnvToken + " is required: create a bot with @BotFather and pass its token in the environment") + } + return err + } + + logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: cfg.LogLevel})) + slog.SetDefault(logger) + logger.Info("configuration loaded", slog.Any("config", cfg)) + + ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + defer stop() + + application, err := app.New(ctx, cfg, logger) + if err != nil { + return err + } + return application.Run(ctx) +} -- cgit v1.3