summaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorMurilo Ijanc <[email protected]>2026-07-26 15:18:21 -0300
committerMurilo Ijanc <[email protected]>2026-07-26 15:18:21 -0300
commit3ca1d2c4370e8e79aba3940d5c8fe115960b75a8 (patch)
treeaa964675c588b80e4f81182d34130ba2d7d984e1 /main.go
downloadtelegram-3ca1d2c4370e8e79aba3940d5c8fe115960b75a8.tar.gz
Initial importv0.1.0
Diffstat (limited to 'main.go')
-rw-r--r--main.go50
1 files changed, 50 insertions, 0 deletions
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 <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)
+}