Skip to content

Commit

Permalink
Start(), Update now supports edited messages / channel posts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Byrd committed Nov 21, 2017
1 parent 43be06e commit ba575e7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
49 changes: 49 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,55 @@ type Settings struct {
Poller Poller
}

// Update object represents an incoming update.
type Update struct {
ID int `json:"update_id"`

Message *Message `json:"message,omitempty"`
EditedMessage *Message `json:"edited_message,omitempty"`
ChannelPost *Message `json:"channel_post,omitempty"`
EditedChannelPost *Message `json:"edited_channel_post,omitempty"`
Callback *Callback `json:"callback_query,omitempty"`
Query *Query `json:"inline_query,omitempty"`
}

// Start brings bot into motion by consuming incoming
// updates (see Bot.Updates channel).
func (b *Bot) Start() {
for upd := range b.Updates {
if b.Messages != nil {
if upd.Message != nil {
b.Messages <- *upd.Message
continue
}

if upd.EditedMessage != nil {
b.Messages <- *upd.EditedMessage
continue
}

if upd.ChannelPost != nil {
b.Messages <- *upd.ChannelPost
continue
}

if upd.EditedChannelPost != nil {
b.Messages <- *upd.EditedChannelPost
continue
}
}

if upd.Callback != nil && b.Callbacks != nil {
b.Callbacks <- *upd.Callback
continue
}

if upd.Query != nil && b.Queries != nil {
b.Queries <- *upd.Query
}
}
}

// Send accepts 2+ arguments, starting with destination chat, followed by
// some Sendable (or string!) and optional send options.
//
Expand Down
10 changes: 0 additions & 10 deletions poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ import (
"github.com/pkg/errors"
)

// Update object represents an incoming update.
type Update struct {
ID int `json:"update_id"`

// Either.
Message *Message `json:"message"`
Callback *Callback `json:"callback_query"`
Query *Query `json:"inline_query"`
}

// Poller is a provider of Updates.
//
// All pollers must implement Poll(), which accepts bot
Expand Down

0 comments on commit ba575e7

Please sign in to comment.