This commit is contained in:
shoopea 2019-05-03 11:23:08 +08:00
parent c5c676f98b
commit 5a30a30ae2

46
main.go
View File

@ -85,49 +85,13 @@ func main() {
initDB() initDB()
} }
go StartBot()
// Registering bot fmt.Println("Started !")
b, err := tb.NewBot(tb.Settings{
Token: cfg.Telegram.Token,
URL: cfg.Telegram.URL,
Poller: &tb.LongPoller{Timeout: 10 * time.Second},
})
if err != nil { // Main loop
log.Fatal(err) for {
return time.Sleep(1 * time.Second)
} }
b.Handle("/hello", func(m *tb.Message) {
if !m.Private() {
return
}
// fmt.Println("Hello payload :", m.Payload) // <PAYLOAD>
PrintText(m)
b.Send(m.Sender, "hello world")
})
b.Handle(tb.OnPhoto, func(m *tb.Message) {
fmt.Println("OnPhoto :", m.Text)
// photos only
})
b.Handle(tb.OnChannelPost, func (m *tb.Message) {
fmt.Println("OnChannelPost :", m.Text)
PrintText(m)
// channel posts only
})
b.Handle(tb.OnQuery, func (q *tb.Query) {
fmt.Println("Query ?")
// incoming inline queries
})
b.Handle(tb.OnText, func(m *tb.Message) {
PrintText(m)
// all the text messages that weren't
// captured by existing handlers
})
b.Start()
} }