Refining ReplyMarkup API.

pull/108/head
Ian Byrd 7 years ago
parent d4f3a16377
commit 9e92b919f8
No known key found for this signature in database
GPG Key ID: 598F598CA3B8055F

@ -139,17 +139,10 @@ err = bot.Send(recipient, audio)
## Reply markup
```go
// Send a selective force reply message.
bot.Send(user, "pong", &tb.SendOptions{
ReplyMarkup: &tb.ReplyMarkup{
ForceReply: true,
Selective: true,
CustomKeyboard: [][]string{
[]string{"1", "2", "3"},
[]string{"4", "5", "6"},
[]string{"7", "8", "9"},
[]string{"*", "0", "#"},
},
},
},
)
bot.Send(user, "pong", &tb.ReplyMarkup{
ForceReply: true,
Selective: true,
ReplyKeyboard: keys,
})
```

@ -43,30 +43,35 @@ type SendOptions struct {
// ReplyMarkup specifies convenient options for bot-user communications.
type ReplyMarkup struct {
InlineKeyboard [][]InlineButton `json:"inline_keyboard,omitempty"`
// ForceReply forces Telegram clients to display
// a reply interface to the user (act as if the user
// has selected the bots message and tapped "Reply").
ForceReply bool `json:"force_reply,omitempty"`
// CustomKeyboard is a grid, consisting of keyboard buttons.
// InlineKeyboard is a grid of InlineButtons displayed in the message.
//
// Note: DO NOT confuse with ReplyKeyboard and other keyboard properties!
InlineKeyboard [][]InlineButton `json:"inline_keyboard,omitempty"`
// ReplyKeyboard is a grid, consisting of keyboard buttons.
//
// Note: you don't need to set HideCustomKeyboard field to show custom keyboard.
CustomKeyboard [][]KeyboardButton `json:"keyboard,omitempty"`
ReplyKeyboard [][]KeyboardButton `json:"keyboard,omitempty"`
// Requests clients to hide the custom keyboard.
//
// Note: You dont need to set CustomKeyboard field to hide custom keyboard.
HideCustomKeyboard bool `json:"hide_keyboard,omitempty"`
HideReplyKeyboard bool `json:"hide_keyboard,omitempty"`
// Requests clients to resize the keyboard vertically for optimal fit
// (e.g., make the keyboard smaller if there are just two rows of buttons).
// (e.g. make the keyboard smaller if there are just two rows of buttons).
//
// Defaults to false, in which case the custom keyboard is always of the
// same height as the app's standard keyboard.
ResizeKeyboard bool `json:"resize_keyboard,omitempty"`
ResizeReplyKeyboard bool `json:"resize_keyboard,omitempty"`
// Requests clients to hide the keyboard as soon as it's been used.
// Requests clients to hide the reply keyboard as soon as it's been used.
//
// Defaults to false.
OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"`

@ -91,11 +91,12 @@ func embedSendOptions(params map[string]string, opt *SendOptions) {
}
if opt.ReplyMarkup != nil {
forceReply := opt.ReplyMarkup.ForceReply
customKeyboard := (opt.ReplyMarkup.CustomKeyboard != nil)
inlineKeyboard := opt.ReplyMarkup.InlineKeyboard != nil
hiddenKeyboard := opt.ReplyMarkup.HideCustomKeyboard
if forceReply || customKeyboard || hiddenKeyboard || inlineKeyboard {
force := opt.ReplyMarkup.ForceReply
reply := opt.ReplyMarkup.ReplyKeyboard != nil
inline := opt.ReplyMarkup.InlineKeyboard != nil
hidden := opt.ReplyMarkup.HideReplyKeyboard
resize := opt.ReplyMarkup.ResizeReplyKeyboard
if force || reply || inline || hidden || resize {
replyMarkup, _ := json.Marshal(opt.ReplyMarkup)
params["reply_markup"] = string(replyMarkup)
}

Loading…
Cancel
Save