-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (35 loc) · 875 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"log"
"net/http"
"os"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/joho/godotenv"
)
func main() {
godotenv.Load()
bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_APITOKEN"))
if err != nil {
panic(err)
}
wh, _ := tgbotapi.NewWebhook(os.Getenv("SERVERLESS_CONTAINER_URL"))
_, err = bot.Request(wh)
if err != nil {
log.Fatal(err)
}
info, err := bot.GetWebhookInfo()
if err != nil {
log.Fatal(err)
}
if info.LastErrorDate != 0 {
log.Printf("Telegram callback failed: %s", info.LastErrorMessage)
}
updates := bot.ListenForWebhook("/")
go http.ListenAndServe(":"+os.Getenv("PORT"), nil)
for update := range updates {
log.Printf("%+v\n", update)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, fmt.Sprintf("Hello, %s!\n", update.Message.Chat.FirstName))
bot.Send(msg)
}
}