-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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.UpdatesViaLongPulling(nil) | ||
|
||
// Stop reviving updates from updates channel | ||
defer bot.StopLongPulling() | ||
|
||
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.StopLongPulling() | ||
} | ||
|
||
return update | ||
}) | ||
|
||
// Log update IDs | ||
for update := range processedUpdates { | ||
fmt.Println("Update ID:", update.UpdateID) | ||
} | ||
|
||
fmt.Println("Bye") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters