(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
+89 -8
View File
@@ -2,6 +2,45 @@ package tgapi
import "context"
// SendRichMessage uploads files referenced by attach:// names in params.RichMessage
// and sends the rich message.
//
// Since: Bot API 10.2
func (u *Uploader) SendRichMessage(params SendRichMessage, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendRichMessage", params, params.ChatID, files...)
return req.Do(u)
}
// SendRichMessageWithContext uploads files referenced by attach:// names in params.RichMessage
// and sends the rich message using ctx for cancellation and deadlines.
//
// Since: Bot API 10.2
func (u *Uploader) SendRichMessageWithContext(ctx context.Context, params SendRichMessage, files ...UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendRichMessage", params, params.ChatID, files...)
return req.DoWithContext(ctx, u)
}
// SendRichMessageDraft streams a rich-message draft without direct file uploads.
// It returns ErrRichMessageDraftUploadUnsupported when files is non-empty.
//
// Since: Bot API 10.2
func (u *Uploader) SendRichMessageDraft(params SendRichMessageDraft, files ...UploaderFile) (bool, error) {
if len(files) > 0 {
return false, ErrRichMessageDraftUploadUnsupported
}
return u.api.SendRichMessageDraft(params)
}
// SendRichMessageDraftWithContext is the context-aware variant of SendRichMessageDraft.
//
// Since: Bot API 10.2
func (u *Uploader) SendRichMessageDraftWithContext(ctx context.Context, params SendRichMessageDraft, files ...UploaderFile) (bool, error) {
if len(files) > 0 {
return false, ErrRichMessageDraftUploadUnsupported
}
return u.api.SendRichMessageDraftWithContext(ctx, params)
}
// UploadPhoto holds parameters for uploading a photo using the Uploader.
// Since: Bot API 1.0
// See https://core.telegram.org/bots/api#sendphoto
@@ -10,6 +49,10 @@ type UploadPhoto struct {
ChatID int64 `json:"chat_id"`
MessageThreadID int `json:"message_thread_id,omitempty"`
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
Caption string `json:"caption,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
@@ -53,6 +96,10 @@ type UploadAudio struct {
ChatID int64 `json:"chat_id"`
MessageThreadID int `json:"message_thread_id,omitempty"`
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
Caption string `json:"caption,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
@@ -98,6 +145,10 @@ type UploadDocument struct {
ChatID int64 `json:"chat_id"`
MessageThreadID int `json:"message_thread_id,omitempty"`
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
Caption string `json:"caption,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
@@ -140,6 +191,10 @@ type UploadVideo struct {
ChatID int64 `json:"chat_id"`
MessageThreadID int `json:"message_thread_id,omitempty"`
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
Duration int `json:"duration,omitempty"`
Width int `json:"width,omitempty"`
@@ -189,6 +244,10 @@ type UploadAnimation struct {
ChatID int64 `json:"chat_id"`
MessageThreadID int `json:"message_thread_id,omitempty"`
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
Duration int `json:"duration,omitempty"`
Width int `json:"width,omitempty"`
@@ -236,6 +295,10 @@ type UploadVoice struct {
ChatID int64 `json:"chat_id"`
MessageThreadID int `json:"message_thread_id,omitempty"`
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
Caption string `json:"caption,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
@@ -278,6 +341,10 @@ type UploadVideoNote struct {
ChatID int64 `json:"chat_id"`
MessageThreadID int `json:"message_thread_id,omitempty"`
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
Duration int `json:"duration,omitempty"`
Length int `json:"length,omitempty"`
@@ -375,6 +442,10 @@ type UploadLivePhoto struct {
MessageThreadID int `json:"message_thread_id,omitempty"`
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
// ReceiverUserID identifies the user who can see the ephemeral message.
ReceiverUserID int64 `json:"receiver_user_id,omitempty"` // Since: Bot API 10.2
// CallbackQueryID identifies the callback query that triggered an ephemeral response.
CallbackQueryID string `json:"callback_query_id,omitempty"` // Since: Bot API 10.2
Caption string `json:"caption,omitempty"`
ParseMode ParseMode `json:"parse_mode,omitempty"`
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
@@ -391,20 +462,30 @@ type UploadLivePhoto struct {
ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"`
}
// SendLivePhoto uploads a live photo via multipart and sends it as a message.
// SendLivePhoto uploads a live-photo video and its static image via multipart.
// livePhoto is sent in the live_photo field and photo in the photo field.
// Since: Bot API 10.0
// file is the live photo file to upload.
// See https://core.telegram.org/bots/api#sendlivephoto
func (u *Uploader) SendLivePhoto(params UploadLivePhoto, file UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendLivePhoto", params, params.ChatID, file.SetType(UploaderLivePhotoType))
func (u *Uploader) SendLivePhoto(params UploadLivePhoto, livePhoto, photo UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message](
"sendLivePhoto", params, params.ChatID,
livePhoto.SetType(UploaderLivePhotoType),
photo.SetType(UploaderPhotoType),
)
return req.Do(u)
}
// SendLivePhotoWithContext is the context-aware variant of SendLivePhoto.
// SendLivePhotoWithContext uploads a live-photo video and its static image via
// multipart using ctx for cancellation and deadlines.
// Since: Bot API 10.0
// It executes the same request but uses ctx for cancellation and deadlines.
// See https://core.telegram.org/bots/api#sendlivephoto
func (u *Uploader) SendLivePhotoWithContext(ctx context.Context, params UploadLivePhoto, file UploaderFile) (Message, error) {
req := NewUploaderRequestWithChatID[Message]("sendLivePhoto", params, params.ChatID, file.SetType(UploaderLivePhotoType))
func (u *Uploader) SendLivePhotoWithContext(
ctx context.Context, params UploadLivePhoto, livePhoto, photo UploaderFile,
) (Message, error) {
req := NewUploaderRequestWithChatID[Message](
"sendLivePhoto", params, params.ChatID,
livePhoto.SetType(UploaderLivePhotoType),
photo.SetType(UploaderPhotoType),
)
return req.DoWithContext(ctx, u)
}