From 5a73cee70adc80ca83dc9b393bee0c122cf84ede Mon Sep 17 00:00:00 2001 From: Ian Byrd Date: Mon, 27 Nov 2017 16:19:42 +0200 Subject: [PATCH] Handle() now supports keyboard buttons as endpoints. --- bot.go | 4 +++- callbacks.go | 7 ++++++- options.go | 2 +- util.go | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bot.go b/bot.go index b68af4b..520ac22 100644 --- a/bot.go +++ b/bot.go @@ -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") } } diff --git a/callbacks.go b/callbacks.go index 4575d3d..2f59236 100644 --- a/callbacks.go +++ b/callbacks.go @@ -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 +} diff --git a/options.go b/options.go index 3e872ef..eb2c783 100644 --- a/options.go +++ b/options.go @@ -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"` diff --git a/util.go b/util.go index 9248c4a..15215dd 100644 --- a/util.go +++ b/util.go @@ -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|" key.Data = "\f" + key.Unique + "|" + key.Data } }