Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 98 additions & 54 deletions _schema/tdesktop.tl

Large diffs are not rendered by default.

152 changes: 96 additions & 56 deletions _schema/tdlib.tl

Large diffs are not rendered by default.

152 changes: 98 additions & 54 deletions _schema/telegram.tl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion telegram/message/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (b *Builder) Markup(m tg.ReplyMarkupClass) *Builder {
// Row sets single row keyboard markup for sending bot buttons.
//
// NB: markup will not be used, if you send multiple media attachments.
func (b *Builder) Row(buttons ...tg.KeyboardButtonClass) *Builder {
func (b *Builder) Row(buttons ...tg.KeyboardInlineButton) *Builder {
return b.Markup(markup.InlineRow(buttons...))
}

Expand Down
2 changes: 1 addition & 1 deletion telegram/message/inline/message_auto_media.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (b *MessageMediaAutoBuilder) Markup(m tg.ReplyMarkupClass) *MessageMediaAut
// Row sets single row keyboard markup for sending bot buttons.
// NB: markup will not be used, if you send multiple media attachments.
func (b *MessageMediaAutoBuilder) Row(
buttons ...tg.KeyboardButtonClass,
buttons ...tg.KeyboardInlineButton,
) *MessageMediaAutoBuilder {
return b.Markup(markup.InlineRow(buttons...))
}
2 changes: 1 addition & 1 deletion telegram/message/inline/message_game.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ func (b *MessageGameBuilder) Markup(m tg.ReplyMarkupClass) *MessageGameBuilder {

// Row sets single row keyboard markup for sending bot buttons.
// NB: markup will not be used, if you send multiple media attachments.
func (b *MessageGameBuilder) Row(buttons ...tg.KeyboardButtonClass) *MessageGameBuilder {
func (b *MessageGameBuilder) Row(buttons ...tg.KeyboardInlineButton) *MessageGameBuilder {
return b.Markup(markup.InlineRow(buttons...))
}
2 changes: 1 addition & 1 deletion telegram/message/inline/message_geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ func (b *MessageMediaGeoBuilder) Markup(m tg.ReplyMarkupClass) *MessageMediaGeoB

// Row sets single row keyboard markup for sending bot buttons.
// NB: markup will not be used, if you send multiple media attachments.
func (b *MessageMediaGeoBuilder) Row(buttons ...tg.KeyboardButtonClass) *MessageMediaGeoBuilder {
func (b *MessageMediaGeoBuilder) Row(buttons ...tg.KeyboardInlineButton) *MessageMediaGeoBuilder {
return b.Markup(markup.InlineRow(buttons...))
}
2 changes: 1 addition & 1 deletion telegram/message/inline/message_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ func (b *MessageTextBuilder) Markup(m tg.ReplyMarkupClass) *MessageTextBuilder {

// Row sets single row keyboard markup for sending bot buttons.
// NB: markup will not be used, if you send multiple media attachments.
func (b *MessageTextBuilder) Row(buttons ...tg.KeyboardButtonClass) *MessageTextBuilder {
func (b *MessageTextBuilder) Row(buttons ...tg.KeyboardInlineButton) *MessageTextBuilder {
return b.Markup(markup.InlineRow(buttons...))
}
201 changes: 98 additions & 103 deletions telegram/message/markup/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,53 +47,83 @@ func StyleIcon(icon int64) StyleOption {
}
}

// Row creates keyboard row.
func Row(buttons ...tg.KeyboardButtonClass) tg.KeyboardButtonRow {
return tg.KeyboardButtonRow{
Buttons: buttons,
// reply creates a reply keyboard button of given type.
func reply(text string, typ tg.ButtonTypeClass, style []StyleOption) tg.KeyboardButton {
return tg.KeyboardButton{
Text: text,
Type: typ,
Style: applyStyle(style),
}
}

// Button creates new plain text button.
func Button(text string, style ...StyleOption) *tg.KeyboardButton {
return &tg.KeyboardButton{
// inline creates an inline keyboard button of given type.
func inline(text string, typ tg.InlineButtonTypeClass, style []StyleOption) tg.KeyboardInlineButton {
return tg.KeyboardInlineButton{
Text: text,
Type: typ,
Style: applyStyle(style),
}
}

// URL creates new URL button.
func URL(text, url string, style ...StyleOption) *tg.KeyboardButtonURL {
return &tg.KeyboardButtonURL{
Text: text,
URL: url,
Style: applyStyle(style),
// Row creates reply keyboard row.
func Row(buttons ...tg.KeyboardButton) tg.KeyboardButtonRow {
return tg.KeyboardButtonRow{
Buttons: buttons,
}
}

// Callback creates new callback button.
func Callback(text string, data []byte, style ...StyleOption) *tg.KeyboardButtonCallback {
return &tg.KeyboardButtonCallback{
Text: text,
Data: data,
Style: applyStyle(style),
// InlineButtonRow creates inline keyboard row.
func InlineButtonRow(buttons ...tg.KeyboardInlineButton) tg.KeyboardInlineButtonRow {
return tg.KeyboardInlineButtonRow{
Buttons: buttons,
}
}

// Button creates new plain text button.
func Button(text string, style ...StyleOption) tg.KeyboardButton {
return reply(text, &tg.ButtonTypeDefault{}, style)
}

// RequestPhone creates button to request a user's phone number.
func RequestPhone(text string, style ...StyleOption) *tg.KeyboardButtonRequestPhone {
return &tg.KeyboardButtonRequestPhone{
Text: text,
Style: applyStyle(style),
}
func RequestPhone(text string, style ...StyleOption) tg.KeyboardButton {
return reply(text, &tg.ButtonTypeRequestPhone{}, style)
}

// RequestGeoLocation creates button to request a user's geo location.
func RequestGeoLocation(text string, style ...StyleOption) *tg.KeyboardButtonRequestGeoLocation {
return &tg.KeyboardButtonRequestGeoLocation{
Text: text,
Style: applyStyle(style),
}
func RequestGeoLocation(text string, style ...StyleOption) tg.KeyboardButton {
return reply(text, &tg.ButtonTypeRequestGeoLocation{}, style)
}

// RequestPoll creates button that allows the user to create and send a poll when pressed.
// Available only in private.
func RequestPoll(text string, quiz bool, style ...StyleOption) tg.KeyboardButton {
return reply(text, &tg.ButtonTypeRequestPoll{Quiz: quiz}, style)
}

// RequestPeer creates button that prompts the user to select and share a peer with the bot using
// messages.sendBotRequestedPeer.
func RequestPeer(text string, buttonID int, peerType tg.RequestPeerTypeClass, style ...StyleOption) tg.KeyboardButton {
return reply(text, &tg.ButtonTypeRequestPeer{
ButtonID: buttonID,
PeerType: peerType,
}, style)
}

// SimpleWebView creates button to open a bot web app using messages.requestSimpleWebView, without sending user
// information to the web app.
// Can only be sent or received as part of a reply keyboard, use WebView for inline keyboards.
func SimpleWebView(text, url string, style ...StyleOption) tg.KeyboardButton {
return reply(text, &tg.ButtonTypeSimpleWebView{URL: url}, style)
}

// URL creates new URL button.
func URL(text, url string, style ...StyleOption) tg.KeyboardInlineButton {
return inline(text, &tg.InlineButtonTypeURL{URL: url}, style)
}

// Callback creates new callback button.
func Callback(text string, data []byte, style ...StyleOption) tg.KeyboardInlineButton {
return inline(text, &tg.InlineButtonTypeCallback{Data: data}, style)
}

// SwitchInline creates button to force a user to switch to inline mode.
Expand All @@ -102,113 +132,78 @@ func RequestGeoLocation(text string, style ...StyleOption) *tg.KeyboardButtonReq
//
// If samePeer set, pressing the button will insert the bot‘s
// username and the specified inline query in the current chat's input field.
func SwitchInline(text, query string, samePeer bool, style ...StyleOption) *tg.KeyboardButtonSwitchInline {
return &tg.KeyboardButtonSwitchInline{
func SwitchInline(text, query string, samePeer bool, style ...StyleOption) tg.KeyboardInlineButton {
return inline(text, &tg.InlineButtonTypeSwitchInline{
SamePeer: samePeer,
Text: text,
Query: query,
Style: applyStyle(style),
}
}, style)
}

// Game creates button to start a game.
func Game(text string, style ...StyleOption) *tg.KeyboardButtonGame {
return &tg.KeyboardButtonGame{
Text: text,
Style: applyStyle(style),
}
func Game(text string, style ...StyleOption) tg.KeyboardInlineButton {
return inline(text, &tg.InlineButtonTypeGame{}, style)
}

// Buy creates button to buy a product.
func Buy(text string, style ...StyleOption) *tg.KeyboardButtonBuy {
return &tg.KeyboardButtonBuy{
Text: text,
Style: applyStyle(style),
}
func Buy(text string, style ...StyleOption) tg.KeyboardInlineButton {
return inline(text, &tg.InlineButtonTypeBuy{}, style)
}

// InputURLAuth creates button to request a user to authorize via URL using Seamless Telegram Login.
// Can only be sent or received as part of an inline keyboard, use URLAuth for reply keyboards.
func InputURLAuth(requestWriteAccess bool, text, fwdText, url string, bot tg.InputUserClass) *tg.InputKeyboardButtonURLAuth {
return &tg.InputKeyboardButtonURLAuth{
// Use it to send a button, use URLAuth to handle a received one.
func InputURLAuth(
requestWriteAccess bool, text, fwdText, url string, bot tg.InputUserClass, style ...StyleOption,
) tg.KeyboardInlineButton {
return inline(text, &tg.InputInlineButtonTypeURLAuth{
RequestWriteAccess: requestWriteAccess,
Text: text,
FwdText: fwdText,
URL: url,
Bot: bot,
}
}, style)
}

// URLAuth creates button to request a user to authorize via URL using Seamless Telegram Login.
// Can only be sent or received as part of a reply keyboard, use InputURLAuth for inline keyboards.
func URLAuth(text, url string, buttonID int, fwdText string, style ...StyleOption) *tg.KeyboardButtonURLAuth {
return &tg.KeyboardButtonURLAuth{
Text: text,
// Use InputURLAuth to send such a button.
func URLAuth(text, url string, buttonID int, fwdText string, style ...StyleOption) tg.KeyboardInlineButton {
return inline(text, &tg.InlineButtonTypeURLAuth{
FwdText: fwdText,
URL: url,
ButtonID: buttonID,
FwdText: fwdText,
Style: applyStyle(style),
}
}

// RequestPoll creates button that allows the user to create and send a poll when pressed.
// Available only in private.
func RequestPoll(text string, quiz bool, style ...StyleOption) *tg.KeyboardButtonRequestPoll {
return &tg.KeyboardButtonRequestPoll{
Text: text,
Quiz: quiz,
Style: applyStyle(style),
}
}, style)
}

// InputUserProfile creates button that links directly to a user profile.
// Can only be sent or received as part of an inline keyboard, use UserProfile for reply keyboards.
func InputUserProfile(text string, user tg.InputUserClass) *tg.InputKeyboardButtonUserProfile {
return &tg.InputKeyboardButtonUserProfile{
Text: text,
UserID: user,
}
// Use it to send a button, use UserProfile to handle a received one.
func InputUserProfile(text string, user tg.InputUserClass, style ...StyleOption) tg.KeyboardInlineButton {
return inline(text, &tg.InputInlineButtonTypeUserProfile{UserID: user}, style)
}

// UserProfile creates button that links directly to a user profile.
// Can only be sent or received as part of a reply keyboard, use InputUserProfile for inline keyboards.
func UserProfile(text string, userID int64, style ...StyleOption) *tg.KeyboardButtonUserProfile {
return &tg.KeyboardButtonUserProfile{
Text: text,
UserID: userID,
Style: applyStyle(style),
}
// Use InputUserProfile to send such a button.
func UserProfile(text string, userID int64, style ...StyleOption) tg.KeyboardInlineButton {
return inline(text, &tg.InlineButtonTypeUserProfile{UserID: userID}, style)
}

// WebView creates button to open a bot web app using messages.requestWebView, sending over user information after
// user confirmation.
// Can only be sent or received as part of an inline keyboard, use SimpleWebView for reply keyboards.
func WebView(text, url string, style ...StyleOption) *tg.KeyboardButtonWebView {
return &tg.KeyboardButtonWebView{
Text: text,
URL: url,
Style: applyStyle(style),
}
func WebView(text, url string, style ...StyleOption) tg.KeyboardInlineButton {
return inline(text, &tg.InlineButtonTypeWebView{URL: url}, style)
}

// SimpleWebView creates button to open a bot web app using messages.requestSimpleWebView, without sending user
// information to the web app.
// Can only be sent or received as part of a reply keyboard, use WebView for inline keyboards.
func SimpleWebView(text, url string, style ...StyleOption) *tg.KeyboardButtonSimpleWebView {
return &tg.KeyboardButtonSimpleWebView{
Text: text,
URL: url,
Style: applyStyle(style),
}
// InputRequestPeer creates button that prompts the user to select and share a peer with the bot,
// requesting the peer's name, username and/or photo.
// Use it to send a button, use RequestPeer to handle a received one.
func InputRequestPeer(text string, typ tg.InputButtonTypeRequestPeer, style ...StyleOption) tg.KeyboardButton {
return reply(text, &typ, style)
}

// RequestPeer creates button that prompts the user to select and share a peer with the bot using
// messages.sendBotRequestedPeer.
func RequestPeer(text string, buttonID int, peerType tg.RequestPeerTypeClass, style ...StyleOption) *tg.KeyboardButtonRequestPeer {
return &tg.KeyboardButtonRequestPeer{
Text: text,
ButtonID: buttonID,
PeerType: peerType,
Style: applyStyle(style),
}
// Copy creates button that copies copyText to the clipboard when pressed.
func Copy(text, copyText string, style ...StyleOption) tg.KeyboardInlineButton {
return inline(text, &tg.InlineButtonTypeCopy{CopyText: copyText}, style)
}

// Disabled creates button that does nothing when pressed.
func Disabled(text string, style ...StyleOption) tg.KeyboardInlineButton {
return inline(text, &tg.InlineButtonTypeDisabled{}, style)
}
13 changes: 9 additions & 4 deletions telegram/message/markup/button_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,20 @@ func TestButtonStyle(t *testing.T) {
a.Equal(want, WebView("text", "url", options...).Style)
a.Equal(want, SimpleWebView("text", "url", options...).Style)
a.Equal(want, RequestPeer("text", 0, &tg.RequestPeerTypeUser{}, options...).Style)
a.Equal(want, InputRequestPeer("text", tg.InputButtonTypeRequestPeer{}, options...).Style)
a.Equal(want, Copy("text", "copy", options...).Style)
a.Equal(want, Disabled("text", options...).Style)
}

func TestButtonNoStyle(t *testing.T) {
a := require.New(t)

// Without options, the style must stay zero so SetFlags does not set the
// optional Style flag during encoding.
a.True(Button("text").Style.Zero())
a.True(URL("text", "url").Style.Zero())
a.True(Callback("text", []byte("data")).Style.Zero())
a.True(RequestPeer("text", 0, &tg.RequestPeerTypeUser{}).Style.Zero())
zero := func(s tg.KeyboardButtonStyle) bool { return s.Zero() }
a.True(zero(Button("text").Style))
a.True(zero(SimpleWebView("text", "url").Style))
a.True(zero(URL("text", "url").Style))
a.True(zero(Callback("text", []byte("data")).Style))
a.True(zero(RequestPeer("text", 0, &tg.RequestPeerTypeUser{}).Style))
}
6 changes: 3 additions & 3 deletions telegram/message/markup/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package markup
import "github.com/gotd/td/tg"

// InlineRow creates inline keyboard with single row using given buttons.
func InlineRow(buttons ...tg.KeyboardButtonClass) tg.ReplyMarkupClass {
return InlineKeyboard(Row(buttons...))
func InlineRow(buttons ...tg.KeyboardInlineButton) tg.ReplyMarkupClass {
return InlineKeyboard(InlineButtonRow(buttons...))
}

// InlineKeyboard creates inline keyboard using given rows.
func InlineKeyboard(rows ...tg.KeyboardButtonRow) tg.ReplyMarkupClass {
func InlineKeyboard(rows ...tg.KeyboardInlineButtonRow) tg.ReplyMarkupClass {
return &tg.ReplyInlineMarkup{
Rows: rows,
}
Expand Down
8 changes: 3 additions & 5 deletions telegram/message/markup/inline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ import (
func TestInlineRow(t *testing.T) {
a := require.New(t)

buttons := []tg.KeyboardButtonClass{
Button("gotd"),
buttons := []tg.KeyboardInlineButton{
URL("Google!", "https://google.com?q=gotd"),
RequestPhone("phone"),
RequestGeoLocation("geo"),
SwitchInline("inline", "query", true),
Game("game"),
Buy("buy"),
InputURLAuth(false, "text", "fwdText", "url", &tg.InputUserSelf{}),
RequestPoll("poll", true),
InputUserProfile("me", &tg.InputUserSelf{}),
WebView("demo", "https://webappcontent.telegram.org/demo"),
Copy("copy", "text to copy"),
Disabled("nothing"),
}

v, ok := InlineRow(buttons...).(*tg.ReplyInlineMarkup)
Expand Down
Loading
Loading