bot: add callback unique field

pull/341/head
Demian 4 years ago
parent 4e02fbfc4f
commit 541cbd7e1e

@ -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

@ -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.

@ -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()
}

Loading…
Cancel
Save