From d835e47024be19d1bd5326bad122675c675c61c0 Mon Sep 17 00:00:00 2001 From: Terekhin Alexandr Date: Sun, 28 Mar 2021 15:20:31 +0300 Subject: [PATCH] App from telebot Signed-off-by: Terekhin Alexandr --- go.mod | 3 +++ main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 go.mod create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..626697a --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module bearns.me/didinst/tg-bot-example + +go 1.15 diff --git a/main.go b/main.go new file mode 100644 index 0000000..2b7fb90 --- /dev/null +++ b/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "log" + "time" + + tb "gopkg.in/tucnak/telebot.v2" +) + +func main() { + var ( + port = os.Getenv("PORT") + publicURL = os.Getenv("PUBLIC_URL") // you must add it to your config vars + token = os.Getenv("TOKEN") // you must add it to your config vars + ) + + webhook := &tb.Webhook{ + Listen: ":" + port, + Endpoint: &tb.WebhookEndpoint{PublicURL: publicURL}, + } + + pref := tb.Settings{ + Token: token, + Poller: webhook, + } + + b, err := tb.NewBot(pref) + if err != nil { + log.Fatal(err) + } + + if err != nil { + log.Fatal(err) + return + } + + b.Handle("/hello", func(m *tb.Message) { + b.Send(m.Sender, "Hello World!") + }) + + b.Start() +} \ No newline at end of file