Merge pull request #4 from Ronmi/master

Support custom keyboard
This commit is contained in:
llya Kowalewski 2015-07-31 12:00:07 +03:00
commit 89fca71055
2 changed files with 32 additions and 12 deletions

7
api.go
View File

@ -95,9 +95,10 @@ func embedSendOptions(params *url.Values, options *SendOptions) {
params.Set("disable_web_page_preview", "true") params.Set("disable_web_page_preview", "true")
} }
if options.ForceReply.Require { // process reply_markup
forceReply, _ := json.Marshal(options.ForceReply) if options.ReplyMarkup.ForceReply || options.ReplyMarkup.CustomKeyboard != nil || options.ReplyMarkup.HideCustomKeyboard {
params.Set("reply_markup", string(forceReply)) replyMarkup, _ := json.Marshal(options.ReplyMarkup)
params.Set("reply_markup", string(replyMarkup))
} }
} }

View File

@ -6,19 +6,38 @@ type SendOptions struct {
// If the message is a reply, original message. // If the message is a reply, original message.
ReplyTo Message ReplyTo Message
// See ForceReply struct definition. // See ReplyMarkup struct definition.
ForceReply ForceReply ReplyMarkup ReplyMarkup
// For text messages, disables previews for links in this message. // For text messages, disables previews for links in this message.
DisableWebPagePreview bool DisableWebPagePreview bool
} }
// ForceReply forces Telegram clients to display type ReplyMarkup struct {
// a reply interface to the user (act as if the user // ForceReply forces Telegram clients to display
// has selected the bots message and tapped "Reply"). // a reply interface to the user (act as if the user
type ForceReply struct { // has selected the bots message and tapped "Reply").
// Enable if intended. ForceReply bool `json:"force_reply,omitempty"`
Require bool `json:"force_reply"`
// CustomKeyboard is Array of button rows, each represented by an Array of Strings.
//
// Note: you don't need to set HideCustomKeyboard field to show custom keyboard.
CustomKeyboard [][]string `json:"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).
// 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_keyboar,omitemptyd"`
// Requests clients to hide the keyboard as soon as it's been used. Defaults to false.
OneTimeKeyboard bool `json:"one_time_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"`
// Use this param if you want to force reply from // Use this param if you want to force reply from
// specific users only. // specific users only.
@ -27,5 +46,5 @@ type ForceReply struct {
// 1) Users that are @mentioned in the text of the Message object; // 1) Users that are @mentioned in the text of the Message object;
// 2) If the bot's message is a reply (has SendOptions.ReplyTo), // 2) If the bot's message is a reply (has SendOptions.ReplyTo),
// sender of the original message. // sender of the original message.
Selective bool `json:"selective"` Selective bool `json:"selective,omitempty"`
} }