1
0
Fork 0

Added NewUpdatesChannel helper

This commit is contained in:
Maxim Lebedev 2017-10-06 13:47:35 +05:00
parent 8b4b287299
commit 4539b38146
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
1 changed files with 38 additions and 0 deletions

View File

@ -1,5 +1,10 @@
package telegram
import (
"log"
"time"
)
func NewReplyKeyboard(rows ...[]KeyboardButton) *ReplyKeyboardMarkup {
var keyboard [][]KeyboardButton
keyboard = append(keyboard, rows...)
@ -59,3 +64,36 @@ func NewInlineKeyboardButtonGame(text string) *InlineKeyboardButton {
func NewInlineKeyboardButtonPay(text string) *InlineKeyboardButton {
return &InlineKeyboardButton{Text: text, Pay: true}
}
func (bot *Bot) NewUpdatesChannel(params *GetUpdatesParameters) chan *Update {
if params == nil {
params = &GetUpdatesParameters{
Limit: 100,
Timeout: 60,
}
}
channel := make(chan *Update, params.Limit)
go func() {
for {
updates, err := bot.GetUpdates(params)
if err != nil {
log.Println(err.Error())
log.Println("failed to get updates, retrying in 3 seconds...")
time.Sleep(time.Second * 3)
continue
}
for _, update := range updates {
if update.ID >= params.Offset {
params.Offset = update.ID + 1
channel <- &update
}
}
}
}()
return channel
}