From c5c676f98b1b80ee9e160f04579a62855596159b Mon Sep 17 00:00:00 2001 From: shoopea Date: Fri, 3 May 2019 11:22:58 +0800 Subject: [PATCH] test --- bot.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 bot.go diff --git a/bot.go b/bot.go new file mode 100644 index 0000000..b85387d --- /dev/null +++ b/bot.go @@ -0,0 +1,59 @@ +package main + +import ( + "time" + "log" + "flag" + "fmt" + "database/sql" + _ "github.com/go-sql-driver/mysql" + "gopkg.in/gcfg.v1" + tb "gopkg.in/tucnak/telebot.v2" +) + +func StartBot() { + // Registering bot + b, err := tb.NewBot(tb.Settings{ + Token: cfg.Telegram.Token, + URL: cfg.Telegram.URL, + Poller: &tb.LongPoller{Timeout: 10 * time.Second}, + }) + + if err != nil { + log.Fatal(err) + return + } + + b.Handle("/hello", func(m *tb.Message) { + if !m.Private() { + return + } +// fmt.Println("Hello payload :", m.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() +} \ No newline at end of file