Skip to content

Commit

Permalink
Fix for data-less inline buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Byrd committed Dec 10, 2017
1 parent bdd5916 commit 426f436
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
20 changes: 16 additions & 4 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (b *Bot) Handle(endpoint interface{}, handler interface{}) {

var (
cmdRx = regexp.MustCompile(`^(\/\w+)(@(\w+))?(\s|$)(.+)?`)
cbackRx = regexp.MustCompile(`^\f(\w+)\|(.+)$`)
cbackRx = regexp.MustCompile(`^\f(\w+)(\|(.+))?$`)
)

func (b *Bot) handleCommand(m *Message, cmdName, cmdBot string) bool {
Expand Down Expand Up @@ -276,7 +276,7 @@ func (b *Bot) incomingUpdate(upd *Update) {
match := cbackRx.FindAllStringSubmatch(data, -1)

if match != nil {
unique, payload := match[0][1], match[0][2]
unique, payload := match[0][1], match[0][3]

if handler, ok := b.handlers["\f"+unique]; ok {
if handler, ok := handler.(func(*Callback)); ok {
Expand Down Expand Up @@ -695,9 +695,21 @@ func (b *Bot) Answer(query *Query, response *QueryResponse) error {
// Respond sends a response for a given callback query. A callback can
// only be responded to once, subsequent attempts to respond to the same callback
// will result in an error.
func (b *Bot) Respond(callback *Callback, response *CallbackResponse) error {
response.CallbackID = callback.ID
//
// Example:
//
// bot.Respond(c)
// bot.Respond(c, response)
//
func (b *Bot) Respond(callback *Callback, responseOptional ...*CallbackResponse) error {
var response *CallbackResponse
if responseOptional == nil {
response = &CallbackResponse{}
} else {
response = responseOptional[0]
}

response.CallbackID = callback.ID
respJSON, err := b.Raw("answerCallbackQuery", response)
if err != nil {
return err
Expand Down
7 changes: 6 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ func embedSendOptions(params map[string]string, opt *SendOptions) {
key := &keys[i][j]
if key.Unique != "" {
// Format: "\f<callback_name>|<data>"
key.Data = "\f" + key.Unique + "|" + key.Data
data := key.Data
if data == "" {
key.Data = "\f" + key.Unique
} else {
key.Data = "\f" + key.Unique + "|" + data
}
}
}
}
Expand Down

0 comments on commit 426f436

Please sign in to comment.