-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
main.go
53 lines (39 loc) · 1004 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
49
50
51
52
53
package main
import (
"fmt"
"os"
"sync/atomic"
"github.com/mymmrac/telego"
tu "github.com/mymmrac/telego/telegoutil"
)
func main() {
botToken := os.Getenv("TOKEN")
// Create Bot
bot, err := telego.NewBot(botToken)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Get updates channel
updates, _ := bot.UpdatesViaLongPolling(nil)
// Stop reviving updates from update channel
defer bot.StopLongPolling()
fmt.Println("Listening for updates...")
count := int64(0)
// Process updates for something (here to count them)
processedUpdates := tu.UpdateProcessor(updates, 100, func(update telego.Update) telego.Update {
atomic.AddInt64(&count, 1)
currentCount := atomic.LoadInt64(&count)
fmt.Println("Update count:", currentCount)
// Stop bot when processed 3 updates
if currentCount >= 3 {
bot.StopLongPolling()
}
return update
})
// Log update IDs
for update := range processedUpdates {
fmt.Println("Update ID:", update.UpdateID)
}
fmt.Println("Bye")
}