-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (35 loc) · 800 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
46
47
48
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"tonycat/config"
"github.com/gin-gonic/gin"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
func main() {
log.SetFlags(log.Lshortfile | log.LstdFlags)
r := gin.New()
r.Use(gin.Logger())
r.Use(gin.Recovery())
bot, err := tgbotapi.NewBotAPI(config.BOT_TOKEN)
if err != nil {
log.Panic(err)
}
if gin.Mode() == "debug" {
bot.Debug = true
}
catBot := &CatBot{Api: bot}
r.POST("bot/webhook", func(c *gin.Context) {
body, _ := ioutil.ReadAll(c.Request.Body)
update := tgbotapi.Update{}
json.Unmarshal(body, &update)
log.Printf("chat content: %v", update.Message)
if update.Message != nil {
catBot.Chat(update.Message)
}
c.String(200, "ok")
})
fmt.Printf("%s", r.Run(":1300"))
}