From 4fa0910fa596e3b5a4521757e1bcee9eb1a7374b Mon Sep 17 00:00:00 2001 From: Vbarinov Date: Sat, 21 Jan 2023 00:15:00 +0400 Subject: [PATCH] initial version --- Dockerfile | 17 +++++++++++++++++ main.go | 35 +++++++++++++++++++++++++++++++++++ tgbot.iml | 10 ++++++++++ 3 files changed, 62 insertions(+) create mode 100644 Dockerfile create mode 100644 main.go create mode 100644 tgbot.iml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..afb38fa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.19.5-buster as builder + +WORKDIR /app + +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go mod init tgbod/m +RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go get +RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o tgbot -ldflags="-w -s" . + +FROM golang:1.19.5-buster + +WORKDIR /app +COPY --from=builder /app/tgbot /usr/bin/ + +ENTRYPOINT ["tgbot"] + +USER 1001 diff --git a/main.go b/main.go new file mode 100644 index 0000000..242f50c --- /dev/null +++ b/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "log" + + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" +) + +func main() { + bot, err := tgbotapi.NewBotAPI("5913395413:AAEcaXZPbsldBW2kFNKy3NwUf5LAyetj_0Y") + if err != nil { + log.Panic(err) + } + + bot.Debug = true + + log.Printf("Authorized on account %s", bot.Self.UserName) + + u := tgbotapi.NewUpdate(0) + u.Timeout = 60 + + updates := bot.GetUpdatesChan(u) + + for update := range updates { + if update.Message != nil { + // If we got a message + log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) + + msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) + msg.ReplyToMessageID = update.Message.MessageID + + bot.Send(msg) + } + } +} diff --git a/tgbot.iml b/tgbot.iml new file mode 100644 index 0000000..db9491b --- /dev/null +++ b/tgbot.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file