Skip to content

Commit

Permalink
bot: add callback unique field
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Oct 12, 2020
1 parent 4e02fbf commit 541cbd7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ func (b *Bot) ProcessUpdate(upd Update) {
unique, payload := match[0][1], match[0][3]

if handler, ok := b.handlers["\f"+unique]; ok {
c.callback.Unique = unique
c.callback.Data = payload
b.runHandler(handler, c)
return
Expand Down
5 changes: 5 additions & 0 deletions callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ type Callback struct {
// Data associated with the callback button. Be aware that
// a bad client can send arbitrary data in this field.
Data string `json:"data"`

// Unique displays an unique of the button from which the
// callback was fired. Sets immediately before the handling,
// while the Data field stores only with payload.
Unique string `json:"-"`
}

// IsInline says whether message is an inline message.
Expand Down
4 changes: 3 additions & 1 deletion middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func Logger(logger *logrus.Logger, fieldsFunc ...LoggerFieldsFunc) tele.Middlewa
return func(next tele.HandlerFunc) tele.HandlerFunc {
return func(c tele.Context) error {
data := c.Data()
if data == "" {
if clb := c.Callback(); clb != nil {
data = clb.Unique + "|" + data
} else if data == "" {
data = c.Text()
}

Expand Down

0 comments on commit 541cbd7

Please sign in to comment.