Documentation
¶
Overview ¶
Package keyboard provides fluent builders for Telegram inline and reply keyboards.
Index ¶
- func BoolPtr(b bool) *bool
- func Row[T any](buttons ...T) []T
- func TranslateReplyMarkup(markup ReplyMarkup) (tg.ReplyMarkupClass, error)
- type ButtonStyleOption
- type InlineBuilder
- type InlineButton
- func Callback(text, data string, opts ...ButtonStyleOption) InlineButton
- func Pay(text string, opts ...ButtonStyleOption) InlineButton
- func SwitchInline(text, query string, opts ...ButtonStyleOption) InlineButton
- func SwitchInlineCurrentChat(text, query string, opts ...ButtonStyleOption) InlineButton
- func URL(text, url string, opts ...ButtonStyleOption) InlineButton
- func WebApp(text, url string, opts ...ButtonStyleOption) InlineButton
- type InlineKeyboard
- type RemoveKeyboard
- type ReplyBuilder
- func (b *ReplyBuilder) Add(buttons ...ReplyButton) *ReplyBuilder
- func (b *ReplyBuilder) Build() ReplyKeyboard
- func (b *ReplyBuilder) WithOneTime() *ReplyBuilder
- func (b *ReplyBuilder) WithPlaceholder(text string) *ReplyBuilder
- func (b *ReplyBuilder) WithResize() *ReplyBuilder
- func (b *ReplyBuilder) WithSelective() *ReplyBuilder
- type ReplyButton
- func ReplyWebApp(text, url string, opts ...ButtonStyleOption) ReplyButton
- func RequestChannel(text string, buttonID int, reqOpts RequestChannelOptions, ...) ReplyButton
- func RequestContact(text string, opts ...ButtonStyleOption) ReplyButton
- func RequestGroup(text string, buttonID int, reqOpts RequestGroupOptions, ...) ReplyButton
- func RequestLocation(text string, opts ...ButtonStyleOption) ReplyButton
- func RequestPoll(text string, quizOnly bool, opts ...ButtonStyleOption) ReplyButton
- func RequestUsers(text string, buttonID int, reqOpts RequestUsersOptions, ...) ReplyButton
- func Text(text string, opts ...ButtonStyleOption) ReplyButton
- func UserProfile(text string, userID int64, opts ...ButtonStyleOption) ReplyButton
- type ReplyKeyboard
- type ReplyMarkup
- type RequestChannelOptions
- type RequestGroupOptions
- type RequestUsersOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Row ¶
func Row[T any](buttons ...T) []T
Row is a generic helper to construct a single row of buttons.
func TranslateReplyMarkup ¶
func TranslateReplyMarkup(markup ReplyMarkup) (tg.ReplyMarkupClass, error)
TranslateReplyMarkup converts a keyboard ReplyMarkup to its MTProto equivalent.
Types ¶
type ButtonStyleOption ¶
type ButtonStyleOption func(*buttonStyle)
ButtonStyleOption configures button visuals.
func Danger ¶
func Danger() ButtonStyleOption
Danger returns a ButtonStyleOption that applies the danger style to a button.
func Icon ¶
func Icon(emojiID int64) ButtonStyleOption
Icon returns a ButtonStyleOption that sets an emoji icon for a button.
func Primary ¶
func Primary() ButtonStyleOption
Primary returns a ButtonStyleOption that applies the primary style to a button.
func Success ¶
func Success() ButtonStyleOption
Success returns a ButtonStyleOption that applies the success style to a button.
type InlineBuilder ¶
type InlineBuilder struct {
// contains filtered or unexported fields
}
InlineBuilder is a fluent builder for constructing inline keyboards.
func NewInlineBuilder ¶
func NewInlineBuilder(columns int) *InlineBuilder
NewInlineBuilder creates a new inline keyboard builder with the specified number of columns.
func (*InlineBuilder) Add ¶
func (b *InlineBuilder) Add(buttons ...InlineButton) *InlineBuilder
Add appends buttons to the inline builder and returns the builder for chaining.
func (*InlineBuilder) Build ¶
func (b *InlineBuilder) Build() InlineKeyboard
Build constructs the final InlineKeyboard from the accumulated buttons.
type InlineButton ¶
type InlineButton struct {
Text string
CallbackData string
URL string
WebAppURL string
SwitchInlineQuery *string
SwitchInlineQueryCurrentChat *string
Pay bool
Style buttonStyle
}
InlineButton represents a single button in an inline keyboard.
func Callback ¶
func Callback(text, data string, opts ...ButtonStyleOption) InlineButton
Callback creates an inline button that sends callback data when pressed.
func Pay ¶
func Pay(text string, opts ...ButtonStyleOption) InlineButton
Pay creates an inline button that initiates a payment.
func SwitchInline ¶
func SwitchInline(text, query string, opts ...ButtonStyleOption) InlineButton
SwitchInline creates an inline button that inserts text into the current chat's query.
func SwitchInlineCurrentChat ¶
func SwitchInlineCurrentChat(text, query string, opts ...ButtonStyleOption) InlineButton
SwitchInlineCurrentChat creates an inline button that inserts text into the current inline query.
func URL ¶
func URL(text, url string, opts ...ButtonStyleOption) InlineButton
URL creates an inline button that opens a URL.
func WebApp ¶
func WebApp(text, url string, opts ...ButtonStyleOption) InlineButton
WebApp creates an inline button that opens a web app.
type InlineKeyboard ¶
type InlineKeyboard struct {
Rows [][]InlineButton
}
InlineKeyboard represents an inline keyboard markup with rows of buttons.
func NewInlineKeyboard ¶
func NewInlineKeyboard(rows ...[]InlineButton) InlineKeyboard
NewInlineKeyboard creates an inline keyboard from rows of buttons.
type RemoveKeyboard ¶
type RemoveKeyboard struct {
Selective bool
}
RemoveKeyboard represents a request to remove the keyboard markup from the screen.
func NewRemoveKeyboard ¶
func NewRemoveKeyboard(selective bool) RemoveKeyboard
NewRemoveKeyboard creates a remove keyboard markup with the given selective flag.
type ReplyBuilder ¶
type ReplyBuilder struct {
// contains filtered or unexported fields
}
ReplyBuilder is a fluent builder for constructing reply keyboards.
func NewReplyBuilder ¶
func NewReplyBuilder(columns int) *ReplyBuilder
NewReplyBuilder creates a new reply keyboard builder with the specified number of columns.
func (*ReplyBuilder) Add ¶
func (b *ReplyBuilder) Add(buttons ...ReplyButton) *ReplyBuilder
Add appends buttons to the reply builder and returns the builder for chaining.
func (*ReplyBuilder) Build ¶
func (b *ReplyBuilder) Build() ReplyKeyboard
Build constructs the final ReplyKeyboard from the accumulated buttons and settings.
func (*ReplyBuilder) WithOneTime ¶
func (b *ReplyBuilder) WithOneTime() *ReplyBuilder
WithOneTime sets the one-time flag and returns the builder for chaining.
func (*ReplyBuilder) WithPlaceholder ¶
func (b *ReplyBuilder) WithPlaceholder(text string) *ReplyBuilder
WithPlaceholder sets the placeholder text and returns the builder for chaining.
func (*ReplyBuilder) WithResize ¶
func (b *ReplyBuilder) WithResize() *ReplyBuilder
WithResize sets the resize flag and returns the builder for chaining.
func (*ReplyBuilder) WithSelective ¶
func (b *ReplyBuilder) WithSelective() *ReplyBuilder
WithSelective sets the selective flag and returns the builder for chaining.
type ReplyButton ¶
type ReplyButton struct {
Text string
RequestContact bool
RequestLocation bool
WebAppURL *string
RequestPoll *bool
UserProfileID *int64
RequestPeerButtonID *int
RequestUsers *RequestUsersOptions
RequestGroup *RequestGroupOptions
RequestChannel *RequestChannelOptions
Style buttonStyle
}
ReplyButton represents a single button in a reply keyboard.
func ReplyWebApp ¶
func ReplyWebApp(text, url string, opts ...ButtonStyleOption) ReplyButton
ReplyWebApp creates a reply button that opens a web app.
func RequestChannel ¶
func RequestChannel(text string, buttonID int, reqOpts RequestChannelOptions, opts ...ButtonStyleOption) ReplyButton
RequestChannel creates a reply button that requests a channel.
func RequestContact ¶
func RequestContact(text string, opts ...ButtonStyleOption) ReplyButton
RequestContact creates a reply button that requests the user's phone number.
func RequestGroup ¶
func RequestGroup(text string, buttonID int, reqOpts RequestGroupOptions, opts ...ButtonStyleOption) ReplyButton
RequestGroup creates a reply button that requests a group.
func RequestLocation ¶
func RequestLocation(text string, opts ...ButtonStyleOption) ReplyButton
RequestLocation creates a reply button that requests the user's location.
func RequestPoll ¶
func RequestPoll(text string, quizOnly bool, opts ...ButtonStyleOption) ReplyButton
RequestPoll creates a reply button that requests a poll or quiz.
func RequestUsers ¶
func RequestUsers(text string, buttonID int, reqOpts RequestUsersOptions, opts ...ButtonStyleOption) ReplyButton
RequestUsers creates a reply button that requests users.
func Text ¶
func Text(text string, opts ...ButtonStyleOption) ReplyButton
Text creates a reply button with plain text.
func UserProfile ¶
func UserProfile(text string, userID int64, opts ...ButtonStyleOption) ReplyButton
UserProfile creates a reply button that requests a user profile.
type ReplyKeyboard ¶
type ReplyKeyboard struct {
Rows [][]ReplyButton
Resize bool
OneTime bool
Selective bool
PlaceholderText string
}
ReplyKeyboard represents a reply keyboard markup with rows of buttons.
func NewReplyKeyboard ¶
func NewReplyKeyboard(rows ...[]ReplyButton) ReplyKeyboard
NewReplyKeyboard creates a reply keyboard from rows of buttons.
func (ReplyKeyboard) WithOneTime ¶
func (k ReplyKeyboard) WithOneTime() ReplyKeyboard
WithOneTime returns a copy of the reply keyboard with the one-time flag set.
func (ReplyKeyboard) WithPlaceholder ¶
func (k ReplyKeyboard) WithPlaceholder(text string) ReplyKeyboard
WithPlaceholder returns a copy of the reply keyboard with the given placeholder text.
func (ReplyKeyboard) WithResize ¶
func (k ReplyKeyboard) WithResize() ReplyKeyboard
WithResize returns a copy of the reply keyboard with the resize flag set.
func (ReplyKeyboard) WithSelective ¶
func (k ReplyKeyboard) WithSelective() ReplyKeyboard
WithSelective returns a copy of the reply keyboard with the selective flag set.
type ReplyMarkup ¶
type ReplyMarkup interface {
// contains filtered or unexported methods
}
ReplyMarkup defines the sealed interface for all Telegram keyboard markups.
type RequestChannelOptions ¶
type RequestChannelOptions struct {
IsCreator bool
HasUsername *bool
UserAdminRights *tg.ChatAdminRights
BotAdminRights *tg.ChatAdminRights
}
RequestChannelOptions specifies filters for requesting channels.
type RequestGroupOptions ¶
type RequestGroupOptions struct {
IsCreator bool
BotIsMember bool
HasUsername *bool
IsForum *bool
UserAdminRights *tg.ChatAdminRights
BotAdminRights *tg.ChatAdminRights
}
RequestGroupOptions specifies filters for requesting groups.
type RequestUsersOptions ¶
RequestUsersOptions specifies filters for requesting users.