Handle() now supports keyboard buttons as endpoints.

pull/108/head
Ian Byrd 7 years ago
parent 119a4e1698
commit 5a73cee70a
No known key found for this signature in database
GPG Key ID: 598F598CA3B8055F

@ -94,6 +94,8 @@ func (b *Bot) Handle(endpoint interface{}, handler interface{}) {
b.handlers[end] = handler
case CallbackEndpoint:
b.handlers["\f"+end.CallbackUnique()] = handler
default:
panic("telebot: unsupported endpoint")
}
}
@ -380,7 +382,7 @@ func (b *Bot) Send(to Recipient, what interface{}, options ...interface{}) (*Mes
case Sendable:
return object.Send(b, to, sendOpts)
default:
panic(fmt.Sprintf("telebot: object %v is not Sendable", object))
panic("telebot: unsupported sendable")
}
}

@ -68,7 +68,12 @@ type InlineButton struct {
InlineQuery string `json:"switch_inline_query,omitempty"`
}
// CallbackUnique returns InlineButto.Unique
// CallbackUnique returns InlineButto.Unique.
func (t *InlineButton) CallbackUnique() string {
return t.Unique
}
// CallbackUnique returns KeyboardButton.Text.
func (t *KeyboardButton) CallbackUnique() string {
return t.Text
}

@ -91,7 +91,7 @@ type ReplyMarkup struct {
//
// Set either Contact or Location to true in order to request
// sensitive info, such as user's phone number or current location.
// (Available in private chats only)
// (Available in private chats only.)
type KeyboardButton struct {
Text string `json:"text"`

@ -2,7 +2,6 @@ package telebot
import (
"encoding/json"
"fmt"
"strconv"
"github.com/pkg/errors"
@ -125,7 +124,7 @@ func extractOptions(how []interface{}) *SendOptions {
opts.ParseMode = opt
default:
panic(fmt.Sprintf("telebot: %v is not a send-option", opt))
panic("telebot: unsupported send-option")
}
}
@ -160,6 +159,7 @@ func embedSendOptions(params map[string]string, opt *SendOptions) {
for j, _ := range keys[i] {
key := &keys[i][j]
if key.Unique != "" {
// Format: "\f<callback_name>|<data>"
key.Data = "\f" + key.Unique + "|" + key.Data
}
}

Loading…
Cancel
Save