diff --git a/README.md b/README.md index daf9920..100b5cc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -# chirpnest - +ChirpNestBot \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..48ccaaf --- /dev/null +++ b/main.go @@ -0,0 +1,62 @@ +package main + +import ( + "time" + "log" + "fmt" + + tb "gopkg.in/tucnak/telebot.v2" +) + +func PrintText(m *tb.Message) { + fmt.Printf("[%d] %s(%d) | %s(%d) : %s\n", m.ID, m.Chat.Title, m.Chat.ID, m.Sender.Username, m.Sender.ID, m.Text) + return +} + +func main() { + b, err := tb.NewBot(tb.Settings{ + Token: "725809138:AAGp5hGQ7KQHxWtXZH93JUAxaHlJKtbXjlE", + // You can also set custom API URL. If field is empty it equals to "https://api.telegram.org" + // URL: "http://195.129.111.17:8012", + URL: "https://api.telegram.org", + 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