(new): rich message support
Golang lint / lint (pull_request) Successful in 1m20s
Golang lint / lint (push) Successful in 4m8s

(fix): runtime reliability
(tests): regression coverage
(doc): v1.1 release notes
This commit is contained in:
2026-08-12 16:34:44 +03:00
parent 48ddf66540
commit f03a081ed6
83 changed files with 6122 additions and 1925 deletions
+17 -9
View File
@@ -59,9 +59,12 @@ func (b InlineKeyboardButtonBuilder) SetStyle(style tgapi.KeyboardButtonStyle) I
}
// SetURL sets a URL that will be opened when the button is pressed.
// If both URL and CallbackData are set, Telegram will prioritize URL.
// It clears callback data because Telegram requires exactly one button action.
func (b InlineKeyboardButtonBuilder) SetURL(url string) InlineKeyboardButtonBuilder {
b.url = url
if url != "" {
b.data = ""
}
return b
}
@@ -79,26 +82,29 @@ func (b InlineKeyboardButtonBuilder) SetPayloadType(t BotPayloadType) InlineKeyb
//
// Example: SetCallbackDataJSON("delete_user", 123, "confirm") → {"cmd":"delete_user","args":["123","confirm"]}.
func (b InlineKeyboardButtonBuilder) SetCallbackDataJSON(cmd string, args ...any) InlineKeyboardButtonBuilder {
b.url = ""
b.data = NewCallbackData(cmd, args...).ToJSON()
return b
}
// SetCallbackDataBase64 sets a structured callback payload encoded as Base64.
// This can be useful when the JSON payload exceeds Telegram's callback data length limit.
// Args are converted to strings using fmt.Sprint.
// SetCallbackDataBase64 sets a Base64-encoded structured callback payload.
// Base64 does not bypass Telegram's 64-byte callback-data limit.
func (b InlineKeyboardButtonBuilder) SetCallbackDataBase64(cmd string, args ...any) InlineKeyboardButtonBuilder {
b.url = ""
b.data = NewCallbackData(cmd, args...).ToBase64()
return b
}
// SetCallbackDataCompact sets a structured callback payload encoded as compact text.
func (b InlineKeyboardButtonBuilder) SetCallbackDataCompact(cmd string, args ...any) InlineKeyboardButtonBuilder {
b.url = ""
b.data = NewCallbackData(cmd, args...).ToCompact()
return b
}
// SetCallbackDataCompactBase64 sets a compact callback payload encoded as Base64.
func (b InlineKeyboardButtonBuilder) SetCallbackDataCompactBase64(cmd string, args ...any) InlineKeyboardButtonBuilder {
b.url = ""
b.data = NewCallbackData(cmd, args...).ToCompactBase64()
return b
}
@@ -106,6 +112,7 @@ func (b InlineKeyboardButtonBuilder) SetCallbackDataCompactBase64(cmd string, ar
// SetCallbackData sets a structured callback payload using the configured payload type.
// The default payload type is JSON.
func (b InlineKeyboardButtonBuilder) SetCallbackData(cmd string, args ...any) InlineKeyboardButtonBuilder {
b.url = ""
switch b.payloadType {
case BotPayloadJSON:
b.data = NewCallbackData(cmd, args...).ToJSON()
@@ -269,7 +276,11 @@ func (in *InlineKeyboard) Get() *tgapi.ReplyMarkup {
if in.CurrentLine.Len() > 0 {
in.AddLine()
}
return &tgapi.ReplyMarkup{InlineKeyboard: in.Lines}
lines := make([][]tgapi.InlineKeyboardButton, len(in.Lines))
for i := range in.Lines {
lines[i] = append([]tgapi.InlineKeyboardButton(nil), in.Lines[i]...)
}
return &tgapi.ReplyMarkup{InlineKeyboard: lines}
}
// CallbackData represents the structured payload sent when an inline button
@@ -297,10 +308,7 @@ func NewCallbackData(command string, args ...any) CallbackData {
for i, arg := range args {
stringArgs[i] = fmt.Sprint(arg)
}
return CallbackData{
Command: command,
Args: stringArgs,
}
return CallbackData{Command: command, Args: stringArgs}
}
// All To* encoders return an empty string when serialization fails. Telegram