feat(tgapi): add context-aware API/uploader methods and align params/docs with Telegram Bot API
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package tgapi
|
||||
|
||||
import "context"
|
||||
|
||||
// SendPhotoP holds parameters for the sendPhoto method.
|
||||
// See https://core.telegram.org/bots/api#sendphoto
|
||||
type SendPhotoP struct {
|
||||
@@ -32,6 +34,14 @@ func (api *API) SendPhoto(params SendPhotoP) (Message, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendPhotoWithContext is the context-aware variant of SendPhoto.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#sendphoto
|
||||
func (api *API) SendPhotoWithContext(ctx context.Context, params SendPhotoP) (Message, error) {
|
||||
req := NewRequestWithChatID[Message]("sendPhoto", params, params.ChatID)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendAudioP holds parameters for the sendAudio method.
|
||||
// See https://core.telegram.org/bots/api#sendaudio
|
||||
type SendAudioP struct {
|
||||
@@ -47,6 +57,7 @@ type SendAudioP struct {
|
||||
Duration int `json:"duration,omitempty"`
|
||||
Performer string `json:"performer,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Thumbnail string `json:"thumbnail,omitempty"`
|
||||
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
ProtectContent bool `json:"protect_content,omitempty"`
|
||||
@@ -65,6 +76,14 @@ func (api *API) SendAudio(params SendAudioP) (Message, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendAudioWithContext is the context-aware variant of SendAudio.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#sendaudio
|
||||
func (api *API) SendAudioWithContext(ctx context.Context, params SendAudioP) (Message, error) {
|
||||
req := NewRequestWithChatID[Message]("sendAudio", params, params.ChatID)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendDocumentP holds parameters for the sendDocument method.
|
||||
// See https://core.telegram.org/bots/api#senddocument
|
||||
type SendDocumentP struct {
|
||||
@@ -73,10 +92,12 @@ type SendDocumentP struct {
|
||||
MessageThreadID int `json:"message_thread_id,omitempty"`
|
||||
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
|
||||
|
||||
Document string `json:"document"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode ParseMode `json:"parse_mode,omitempty"`
|
||||
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
|
||||
Document string `json:"document"`
|
||||
Thumbnail string `json:"thumbnail,omitempty"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode ParseMode `json:"parse_mode,omitempty"`
|
||||
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
|
||||
DisableContentTypeDetection bool `json:"disable_content_type_detection,omitempty"`
|
||||
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
ProtectContent bool `json:"protect_content,omitempty"`
|
||||
@@ -95,6 +116,14 @@ func (api *API) SendDocument(params SendDocumentP) (Message, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendDocumentWithContext is the context-aware variant of SendDocument.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#senddocument
|
||||
func (api *API) SendDocumentWithContext(ctx context.Context, params SendDocumentP) (Message, error) {
|
||||
req := NewRequestWithChatID[Message]("sendDocument", params, params.ChatID)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendVideoP holds parameters for the sendVideo method.
|
||||
// See https://core.telegram.org/bots/api#sendvideo
|
||||
type SendVideoP struct {
|
||||
@@ -103,11 +132,12 @@ type SendVideoP struct {
|
||||
MessageThreadID int `json:"message_thread_id,omitempty"`
|
||||
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
|
||||
|
||||
Video string `json:"video"`
|
||||
Duration int `json:"duration,omitempty"`
|
||||
Width int `json:"width,omitempty"`
|
||||
Height int `json:"height,omitempty"`
|
||||
Cover string `json:"cover,omitempty"`
|
||||
Video string `json:"video"`
|
||||
Thumbnail string `json:"thumbnail,omitempty"`
|
||||
Duration int `json:"duration,omitempty"`
|
||||
Width int `json:"width,omitempty"`
|
||||
Height int `json:"height,omitempty"`
|
||||
Cover string `json:"cover,omitempty"`
|
||||
|
||||
StartTimestamp int `json:"start_timestamp,omitempty"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
@@ -134,6 +164,14 @@ func (api *API) SendVideo(params SendVideoP) (Message, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendVideoWithContext is the context-aware variant of SendVideo.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#sendvideo
|
||||
func (api *API) SendVideoWithContext(ctx context.Context, params SendVideoP) (Message, error) {
|
||||
req := NewRequestWithChatID[Message]("sendVideo", params, params.ChatID)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendAnimationP holds parameters for the sendAnimation method.
|
||||
// See https://core.telegram.org/bots/api#sendanimation
|
||||
type SendAnimationP struct {
|
||||
@@ -143,6 +181,7 @@ type SendAnimationP struct {
|
||||
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
|
||||
|
||||
Animation string `json:"animation"`
|
||||
Thumbnail string `json:"thumbnail,omitempty"`
|
||||
Duration int `json:"duration,omitempty"`
|
||||
Width int `json:"width,omitempty"`
|
||||
Height int `json:"height,omitempty"`
|
||||
@@ -169,6 +208,14 @@ func (api *API) SendAnimation(params SendAnimationP) (Message, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendAnimationWithContext is the context-aware variant of SendAnimation.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#sendanimation
|
||||
func (api *API) SendAnimationWithContext(ctx context.Context, params SendAnimationP) (Message, error) {
|
||||
req := NewRequestWithChatID[Message]("sendAnimation", params, params.ChatID)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendVoiceP holds parameters for the sendVoice method.
|
||||
// See https://core.telegram.org/bots/api#sendvoice
|
||||
type SendVoiceP struct {
|
||||
@@ -199,6 +246,14 @@ func (api *API) SendVoice(params *SendVoiceP) (Message, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendVoiceWithContext is the context-aware variant of SendVoice.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#sendvoice
|
||||
func (api *API) SendVoiceWithContext(ctx context.Context, params *SendVoiceP) (Message, error) {
|
||||
req := NewRequestWithChatID[Message]("sendVoice", params, params.ChatID)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendVideoNoteP holds parameters for the sendVideoNote method.
|
||||
// See https://core.telegram.org/bots/api#sendvideonote
|
||||
type SendVideoNoteP struct {
|
||||
@@ -208,6 +263,7 @@ type SendVideoNoteP struct {
|
||||
DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"`
|
||||
|
||||
VideoNote string `json:"video_note"`
|
||||
Thumbnail string `json:"thumbnail,omitempty"`
|
||||
Duration int `json:"duration,omitempty"`
|
||||
Length int `json:"length,omitempty"`
|
||||
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||
@@ -227,6 +283,14 @@ func (api *API) SendVideoNote(params SendVideoNoteP) (Message, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendVideoNoteWithContext is the context-aware variant of SendVideoNote.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#sendvideonote
|
||||
func (api *API) SendVideoNoteWithContext(ctx context.Context, params SendVideoNoteP) (Message, error) {
|
||||
req := NewRequestWithChatID[Message]("sendVideoNote", params, params.ChatID)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendPaidMediaP holds parameters for the sendPaidMedia method.
|
||||
// See https://core.telegram.org/bots/api#sendpaidmedia
|
||||
type SendPaidMediaP struct {
|
||||
@@ -258,6 +322,14 @@ func (api *API) SendPaidMedia(params SendPaidMediaP) (Message, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendPaidMediaWithContext is the context-aware variant of SendPaidMedia.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#sendpaidmedia
|
||||
func (api *API) SendPaidMediaWithContext(ctx context.Context, params SendPaidMediaP) (Message, error) {
|
||||
req := NewRequestWithChatID[Message]("sendPaidMedia", params, params.ChatID)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendMediaGroupP holds parameters for the sendMediaGroup method.
|
||||
// See https://core.telegram.org/bots/api#sendmediagroup
|
||||
type SendMediaGroupP struct {
|
||||
@@ -280,3 +352,11 @@ func (api *API) SendMediaGroup(params SendMediaGroupP) ([]Message, error) {
|
||||
req := NewRequestWithChatID[[]Message]("sendMediaGroup", params, params.ChatID)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendMediaGroupWithContext is the context-aware variant of SendMediaGroup.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#sendmediagroup
|
||||
func (api *API) SendMediaGroupWithContext(ctx context.Context, params SendMediaGroupP) ([]Message, error) {
|
||||
req := NewRequestWithChatID[[]Message]("sendMediaGroup", params, params.ChatID)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user