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"
|
||||
|
||||
// SetMyCommandsP holds parameters for the setMyCommands method.
|
||||
// See https://core.telegram.org/bots/api#setmycommands
|
||||
type SetMyCommandsP struct {
|
||||
@@ -16,6 +18,14 @@ func (api *API) SetMyCommands(params SetMyCommandsP) (bool, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetMyCommandsWithContext is the context-aware variant of SetMyCommands.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#setmycommands
|
||||
func (api *API) SetMyCommandsWithContext(ctx context.Context, params SetMyCommandsP) (bool, error) {
|
||||
req := NewRequest[bool]("setMyCommands", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// DeleteMyCommandsP holds parameters for the deleteMyCommands method.
|
||||
// See https://core.telegram.org/bots/api#deletemycommands
|
||||
type DeleteMyCommandsP struct {
|
||||
@@ -31,6 +41,14 @@ func (api *API) DeleteMyCommands(params DeleteMyCommandsP) (bool, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// DeleteMyCommandsWithContext is the context-aware variant of DeleteMyCommands.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#deletemycommands
|
||||
func (api *API) DeleteMyCommandsWithContext(ctx context.Context, params DeleteMyCommandsP) (bool, error) {
|
||||
req := NewRequest[bool]("deleteMyCommands", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetMyCommands holds parameters for the getMyCommands method.
|
||||
// See https://core.telegram.org/bots/api#getmycommands
|
||||
type GetMyCommands struct {
|
||||
@@ -45,6 +63,14 @@ func (api *API) GetMyCommands(params GetMyCommands) ([]BotCommand, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetMyCommandsWithContext is the context-aware variant of GetMyCommands.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#getmycommands
|
||||
func (api *API) GetMyCommandsWithContext(ctx context.Context, params GetMyCommands) ([]BotCommand, error) {
|
||||
req := NewRequest[[]BotCommand]("getMyCommands", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetMyName holds parameters for the setMyName method.
|
||||
// See https://core.telegram.org/bots/api#setmyname
|
||||
type SetMyName struct {
|
||||
@@ -60,6 +86,14 @@ func (api *API) SetMyName(params SetMyName) (bool, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetMyNameWithContext is the context-aware variant of SetMyName.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#setmyname
|
||||
func (api *API) SetMyNameWithContext(ctx context.Context, params SetMyName) (bool, error) {
|
||||
req := NewRequest[bool]("setMyName", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetMyName holds parameters for the getMyName method.
|
||||
// See https://core.telegram.org/bots/api#getmyname
|
||||
type GetMyName struct {
|
||||
@@ -73,6 +107,14 @@ func (api *API) GetMyName(params GetMyName) (BotName, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetMyNameWithContext is the context-aware variant of GetMyName.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#getmyname
|
||||
func (api *API) GetMyNameWithContext(ctx context.Context, params GetMyName) (BotName, error) {
|
||||
req := NewRequest[BotName]("getMyName", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetMyDescription holds parameters for the setMyDescription method.
|
||||
// See https://core.telegram.org/bots/api#setmydescription
|
||||
type SetMyDescription struct {
|
||||
@@ -88,6 +130,14 @@ func (api *API) SetMyDescription(params SetMyDescription) (bool, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetMyDescriptionWithContext is the context-aware variant of SetMyDescription.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#setmydescription
|
||||
func (api *API) SetMyDescriptionWithContext(ctx context.Context, params SetMyDescription) (bool, error) {
|
||||
req := NewRequest[bool]("setMyDescription", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetMyDescription holds parameters for the getMyDescription method.
|
||||
// See https://core.telegram.org/bots/api#getmydescription
|
||||
type GetMyDescription struct {
|
||||
@@ -101,6 +151,14 @@ func (api *API) GetMyDescription(params GetMyDescription) (BotDescription, error
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetMyDescriptionWithContext is the context-aware variant of GetMyDescription.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#getmydescription
|
||||
func (api *API) GetMyDescriptionWithContext(ctx context.Context, params GetMyDescription) (BotDescription, error) {
|
||||
req := NewRequest[BotDescription]("getMyDescription", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetMyShortDescription holds parameters for the setMyShortDescription method.
|
||||
// See https://core.telegram.org/bots/api#setmyshortdescription
|
||||
type SetMyShortDescription struct {
|
||||
@@ -116,6 +174,14 @@ func (api *API) SetMyShortDescription(params SetMyShortDescription) (bool, error
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetMyShortDescriptionWithContext is the context-aware variant of SetMyShortDescription.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#setmyshortdescription
|
||||
func (api *API) SetMyShortDescriptionWithContext(ctx context.Context, params SetMyShortDescription) (bool, error) {
|
||||
req := NewRequest[bool]("setMyShortDescription", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetMyShortDescription holds parameters for the getMyShortDescription method.
|
||||
// See https://core.telegram.org/bots/api#getmyshortdescription
|
||||
type GetMyShortDescription struct {
|
||||
@@ -129,6 +195,14 @@ func (api *API) GetMyShortDescription(params GetMyShortDescription) (BotShortDes
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetMyShortDescriptionWithContext is the context-aware variant of GetMyShortDescription.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#getmyshortdescription
|
||||
func (api *API) GetMyShortDescriptionWithContext(ctx context.Context, params GetMyShortDescription) (BotShortDescription, error) {
|
||||
req := NewRequest[BotShortDescription]("getMyShortDescription", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetMyProfilePhotoP holds parameters for the setMyProfilePhoto method.
|
||||
// See https://core.telegram.org/bots/api#setmyprofilephoto
|
||||
type SetMyProfilePhotoP struct {
|
||||
@@ -143,6 +217,14 @@ func (api *API) SetMyProfilePhoto(params SetMyProfilePhotoP) (bool, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetMyProfilePhotoWithContext is the context-aware variant of SetMyProfilePhoto.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#setmyprofilephoto
|
||||
func (api *API) SetMyProfilePhotoWithContext(ctx context.Context, params SetMyProfilePhotoP) (bool, error) {
|
||||
req := NewRequest[bool]("setMyProfilePhoto", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// RemoveMyProfilePhoto removes the bot's profile photo.
|
||||
// Returns true on success.
|
||||
// See https://core.telegram.org/bots/api#removemyprofilephoto
|
||||
@@ -151,6 +233,14 @@ func (api *API) RemoveMyProfilePhoto() (bool, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// RemoveMyProfilePhotoWithContext is the context-aware variant of RemoveMyProfilePhoto.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#removemyprofilephoto
|
||||
func (api *API) RemoveMyProfilePhotoWithContext(ctx context.Context) (bool, error) {
|
||||
req := NewRequest[bool]("removeMyProfilePhoto", NoParams)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetChatMenuButtonP holds parameters for the setChatMenuButton method.
|
||||
// See https://core.telegram.org/bots/api#setchatmenubutton
|
||||
type SetChatMenuButtonP struct {
|
||||
@@ -166,6 +256,14 @@ func (api *API) SetChatMenuButton(params SetChatMenuButtonP) (bool, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetChatMenuButtonWithContext is the context-aware variant of SetChatMenuButton.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#setchatmenubutton
|
||||
func (api *API) SetChatMenuButtonWithContext(ctx context.Context, params SetChatMenuButtonP) (bool, error) {
|
||||
req := NewRequest[bool]("setChatMenuButton", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetChatMenuButtonP holds parameters for the getChatMenuButton method.
|
||||
// See https://core.telegram.org/bots/api#getchatmenubutton
|
||||
type GetChatMenuButtonP struct {
|
||||
@@ -179,6 +277,14 @@ func (api *API) GetChatMenuButton(params GetChatMenuButtonP) (BaseMenuButton, er
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetChatMenuButtonWithContext is the context-aware variant of GetChatMenuButton.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#getchatmenubutton
|
||||
func (api *API) GetChatMenuButtonWithContext(ctx context.Context, params GetChatMenuButtonP) (BaseMenuButton, error) {
|
||||
req := NewRequest[BaseMenuButton]("getChatMenuButton", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SetMyDefaultAdministratorRightsP holds parameters for the setMyDefaultAdministratorRights method.
|
||||
// See https://core.telegram.org/bots/api#setmydefaultadministratorrights
|
||||
type SetMyDefaultAdministratorRightsP struct {
|
||||
@@ -194,6 +300,14 @@ func (api *API) SetMyDefaultAdministratorRights(params SetMyDefaultAdministrator
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SetMyDefaultAdministratorRightsWithContext is the context-aware variant of SetMyDefaultAdministratorRights.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#setmydefaultadministratorrights
|
||||
func (api *API) SetMyDefaultAdministratorRightsWithContext(ctx context.Context, params SetMyDefaultAdministratorRightsP) (bool, error) {
|
||||
req := NewRequest[bool]("setMyDefaultAdministratorRights", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetMyDefaultAdministratorRightsP holds parameters for the getMyDefaultAdministratorRights method.
|
||||
// See https://core.telegram.org/bots/api#getmydefaultadministratorrights
|
||||
type GetMyDefaultAdministratorRightsP struct {
|
||||
@@ -207,6 +321,14 @@ func (api *API) GetMyDefaultAdministratorRights(params GetMyDefaultAdministrator
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetMyDefaultAdministratorRightsWithContext is the context-aware variant of GetMyDefaultAdministratorRights.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#getmydefaultadministratorrights
|
||||
func (api *API) GetMyDefaultAdministratorRightsWithContext(ctx context.Context, params GetMyDefaultAdministratorRightsP) (ChatAdministratorRights, error) {
|
||||
req := NewRequest[ChatAdministratorRights]("getMyDefaultAdministratorRights", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GetAvailableGifts returns the list of gifts that can be sent by the bot.
|
||||
// See https://core.telegram.org/bots/api#getavailablegifts
|
||||
func (api *API) GetAvailableGifts() (Gifts, error) {
|
||||
@@ -214,6 +336,14 @@ func (api *API) GetAvailableGifts() (Gifts, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GetAvailableGiftsWithContext is the context-aware variant of GetAvailableGifts.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#getavailablegifts
|
||||
func (api *API) GetAvailableGiftsWithContext(ctx context.Context) (Gifts, error) {
|
||||
req := NewRequest[Gifts]("getAvailableGifts", NoParams)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// SendGiftP holds parameters for the sendGift method.
|
||||
// See https://core.telegram.org/bots/api#sendgift
|
||||
type SendGiftP struct {
|
||||
@@ -234,6 +364,14 @@ func (api *API) SendGift(params SendGiftP) (bool, error) {
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// SendGiftWithContext is the context-aware variant of SendGift.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#sendgift
|
||||
func (api *API) SendGiftWithContext(ctx context.Context, params SendGiftP) (bool, error) {
|
||||
req := NewRequest[bool]("sendGift", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
// GiftPremiumSubscriptionP holds parameters for the giftPremiumSubscription method.
|
||||
// See https://core.telegram.org/bots/api#giftpremiumsubscription
|
||||
type GiftPremiumSubscriptionP struct {
|
||||
@@ -252,3 +390,11 @@ func (api *API) GiftPremiumSubscription(params GiftPremiumSubscriptionP) (bool,
|
||||
req := NewRequest[bool]("giftPremiumSubscription", params)
|
||||
return req.Do(api)
|
||||
}
|
||||
|
||||
// GiftPremiumSubscriptionWithContext is the context-aware variant of GiftPremiumSubscription.
|
||||
// It executes the same request but uses ctx for cancellation and deadlines.
|
||||
// See https://core.telegram.org/bots/api#giftpremiumsubscription
|
||||
func (api *API) GiftPremiumSubscriptionWithContext(ctx context.Context, params GiftPremiumSubscriptionP) (bool, error) {
|
||||
req := NewRequest[bool]("giftPremiumSubscription", params)
|
||||
return req.DoWithContext(ctx, api)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user