mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-06-10 23:09:04 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5523ed2b06 |
+55
-208
@@ -4,100 +4,40 @@
|
|||||||
|
|
||||||
package api
|
package api
|
||||||
|
|
||||||
type BackgroundFillFreeformGradientType string
|
type BackgroundFillType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BackgroundFillFreeformGradientTypeFreeformGradient BackgroundFillFreeformGradientType = "freeform_gradient"
|
BackgroundFillTypeSolid BackgroundFillType = "solid"
|
||||||
|
BackgroundFillTypeGradient BackgroundFillType = "gradient"
|
||||||
|
BackgroundFillTypeFreeformGradient BackgroundFillType = "freeform_gradient"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BackgroundFillGradientType string
|
type BackgroundTypeKind string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BackgroundFillGradientTypeGradient BackgroundFillGradientType = "gradient"
|
BackgroundTypeKindFill BackgroundTypeKind = "fill"
|
||||||
|
BackgroundTypeKindWallpaper BackgroundTypeKind = "wallpaper"
|
||||||
|
BackgroundTypeKindPattern BackgroundTypeKind = "pattern"
|
||||||
|
BackgroundTypeKindChatTheme BackgroundTypeKind = "chat_theme"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BackgroundFillSolidType string
|
type ChatBoostSourceKind string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BackgroundFillSolidTypeSolid BackgroundFillSolidType = "solid"
|
ChatBoostSourceKindPremium ChatBoostSourceKind = "premium"
|
||||||
|
ChatBoostSourceKindGiftCode ChatBoostSourceKind = "gift_code"
|
||||||
|
ChatBoostSourceKindGiveaway ChatBoostSourceKind = "giveaway"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BackgroundTypeChatThemeType string
|
type ChatMemberStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BackgroundTypeChatThemeTypeChatTheme BackgroundTypeChatThemeType = "chat_theme"
|
ChatMemberStatusCreator ChatMemberStatus = "creator"
|
||||||
)
|
ChatMemberStatusAdministrator ChatMemberStatus = "administrator"
|
||||||
|
ChatMemberStatusMember ChatMemberStatus = "member"
|
||||||
type BackgroundTypeFillType string
|
ChatMemberStatusRestricted ChatMemberStatus = "restricted"
|
||||||
|
ChatMemberStatusLeft ChatMemberStatus = "left"
|
||||||
const (
|
ChatMemberStatusKicked ChatMemberStatus = "kicked"
|
||||||
BackgroundTypeFillTypeFill BackgroundTypeFillType = "fill"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BackgroundTypePatternType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
BackgroundTypePatternTypePattern BackgroundTypePatternType = "pattern"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BackgroundTypeWallpaperType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
BackgroundTypeWallpaperTypeWallpaper BackgroundTypeWallpaperType = "wallpaper"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatBoostSourceGiftCodeSource string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ChatBoostSourceGiftCodeSourceGiftCode ChatBoostSourceGiftCodeSource = "gift_code"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatBoostSourceGiveawaySource string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ChatBoostSourceGiveawaySourceGiveaway ChatBoostSourceGiveawaySource = "giveaway"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatBoostSourcePremiumSource string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ChatBoostSourcePremiumSourcePremium ChatBoostSourcePremiumSource = "premium"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatMemberAdministratorStatus string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ChatMemberAdministratorStatusAdministrator ChatMemberAdministratorStatus = "administrator"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatMemberBannedStatus string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ChatMemberBannedStatusKicked ChatMemberBannedStatus = "kicked"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatMemberLeftStatus string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ChatMemberLeftStatusLeft ChatMemberLeftStatus = "left"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatMemberMemberStatus string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ChatMemberMemberStatusMember ChatMemberMemberStatus = "member"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatMemberOwnerStatus string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ChatMemberOwnerStatusCreator ChatMemberOwnerStatus = "creator"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatMemberRestrictedStatus string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ChatMemberRestrictedStatusRestricted ChatMemberRestrictedStatus = "restricted"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ChatType string
|
type ChatType string
|
||||||
@@ -202,64 +142,29 @@ const (
|
|||||||
MessageEntityTypeDateTime MessageEntityType = "date_time"
|
MessageEntityTypeDateTime MessageEntityType = "date_time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MessageOriginChannelType string
|
type MessageOriginType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MessageOriginChannelTypeChannel MessageOriginChannelType = "channel"
|
MessageOriginTypeUser MessageOriginType = "user"
|
||||||
|
MessageOriginTypeHiddenUser MessageOriginType = "hidden_user"
|
||||||
|
MessageOriginTypeChat MessageOriginType = "chat"
|
||||||
|
MessageOriginTypeChannel MessageOriginType = "channel"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MessageOriginChatType string
|
type OwnedGiftType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MessageOriginChatTypeChat MessageOriginChatType = "chat"
|
OwnedGiftTypeRegular OwnedGiftType = "regular"
|
||||||
|
OwnedGiftTypeUnique OwnedGiftType = "unique"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MessageOriginHiddenUserType string
|
type PaidMediaType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MessageOriginHiddenUserTypeHiddenUser MessageOriginHiddenUserType = "hidden_user"
|
PaidMediaTypeLivePhoto PaidMediaType = "live_photo"
|
||||||
)
|
PaidMediaTypePhoto PaidMediaType = "photo"
|
||||||
|
PaidMediaTypePreview PaidMediaType = "preview"
|
||||||
type MessageOriginUserType string
|
PaidMediaTypeVideo PaidMediaType = "video"
|
||||||
|
|
||||||
const (
|
|
||||||
MessageOriginUserTypeUser MessageOriginUserType = "user"
|
|
||||||
)
|
|
||||||
|
|
||||||
type OwnedGiftRegularType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
OwnedGiftRegularTypeRegular OwnedGiftRegularType = "regular"
|
|
||||||
)
|
|
||||||
|
|
||||||
type OwnedGiftUniqueType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
OwnedGiftUniqueTypeUnique OwnedGiftUniqueType = "unique"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PaidMediaLivePhotoType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
PaidMediaLivePhotoTypeLivePhoto PaidMediaLivePhotoType = "live_photo"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PaidMediaPhotoType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
PaidMediaPhotoTypePhoto PaidMediaPhotoType = "photo"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PaidMediaPreviewType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
PaidMediaPreviewTypePreview PaidMediaPreviewType = "preview"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PaidMediaVideoType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
PaidMediaVideoTypeVideo PaidMediaVideoType = "video"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ParseMode string
|
type ParseMode string
|
||||||
@@ -328,22 +233,12 @@ const (
|
|||||||
PollTypeQuiz PollType = "quiz"
|
PollTypeQuiz PollType = "quiz"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReactionTypeCustomEmojiType string
|
type ReactionTypeKind string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ReactionTypeCustomEmojiTypeCustomEmoji ReactionTypeCustomEmojiType = "custom_emoji"
|
ReactionTypeKindEmoji ReactionTypeKind = "emoji"
|
||||||
)
|
ReactionTypeKindCustomEmoji ReactionTypeKind = "custom_emoji"
|
||||||
|
ReactionTypeKindPaid ReactionTypeKind = "paid"
|
||||||
type ReactionTypeEmojiType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ReactionTypeEmojiTypeEmoji ReactionTypeEmojiType = "emoji"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ReactionTypePaidType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ReactionTypePaidTypePaid ReactionTypePaidType = "paid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type RefundedPaymentCurrency string
|
type RefundedPaymentCurrency string
|
||||||
@@ -352,22 +247,12 @@ const (
|
|||||||
RefundedPaymentCurrencyXTR RefundedPaymentCurrency = "XTR"
|
RefundedPaymentCurrencyXTR RefundedPaymentCurrency = "XTR"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RevenueWithdrawalStateFailedType string
|
type RevenueWithdrawalStateKind string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RevenueWithdrawalStateFailedTypeFailed RevenueWithdrawalStateFailedType = "failed"
|
RevenueWithdrawalStateKindPending RevenueWithdrawalStateKind = "pending"
|
||||||
)
|
RevenueWithdrawalStateKindSucceeded RevenueWithdrawalStateKind = "succeeded"
|
||||||
|
RevenueWithdrawalStateKindFailed RevenueWithdrawalStateKind = "failed"
|
||||||
type RevenueWithdrawalStatePendingType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
RevenueWithdrawalStatePendingTypePending RevenueWithdrawalStatePendingType = "pending"
|
|
||||||
)
|
|
||||||
|
|
||||||
type RevenueWithdrawalStateSucceededType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
RevenueWithdrawalStateSucceededTypeSucceeded RevenueWithdrawalStateSucceededType = "succeeded"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type StickerType string
|
type StickerType string
|
||||||
@@ -378,34 +263,14 @@ const (
|
|||||||
StickerTypeCustomEmoji StickerType = "custom_emoji"
|
StickerTypeCustomEmoji StickerType = "custom_emoji"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StoryAreaTypeLinkType string
|
type StoryAreaTypeKind string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
StoryAreaTypeLinkTypeLink StoryAreaTypeLinkType = "link"
|
StoryAreaTypeKindLocation StoryAreaTypeKind = "location"
|
||||||
)
|
StoryAreaTypeKindSuggestedReaction StoryAreaTypeKind = "suggested_reaction"
|
||||||
|
StoryAreaTypeKindLink StoryAreaTypeKind = "link"
|
||||||
type StoryAreaTypeLocationType string
|
StoryAreaTypeKindWeather StoryAreaTypeKind = "weather"
|
||||||
|
StoryAreaTypeKindUniqueGift StoryAreaTypeKind = "unique_gift"
|
||||||
const (
|
|
||||||
StoryAreaTypeLocationTypeLocation StoryAreaTypeLocationType = "location"
|
|
||||||
)
|
|
||||||
|
|
||||||
type StoryAreaTypeSuggestedReactionType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
StoryAreaTypeSuggestedReactionTypeSuggestedReaction StoryAreaTypeSuggestedReactionType = "suggested_reaction"
|
|
||||||
)
|
|
||||||
|
|
||||||
type StoryAreaTypeUniqueGiftType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
StoryAreaTypeUniqueGiftTypeUniqueGift StoryAreaTypeUniqueGiftType = "unique_gift"
|
|
||||||
)
|
|
||||||
|
|
||||||
type StoryAreaTypeWeatherType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
StoryAreaTypeWeatherTypeWeather StoryAreaTypeWeatherType = "weather"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SuggestedPostInfoState string
|
type SuggestedPostInfoState string
|
||||||
@@ -430,34 +295,16 @@ const (
|
|||||||
SuggestedPostRefundedReasonPaymentRefunded SuggestedPostRefundedReason = "payment_refunded"
|
SuggestedPostRefundedReasonPaymentRefunded SuggestedPostRefundedReason = "payment_refunded"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransactionPartnerAffiliateProgramType string
|
type TransactionPartnerType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TransactionPartnerAffiliateProgramTypeAffiliateProgram TransactionPartnerAffiliateProgramType = "affiliate_program"
|
TransactionPartnerTypeUser TransactionPartnerType = "user"
|
||||||
)
|
TransactionPartnerTypeChat TransactionPartnerType = "chat"
|
||||||
|
TransactionPartnerTypeAffiliateProgram TransactionPartnerType = "affiliate_program"
|
||||||
type TransactionPartnerFragmentType string
|
TransactionPartnerTypeFragment TransactionPartnerType = "fragment"
|
||||||
|
TransactionPartnerTypeTelegramAds TransactionPartnerType = "telegram_ads"
|
||||||
const (
|
TransactionPartnerTypeTelegramApi TransactionPartnerType = "telegram_api"
|
||||||
TransactionPartnerFragmentTypeFragment TransactionPartnerFragmentType = "fragment"
|
TransactionPartnerTypeOther TransactionPartnerType = "other"
|
||||||
)
|
|
||||||
|
|
||||||
type TransactionPartnerOtherType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
TransactionPartnerOtherTypeOther TransactionPartnerOtherType = "other"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TransactionPartnerTelegramAdsType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
TransactionPartnerTelegramAdsTypeTelegramAds TransactionPartnerTelegramAdsType = "telegram_ads"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TransactionPartnerTelegramApiType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
TransactionPartnerTelegramApiTypeTelegramApi TransactionPartnerTelegramApiType = "telegram_api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransactionPartnerUserTransactionType string
|
type TransactionPartnerUserTransactionType string
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func TestMarshalJSON_RoundTrip(t *testing.T) {
|
|||||||
|
|
||||||
round, ok := out.(*ChatMemberLeft)
|
round, ok := out.(*ChatMemberLeft)
|
||||||
require.True(t, ok, "expected *ChatMemberLeft, got %T", out)
|
require.True(t, ok, "expected *ChatMemberLeft, got %T", out)
|
||||||
require.Equal(t, ChatMemberLeftStatusLeft, round.Status)
|
require.Equal(t, ChatMemberStatusLeft, round.Status)
|
||||||
require.Equal(t, orig.User.ID, round.User.ID)
|
require.Equal(t, orig.User.ID, round.User.ID)
|
||||||
require.Equal(t, orig.User.FirstName, round.User.FirstName)
|
require.Equal(t, orig.User.FirstName, round.User.FirstName)
|
||||||
}
|
}
|
||||||
|
|||||||
+44
-44
@@ -800,7 +800,7 @@ func UnmarshalMessageOrigin(data []byte) (MessageOrigin, error) {
|
|||||||
// The message was originally sent by a known user.
|
// The message was originally sent by a known user.
|
||||||
type MessageOriginUser struct {
|
type MessageOriginUser struct {
|
||||||
// Type of the message origin, always “user”
|
// Type of the message origin, always “user”
|
||||||
Type MessageOriginUserType `json:"type"`
|
Type MessageOriginType `json:"type"`
|
||||||
// Date the message was sent originally in Unix time
|
// Date the message was sent originally in Unix time
|
||||||
Date int64 `json:"date"`
|
Date int64 `json:"date"`
|
||||||
// User that sent the message originally
|
// User that sent the message originally
|
||||||
@@ -826,7 +826,7 @@ func (v *MessageOriginUser) MarshalJSON() ([]byte, error) {
|
|||||||
// The message was originally sent by an unknown user.
|
// The message was originally sent by an unknown user.
|
||||||
type MessageOriginHiddenUser struct {
|
type MessageOriginHiddenUser struct {
|
||||||
// Type of the message origin, always “hidden_user”
|
// Type of the message origin, always “hidden_user”
|
||||||
Type MessageOriginHiddenUserType `json:"type"`
|
Type MessageOriginType `json:"type"`
|
||||||
// Date the message was sent originally in Unix time
|
// Date the message was sent originally in Unix time
|
||||||
Date int64 `json:"date"`
|
Date int64 `json:"date"`
|
||||||
// Name of the user that sent the message originally
|
// Name of the user that sent the message originally
|
||||||
@@ -852,7 +852,7 @@ func (v *MessageOriginHiddenUser) MarshalJSON() ([]byte, error) {
|
|||||||
// The message was originally sent on behalf of a chat to a group chat.
|
// The message was originally sent on behalf of a chat to a group chat.
|
||||||
type MessageOriginChat struct {
|
type MessageOriginChat struct {
|
||||||
// Type of the message origin, always “chat”
|
// Type of the message origin, always “chat”
|
||||||
Type MessageOriginChatType `json:"type"`
|
Type MessageOriginType `json:"type"`
|
||||||
// Date the message was sent originally in Unix time
|
// Date the message was sent originally in Unix time
|
||||||
Date int64 `json:"date"`
|
Date int64 `json:"date"`
|
||||||
// Chat that sent the message originally
|
// Chat that sent the message originally
|
||||||
@@ -880,7 +880,7 @@ func (v *MessageOriginChat) MarshalJSON() ([]byte, error) {
|
|||||||
// The message was originally sent to a channel chat.
|
// The message was originally sent to a channel chat.
|
||||||
type MessageOriginChannel struct {
|
type MessageOriginChannel struct {
|
||||||
// Type of the message origin, always “channel”
|
// Type of the message origin, always “channel”
|
||||||
Type MessageOriginChannelType `json:"type"`
|
Type MessageOriginType `json:"type"`
|
||||||
// Date the message was sent originally in Unix time
|
// Date the message was sent originally in Unix time
|
||||||
Date int64 `json:"date"`
|
Date int64 `json:"date"`
|
||||||
// Channel chat to which the message was originally sent
|
// Channel chat to which the message was originally sent
|
||||||
@@ -1174,7 +1174,7 @@ func UnmarshalPaidMedia(data []byte) (PaidMedia, error) {
|
|||||||
// The paid media is a live photo.
|
// The paid media is a live photo.
|
||||||
type PaidMediaLivePhoto struct {
|
type PaidMediaLivePhoto struct {
|
||||||
// Type of the paid media, always “live_photo”
|
// Type of the paid media, always “live_photo”
|
||||||
Type PaidMediaLivePhotoType `json:"type"`
|
Type PaidMediaType `json:"type"`
|
||||||
// The photo
|
// The photo
|
||||||
LivePhoto LivePhoto `json:"live_photo"`
|
LivePhoto LivePhoto `json:"live_photo"`
|
||||||
}
|
}
|
||||||
@@ -1198,7 +1198,7 @@ func (v *PaidMediaLivePhoto) MarshalJSON() ([]byte, error) {
|
|||||||
// The paid media is a photo.
|
// The paid media is a photo.
|
||||||
type PaidMediaPhoto struct {
|
type PaidMediaPhoto struct {
|
||||||
// Type of the paid media, always “photo”
|
// Type of the paid media, always “photo”
|
||||||
Type PaidMediaPhotoType `json:"type"`
|
Type PaidMediaType `json:"type"`
|
||||||
// The photo
|
// The photo
|
||||||
Photo []PhotoSize `json:"photo"`
|
Photo []PhotoSize `json:"photo"`
|
||||||
}
|
}
|
||||||
@@ -1222,7 +1222,7 @@ func (v *PaidMediaPhoto) MarshalJSON() ([]byte, error) {
|
|||||||
// The paid media isn't available before the payment.
|
// The paid media isn't available before the payment.
|
||||||
type PaidMediaPreview struct {
|
type PaidMediaPreview struct {
|
||||||
// Type of the paid media, always “preview”
|
// Type of the paid media, always “preview”
|
||||||
Type PaidMediaPreviewType `json:"type"`
|
Type PaidMediaType `json:"type"`
|
||||||
// Optional. Media width as defined by the sender
|
// Optional. Media width as defined by the sender
|
||||||
Width *int64 `json:"width,omitempty"`
|
Width *int64 `json:"width,omitempty"`
|
||||||
// Optional. Media height as defined by the sender
|
// Optional. Media height as defined by the sender
|
||||||
@@ -1250,7 +1250,7 @@ func (v *PaidMediaPreview) MarshalJSON() ([]byte, error) {
|
|||||||
// The paid media is a video.
|
// The paid media is a video.
|
||||||
type PaidMediaVideo struct {
|
type PaidMediaVideo struct {
|
||||||
// Type of the paid media, always “video”
|
// Type of the paid media, always “video”
|
||||||
Type PaidMediaVideoType `json:"type"`
|
Type PaidMediaType `json:"type"`
|
||||||
// The video
|
// The video
|
||||||
Video Video `json:"video"`
|
Video Video `json:"video"`
|
||||||
}
|
}
|
||||||
@@ -1752,7 +1752,7 @@ func UnmarshalBackgroundFill(data []byte) (BackgroundFill, error) {
|
|||||||
// The background is filled using the selected color.
|
// The background is filled using the selected color.
|
||||||
type BackgroundFillSolid struct {
|
type BackgroundFillSolid struct {
|
||||||
// Type of the background fill, always “solid”
|
// Type of the background fill, always “solid”
|
||||||
Type BackgroundFillSolidType `json:"type"`
|
Type BackgroundFillType `json:"type"`
|
||||||
// The color of the background fill in the RGB24 format
|
// The color of the background fill in the RGB24 format
|
||||||
Color int64 `json:"color"`
|
Color int64 `json:"color"`
|
||||||
}
|
}
|
||||||
@@ -1776,7 +1776,7 @@ func (v *BackgroundFillSolid) MarshalJSON() ([]byte, error) {
|
|||||||
// The background is a gradient fill.
|
// The background is a gradient fill.
|
||||||
type BackgroundFillGradient struct {
|
type BackgroundFillGradient struct {
|
||||||
// Type of the background fill, always “gradient”
|
// Type of the background fill, always “gradient”
|
||||||
Type BackgroundFillGradientType `json:"type"`
|
Type BackgroundFillType `json:"type"`
|
||||||
// Top color of the gradient in the RGB24 format
|
// Top color of the gradient in the RGB24 format
|
||||||
TopColor int64 `json:"top_color"`
|
TopColor int64 `json:"top_color"`
|
||||||
// Bottom color of the gradient in the RGB24 format
|
// Bottom color of the gradient in the RGB24 format
|
||||||
@@ -1804,7 +1804,7 @@ func (v *BackgroundFillGradient) MarshalJSON() ([]byte, error) {
|
|||||||
// The background is a freeform gradient that rotates after every message in the chat.
|
// The background is a freeform gradient that rotates after every message in the chat.
|
||||||
type BackgroundFillFreeformGradient struct {
|
type BackgroundFillFreeformGradient struct {
|
||||||
// Type of the background fill, always “freeform_gradient”
|
// Type of the background fill, always “freeform_gradient”
|
||||||
Type BackgroundFillFreeformGradientType `json:"type"`
|
Type BackgroundFillType `json:"type"`
|
||||||
// A list of the 3 or 4 base colors that are used to generate the freeform gradient in the RGB24 format
|
// A list of the 3 or 4 base colors that are used to generate the freeform gradient in the RGB24 format
|
||||||
Colors []int64 `json:"colors"`
|
Colors []int64 `json:"colors"`
|
||||||
}
|
}
|
||||||
@@ -1878,7 +1878,7 @@ func UnmarshalBackgroundType(data []byte) (BackgroundType, error) {
|
|||||||
// The background is automatically filled based on the selected colors.
|
// The background is automatically filled based on the selected colors.
|
||||||
type BackgroundTypeFill struct {
|
type BackgroundTypeFill struct {
|
||||||
// Type of the background, always “fill”
|
// Type of the background, always “fill”
|
||||||
Type BackgroundTypeFillType `json:"type"`
|
Type BackgroundTypeKind `json:"type"`
|
||||||
// The background fill
|
// The background fill
|
||||||
Fill BackgroundFill `json:"fill"`
|
Fill BackgroundFill `json:"fill"`
|
||||||
// Dimming of the background in dark themes, as a percentage; 0-100
|
// Dimming of the background in dark themes, as a percentage; 0-100
|
||||||
@@ -1928,7 +1928,7 @@ func (m *BackgroundTypeFill) UnmarshalJSON(data []byte) error {
|
|||||||
// The background is a wallpaper in the JPEG format.
|
// The background is a wallpaper in the JPEG format.
|
||||||
type BackgroundTypeWallpaper struct {
|
type BackgroundTypeWallpaper struct {
|
||||||
// Type of the background, always “wallpaper”
|
// Type of the background, always “wallpaper”
|
||||||
Type BackgroundTypeWallpaperType `json:"type"`
|
Type BackgroundTypeKind `json:"type"`
|
||||||
// Document with the wallpaper
|
// Document with the wallpaper
|
||||||
Document Document `json:"document"`
|
Document Document `json:"document"`
|
||||||
// Dimming of the background in dark themes, as a percentage; 0-100
|
// Dimming of the background in dark themes, as a percentage; 0-100
|
||||||
@@ -1958,7 +1958,7 @@ func (v *BackgroundTypeWallpaper) MarshalJSON() ([]byte, error) {
|
|||||||
// The background is a .PNG or .TGV (gzipped subset of SVG with MIME type “application/x-tgwallpattern”) pattern to be combined with the background fill chosen by the user.
|
// The background is a .PNG or .TGV (gzipped subset of SVG with MIME type “application/x-tgwallpattern”) pattern to be combined with the background fill chosen by the user.
|
||||||
type BackgroundTypePattern struct {
|
type BackgroundTypePattern struct {
|
||||||
// Type of the background, always “pattern”
|
// Type of the background, always “pattern”
|
||||||
Type BackgroundTypePatternType `json:"type"`
|
Type BackgroundTypeKind `json:"type"`
|
||||||
// Document with the pattern
|
// Document with the pattern
|
||||||
Document Document `json:"document"`
|
Document Document `json:"document"`
|
||||||
// The background fill that is combined with the pattern
|
// The background fill that is combined with the pattern
|
||||||
@@ -2014,7 +2014,7 @@ func (m *BackgroundTypePattern) UnmarshalJSON(data []byte) error {
|
|||||||
// The background is taken directly from a built-in chat theme.
|
// The background is taken directly from a built-in chat theme.
|
||||||
type BackgroundTypeChatTheme struct {
|
type BackgroundTypeChatTheme struct {
|
||||||
// Type of the background, always “chat_theme”
|
// Type of the background, always “chat_theme”
|
||||||
Type BackgroundTypeChatThemeType `json:"type"`
|
Type BackgroundTypeKind `json:"type"`
|
||||||
// Name of the chat theme, which is usually an emoji
|
// Name of the chat theme, which is usually an emoji
|
||||||
ThemeName string `json:"theme_name"`
|
ThemeName string `json:"theme_name"`
|
||||||
}
|
}
|
||||||
@@ -2808,7 +2808,7 @@ func UnmarshalChatMember(data []byte) (ChatMember, error) {
|
|||||||
// Represents a chat member that owns the chat and has all administrator privileges.
|
// Represents a chat member that owns the chat and has all administrator privileges.
|
||||||
type ChatMemberOwner struct {
|
type ChatMemberOwner struct {
|
||||||
// The member's status in the chat, always “creator”
|
// The member's status in the chat, always “creator”
|
||||||
Status ChatMemberOwnerStatus `json:"status"`
|
Status ChatMemberStatus `json:"status"`
|
||||||
// Information about the user
|
// Information about the user
|
||||||
User User `json:"user"`
|
User User `json:"user"`
|
||||||
// True, if the user's presence in the chat is hidden
|
// True, if the user's presence in the chat is hidden
|
||||||
@@ -2836,7 +2836,7 @@ func (v *ChatMemberOwner) MarshalJSON() ([]byte, error) {
|
|||||||
// Represents a chat member that has some additional privileges.
|
// Represents a chat member that has some additional privileges.
|
||||||
type ChatMemberAdministrator struct {
|
type ChatMemberAdministrator struct {
|
||||||
// The member's status in the chat, always “administrator”
|
// The member's status in the chat, always “administrator”
|
||||||
Status ChatMemberAdministratorStatus `json:"status"`
|
Status ChatMemberStatus `json:"status"`
|
||||||
// Information about the user
|
// Information about the user
|
||||||
User User `json:"user"`
|
User User `json:"user"`
|
||||||
// True, if the bot is allowed to edit administrator privileges of that user
|
// True, if the bot is allowed to edit administrator privileges of that user
|
||||||
@@ -2898,7 +2898,7 @@ func (v *ChatMemberAdministrator) MarshalJSON() ([]byte, error) {
|
|||||||
// Represents a chat member that has no additional privileges or restrictions.
|
// Represents a chat member that has no additional privileges or restrictions.
|
||||||
type ChatMemberMember struct {
|
type ChatMemberMember struct {
|
||||||
// The member's status in the chat, always “member”
|
// The member's status in the chat, always “member”
|
||||||
Status ChatMemberMemberStatus `json:"status"`
|
Status ChatMemberStatus `json:"status"`
|
||||||
// Optional. Tag of the member
|
// Optional. Tag of the member
|
||||||
Tag string `json:"tag,omitempty"`
|
Tag string `json:"tag,omitempty"`
|
||||||
// Information about the user
|
// Information about the user
|
||||||
@@ -2926,7 +2926,7 @@ func (v *ChatMemberMember) MarshalJSON() ([]byte, error) {
|
|||||||
// Represents a chat member that is under certain restrictions in the chat. Supergroups only.
|
// Represents a chat member that is under certain restrictions in the chat. Supergroups only.
|
||||||
type ChatMemberRestricted struct {
|
type ChatMemberRestricted struct {
|
||||||
// The member's status in the chat, always “restricted”
|
// The member's status in the chat, always “restricted”
|
||||||
Status ChatMemberRestrictedStatus `json:"status"`
|
Status ChatMemberStatus `json:"status"`
|
||||||
// Optional. Tag of the member
|
// Optional. Tag of the member
|
||||||
Tag string `json:"tag,omitempty"`
|
Tag string `json:"tag,omitempty"`
|
||||||
// Information about the user
|
// Information about the user
|
||||||
@@ -2988,7 +2988,7 @@ func (v *ChatMemberRestricted) MarshalJSON() ([]byte, error) {
|
|||||||
// Represents a chat member that isn't currently a member of the chat, but may join it themselves.
|
// Represents a chat member that isn't currently a member of the chat, but may join it themselves.
|
||||||
type ChatMemberLeft struct {
|
type ChatMemberLeft struct {
|
||||||
// The member's status in the chat, always “left”
|
// The member's status in the chat, always “left”
|
||||||
Status ChatMemberLeftStatus `json:"status"`
|
Status ChatMemberStatus `json:"status"`
|
||||||
// Information about the user
|
// Information about the user
|
||||||
User User `json:"user"`
|
User User `json:"user"`
|
||||||
}
|
}
|
||||||
@@ -3012,7 +3012,7 @@ func (v *ChatMemberLeft) MarshalJSON() ([]byte, error) {
|
|||||||
// Represents a chat member that was banned in the chat and can't return to the chat or view chat messages.
|
// Represents a chat member that was banned in the chat and can't return to the chat or view chat messages.
|
||||||
type ChatMemberBanned struct {
|
type ChatMemberBanned struct {
|
||||||
// The member's status in the chat, always “kicked”
|
// The member's status in the chat, always “kicked”
|
||||||
Status ChatMemberBannedStatus `json:"status"`
|
Status ChatMemberStatus `json:"status"`
|
||||||
// Information about the user
|
// Information about the user
|
||||||
User User `json:"user"`
|
User User `json:"user"`
|
||||||
// Date when restrictions will be lifted for this user; Unix time. If 0, then the user is banned forever
|
// Date when restrictions will be lifted for this user; Unix time. If 0, then the user is banned forever
|
||||||
@@ -3230,7 +3230,7 @@ func UnmarshalStoryAreaType(data []byte) (StoryAreaType, error) {
|
|||||||
// Describes a story area pointing to a location. Currently, a story can have up to 10 location areas.
|
// Describes a story area pointing to a location. Currently, a story can have up to 10 location areas.
|
||||||
type StoryAreaTypeLocation struct {
|
type StoryAreaTypeLocation struct {
|
||||||
// Type of the area, always “location”
|
// Type of the area, always “location”
|
||||||
Type StoryAreaTypeLocationType `json:"type"`
|
Type StoryAreaTypeKind `json:"type"`
|
||||||
// Location latitude in degrees
|
// Location latitude in degrees
|
||||||
Latitude float64 `json:"latitude"`
|
Latitude float64 `json:"latitude"`
|
||||||
// Location longitude in degrees
|
// Location longitude in degrees
|
||||||
@@ -3258,7 +3258,7 @@ func (v *StoryAreaTypeLocation) MarshalJSON() ([]byte, error) {
|
|||||||
// Describes a story area pointing to a suggested reaction. Currently, a story can have up to 5 suggested reaction areas.
|
// Describes a story area pointing to a suggested reaction. Currently, a story can have up to 5 suggested reaction areas.
|
||||||
type StoryAreaTypeSuggestedReaction struct {
|
type StoryAreaTypeSuggestedReaction struct {
|
||||||
// Type of the area, always “suggested_reaction”
|
// Type of the area, always “suggested_reaction”
|
||||||
Type StoryAreaTypeSuggestedReactionType `json:"type"`
|
Type StoryAreaTypeKind `json:"type"`
|
||||||
// Type of the reaction
|
// Type of the reaction
|
||||||
ReactionType ReactionType `json:"reaction_type"`
|
ReactionType ReactionType `json:"reaction_type"`
|
||||||
// Optional. Pass True if the reaction area has a dark background
|
// Optional. Pass True if the reaction area has a dark background
|
||||||
@@ -3310,7 +3310,7 @@ func (m *StoryAreaTypeSuggestedReaction) UnmarshalJSON(data []byte) error {
|
|||||||
// Describes a story area pointing to an HTTP or tg:// link. Currently, a story can have up to 3 link areas.
|
// Describes a story area pointing to an HTTP or tg:// link. Currently, a story can have up to 3 link areas.
|
||||||
type StoryAreaTypeLink struct {
|
type StoryAreaTypeLink struct {
|
||||||
// Type of the area, always “link”
|
// Type of the area, always “link”
|
||||||
Type StoryAreaTypeLinkType `json:"type"`
|
Type StoryAreaTypeKind `json:"type"`
|
||||||
// HTTP or tg:// URL to be opened when the area is clicked
|
// HTTP or tg:// URL to be opened when the area is clicked
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
@@ -3334,7 +3334,7 @@ func (v *StoryAreaTypeLink) MarshalJSON() ([]byte, error) {
|
|||||||
// Describes a story area containing weather information. Currently, a story can have up to 3 weather areas.
|
// Describes a story area containing weather information. Currently, a story can have up to 3 weather areas.
|
||||||
type StoryAreaTypeWeather struct {
|
type StoryAreaTypeWeather struct {
|
||||||
// Type of the area, always “weather”
|
// Type of the area, always “weather”
|
||||||
Type StoryAreaTypeWeatherType `json:"type"`
|
Type StoryAreaTypeKind `json:"type"`
|
||||||
// Temperature, in degree Celsius
|
// Temperature, in degree Celsius
|
||||||
Temperature float64 `json:"temperature"`
|
Temperature float64 `json:"temperature"`
|
||||||
// Emoji representing the weather
|
// Emoji representing the weather
|
||||||
@@ -3362,7 +3362,7 @@ func (v *StoryAreaTypeWeather) MarshalJSON() ([]byte, error) {
|
|||||||
// Describes a story area pointing to a unique gift. Currently, a story can have at most 1 unique gift area.
|
// Describes a story area pointing to a unique gift. Currently, a story can have at most 1 unique gift area.
|
||||||
type StoryAreaTypeUniqueGift struct {
|
type StoryAreaTypeUniqueGift struct {
|
||||||
// Type of the area, always “unique_gift”
|
// Type of the area, always “unique_gift”
|
||||||
Type StoryAreaTypeUniqueGiftType `json:"type"`
|
Type StoryAreaTypeKind `json:"type"`
|
||||||
// Unique name of the gift
|
// Unique name of the gift
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
@@ -3470,7 +3470,7 @@ func UnmarshalReactionType(data []byte) (ReactionType, error) {
|
|||||||
// The reaction is based on an emoji.
|
// The reaction is based on an emoji.
|
||||||
type ReactionTypeEmoji struct {
|
type ReactionTypeEmoji struct {
|
||||||
// Type of the reaction, always “emoji”
|
// Type of the reaction, always “emoji”
|
||||||
Type ReactionTypeEmojiType `json:"type"`
|
Type ReactionTypeKind `json:"type"`
|
||||||
// Reaction emoji. Currently, it can be one of "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
|
// Reaction emoji. Currently, it can be one of "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
|
||||||
Emoji string `json:"emoji"`
|
Emoji string `json:"emoji"`
|
||||||
}
|
}
|
||||||
@@ -3494,7 +3494,7 @@ func (v *ReactionTypeEmoji) MarshalJSON() ([]byte, error) {
|
|||||||
// The reaction is based on a custom emoji.
|
// The reaction is based on a custom emoji.
|
||||||
type ReactionTypeCustomEmoji struct {
|
type ReactionTypeCustomEmoji struct {
|
||||||
// Type of the reaction, always “custom_emoji”
|
// Type of the reaction, always “custom_emoji”
|
||||||
Type ReactionTypeCustomEmojiType `json:"type"`
|
Type ReactionTypeKind `json:"type"`
|
||||||
// Custom emoji identifier
|
// Custom emoji identifier
|
||||||
CustomEmojiID string `json:"custom_emoji_id"`
|
CustomEmojiID string `json:"custom_emoji_id"`
|
||||||
}
|
}
|
||||||
@@ -3518,7 +3518,7 @@ func (v *ReactionTypeCustomEmoji) MarshalJSON() ([]byte, error) {
|
|||||||
// The reaction is paid.
|
// The reaction is paid.
|
||||||
type ReactionTypePaid struct {
|
type ReactionTypePaid struct {
|
||||||
// Type of the reaction, always “paid”
|
// Type of the reaction, always “paid”
|
||||||
Type ReactionTypePaidType `json:"type"`
|
Type ReactionTypeKind `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON encodes ReactionTypePaid with the discriminator field
|
// MarshalJSON encodes ReactionTypePaid with the discriminator field
|
||||||
@@ -3880,7 +3880,7 @@ func UnmarshalOwnedGift(data []byte) (OwnedGift, error) {
|
|||||||
// Describes a regular gift owned by a user or a chat.
|
// Describes a regular gift owned by a user or a chat.
|
||||||
type OwnedGiftRegular struct {
|
type OwnedGiftRegular struct {
|
||||||
// Type of the gift, always “regular”
|
// Type of the gift, always “regular”
|
||||||
Type OwnedGiftRegularType `json:"type"`
|
Type OwnedGiftType `json:"type"`
|
||||||
// Information about the regular gift
|
// Information about the regular gift
|
||||||
Gift Gift `json:"gift"`
|
Gift Gift `json:"gift"`
|
||||||
// Optional. Unique identifier of the gift for the bot; for gifts received on behalf of business accounts only
|
// Optional. Unique identifier of the gift for the bot; for gifts received on behalf of business accounts only
|
||||||
@@ -3930,7 +3930,7 @@ func (v *OwnedGiftRegular) MarshalJSON() ([]byte, error) {
|
|||||||
// Describes a unique gift received and owned by a user or a chat.
|
// Describes a unique gift received and owned by a user or a chat.
|
||||||
type OwnedGiftUnique struct {
|
type OwnedGiftUnique struct {
|
||||||
// Type of the gift, always “unique”
|
// Type of the gift, always “unique”
|
||||||
Type OwnedGiftUniqueType `json:"type"`
|
Type OwnedGiftType `json:"type"`
|
||||||
// Information about the unique gift
|
// Information about the unique gift
|
||||||
Gift UniqueGift `json:"gift"`
|
Gift UniqueGift `json:"gift"`
|
||||||
// Optional. Unique identifier of the received gift for the bot; for gifts received on behalf of business accounts only
|
// Optional. Unique identifier of the received gift for the bot; for gifts received on behalf of business accounts only
|
||||||
@@ -4421,7 +4421,7 @@ func UnmarshalChatBoostSource(data []byte) (ChatBoostSource, error) {
|
|||||||
// The boost was obtained by subscribing to Telegram Premium or by gifting a Telegram Premium subscription to another user.
|
// The boost was obtained by subscribing to Telegram Premium or by gifting a Telegram Premium subscription to another user.
|
||||||
type ChatBoostSourcePremium struct {
|
type ChatBoostSourcePremium struct {
|
||||||
// Source of the boost, always “premium”
|
// Source of the boost, always “premium”
|
||||||
Source ChatBoostSourcePremiumSource `json:"source"`
|
Source ChatBoostSourceKind `json:"source"`
|
||||||
// User that boosted the chat
|
// User that boosted the chat
|
||||||
User User `json:"user"`
|
User User `json:"user"`
|
||||||
}
|
}
|
||||||
@@ -4445,7 +4445,7 @@ func (v *ChatBoostSourcePremium) MarshalJSON() ([]byte, error) {
|
|||||||
// The boost was obtained by the creation of Telegram Premium gift codes to boost a chat. Each such code boosts the chat 4 times for the duration of the corresponding Telegram Premium subscription.
|
// The boost was obtained by the creation of Telegram Premium gift codes to boost a chat. Each such code boosts the chat 4 times for the duration of the corresponding Telegram Premium subscription.
|
||||||
type ChatBoostSourceGiftCode struct {
|
type ChatBoostSourceGiftCode struct {
|
||||||
// Source of the boost, always “gift_code”
|
// Source of the boost, always “gift_code”
|
||||||
Source ChatBoostSourceGiftCodeSource `json:"source"`
|
Source ChatBoostSourceKind `json:"source"`
|
||||||
// User for which the gift code was created
|
// User for which the gift code was created
|
||||||
User User `json:"user"`
|
User User `json:"user"`
|
||||||
}
|
}
|
||||||
@@ -4469,7 +4469,7 @@ func (v *ChatBoostSourceGiftCode) MarshalJSON() ([]byte, error) {
|
|||||||
// The boost was obtained by the creation of a Telegram Premium or a Telegram Star giveaway. This boosts the chat 4 times for the duration of the corresponding Telegram Premium subscription for Telegram Premium giveaways and prize_star_count / 500 times for one year for Telegram Star giveaways.
|
// The boost was obtained by the creation of a Telegram Premium or a Telegram Star giveaway. This boosts the chat 4 times for the duration of the corresponding Telegram Premium subscription for Telegram Premium giveaways and prize_star_count / 500 times for one year for Telegram Star giveaways.
|
||||||
type ChatBoostSourceGiveaway struct {
|
type ChatBoostSourceGiveaway struct {
|
||||||
// Source of the boost, always “giveaway”
|
// Source of the boost, always “giveaway”
|
||||||
Source ChatBoostSourceGiveawaySource `json:"source"`
|
Source ChatBoostSourceKind `json:"source"`
|
||||||
// Identifier of a message in the chat with the giveaway; the message could have been deleted already. May be 0 if the message isn't sent yet.
|
// Identifier of a message in the chat with the giveaway; the message could have been deleted already. May be 0 if the message isn't sent yet.
|
||||||
GiveawayMessageID int64 `json:"giveaway_message_id"`
|
GiveawayMessageID int64 `json:"giveaway_message_id"`
|
||||||
// Optional. User that won the prize in the giveaway if any; for Telegram Premium giveaways only
|
// Optional. User that won the prize in the giveaway if any; for Telegram Premium giveaways only
|
||||||
@@ -6632,7 +6632,7 @@ func UnmarshalRevenueWithdrawalState(data []byte) (RevenueWithdrawalState, error
|
|||||||
// The withdrawal is in progress.
|
// The withdrawal is in progress.
|
||||||
type RevenueWithdrawalStatePending struct {
|
type RevenueWithdrawalStatePending struct {
|
||||||
// Type of the state, always “pending”
|
// Type of the state, always “pending”
|
||||||
Type RevenueWithdrawalStatePendingType `json:"type"`
|
Type RevenueWithdrawalStateKind `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON encodes RevenueWithdrawalStatePending with the discriminator field
|
// MarshalJSON encodes RevenueWithdrawalStatePending with the discriminator field
|
||||||
@@ -6654,7 +6654,7 @@ func (v *RevenueWithdrawalStatePending) MarshalJSON() ([]byte, error) {
|
|||||||
// The withdrawal succeeded.
|
// The withdrawal succeeded.
|
||||||
type RevenueWithdrawalStateSucceeded struct {
|
type RevenueWithdrawalStateSucceeded struct {
|
||||||
// Type of the state, always “succeeded”
|
// Type of the state, always “succeeded”
|
||||||
Type RevenueWithdrawalStateSucceededType `json:"type"`
|
Type RevenueWithdrawalStateKind `json:"type"`
|
||||||
// Date the withdrawal was completed in Unix time
|
// Date the withdrawal was completed in Unix time
|
||||||
Date int64 `json:"date"`
|
Date int64 `json:"date"`
|
||||||
// An HTTPS URL that can be used to see transaction details
|
// An HTTPS URL that can be used to see transaction details
|
||||||
@@ -6680,7 +6680,7 @@ func (v *RevenueWithdrawalStateSucceeded) MarshalJSON() ([]byte, error) {
|
|||||||
// The withdrawal failed and the transaction was refunded.
|
// The withdrawal failed and the transaction was refunded.
|
||||||
type RevenueWithdrawalStateFailed struct {
|
type RevenueWithdrawalStateFailed struct {
|
||||||
// Type of the state, always “failed”
|
// Type of the state, always “failed”
|
||||||
Type RevenueWithdrawalStateFailedType `json:"type"`
|
Type RevenueWithdrawalStateKind `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON encodes RevenueWithdrawalStateFailed with the discriminator field
|
// MarshalJSON encodes RevenueWithdrawalStateFailed with the discriminator field
|
||||||
@@ -6780,7 +6780,7 @@ func UnmarshalTransactionPartner(data []byte) (TransactionPartner, error) {
|
|||||||
// Describes a transaction with a user.
|
// Describes a transaction with a user.
|
||||||
type TransactionPartnerUser struct {
|
type TransactionPartnerUser struct {
|
||||||
// Type of the transaction partner, always “user”
|
// Type of the transaction partner, always “user”
|
||||||
Type MessageOriginUserType `json:"type"`
|
Type TransactionPartnerType `json:"type"`
|
||||||
// Type of the transaction, currently one of “invoice_payment” for payments via invoices, “paid_media_payment” for payments for paid media, “gift_purchase” for gifts sent by the bot, “premium_purchase” for Telegram Premium subscriptions gifted by the bot, “business_account_transfer” for direct transfers from managed business accounts
|
// Type of the transaction, currently one of “invoice_payment” for payments via invoices, “paid_media_payment” for payments for paid media, “gift_purchase” for gifts sent by the bot, “premium_purchase” for Telegram Premium subscriptions gifted by the bot, “business_account_transfer” for direct transfers from managed business accounts
|
||||||
TransactionType TransactionPartnerUserTransactionType `json:"transaction_type"`
|
TransactionType TransactionPartnerUserTransactionType `json:"transaction_type"`
|
||||||
// Information about the user
|
// Information about the user
|
||||||
@@ -6852,7 +6852,7 @@ func (m *TransactionPartnerUser) UnmarshalJSON(data []byte) error {
|
|||||||
// Describes a transaction with a chat.
|
// Describes a transaction with a chat.
|
||||||
type TransactionPartnerChat struct {
|
type TransactionPartnerChat struct {
|
||||||
// Type of the transaction partner, always “chat”
|
// Type of the transaction partner, always “chat”
|
||||||
Type MessageOriginChatType `json:"type"`
|
Type TransactionPartnerType `json:"type"`
|
||||||
// Information about the chat
|
// Information about the chat
|
||||||
Chat Chat `json:"chat"`
|
Chat Chat `json:"chat"`
|
||||||
// Optional. The gift sent to the chat by the bot
|
// Optional. The gift sent to the chat by the bot
|
||||||
@@ -6878,7 +6878,7 @@ func (v *TransactionPartnerChat) MarshalJSON() ([]byte, error) {
|
|||||||
// Describes the affiliate program that issued the affiliate commission received via this transaction.
|
// Describes the affiliate program that issued the affiliate commission received via this transaction.
|
||||||
type TransactionPartnerAffiliateProgram struct {
|
type TransactionPartnerAffiliateProgram struct {
|
||||||
// Type of the transaction partner, always “affiliate_program”
|
// Type of the transaction partner, always “affiliate_program”
|
||||||
Type TransactionPartnerAffiliateProgramType `json:"type"`
|
Type TransactionPartnerType `json:"type"`
|
||||||
// Optional. Information about the bot that sponsored the affiliate program
|
// Optional. Information about the bot that sponsored the affiliate program
|
||||||
SponsorUser *User `json:"sponsor_user,omitempty"`
|
SponsorUser *User `json:"sponsor_user,omitempty"`
|
||||||
// The number of Telegram Stars received by the bot for each 1000 Telegram Stars received by the affiliate program sponsor from referred users
|
// The number of Telegram Stars received by the bot for each 1000 Telegram Stars received by the affiliate program sponsor from referred users
|
||||||
@@ -6904,7 +6904,7 @@ func (v *TransactionPartnerAffiliateProgram) MarshalJSON() ([]byte, error) {
|
|||||||
// Describes a withdrawal transaction with Fragment.
|
// Describes a withdrawal transaction with Fragment.
|
||||||
type TransactionPartnerFragment struct {
|
type TransactionPartnerFragment struct {
|
||||||
// Type of the transaction partner, always “fragment”
|
// Type of the transaction partner, always “fragment”
|
||||||
Type TransactionPartnerFragmentType `json:"type"`
|
Type TransactionPartnerType `json:"type"`
|
||||||
// Optional. State of the transaction if the transaction is outgoing
|
// Optional. State of the transaction if the transaction is outgoing
|
||||||
WithdrawalState RevenueWithdrawalState `json:"withdrawal_state,omitempty"`
|
WithdrawalState RevenueWithdrawalState `json:"withdrawal_state,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -6952,7 +6952,7 @@ func (m *TransactionPartnerFragment) UnmarshalJSON(data []byte) error {
|
|||||||
// Describes a withdrawal transaction to the Telegram Ads platform.
|
// Describes a withdrawal transaction to the Telegram Ads platform.
|
||||||
type TransactionPartnerTelegramAds struct {
|
type TransactionPartnerTelegramAds struct {
|
||||||
// Type of the transaction partner, always “telegram_ads”
|
// Type of the transaction partner, always “telegram_ads”
|
||||||
Type TransactionPartnerTelegramAdsType `json:"type"`
|
Type TransactionPartnerType `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON encodes TransactionPartnerTelegramAds with the discriminator field
|
// MarshalJSON encodes TransactionPartnerTelegramAds with the discriminator field
|
||||||
@@ -6974,7 +6974,7 @@ func (v *TransactionPartnerTelegramAds) MarshalJSON() ([]byte, error) {
|
|||||||
// Describes a transaction with payment for paid broadcasting.
|
// Describes a transaction with payment for paid broadcasting.
|
||||||
type TransactionPartnerTelegramApi struct {
|
type TransactionPartnerTelegramApi struct {
|
||||||
// Type of the transaction partner, always “telegram_api”
|
// Type of the transaction partner, always “telegram_api”
|
||||||
Type TransactionPartnerTelegramApiType `json:"type"`
|
Type TransactionPartnerType `json:"type"`
|
||||||
// The number of successful requests that exceeded regular limits and were therefore billed
|
// The number of successful requests that exceeded regular limits and were therefore billed
|
||||||
RequestCount int64 `json:"request_count"`
|
RequestCount int64 `json:"request_count"`
|
||||||
}
|
}
|
||||||
@@ -6998,7 +6998,7 @@ func (v *TransactionPartnerTelegramApi) MarshalJSON() ([]byte, error) {
|
|||||||
// Describes a transaction with an unknown source or recipient.
|
// Describes a transaction with an unknown source or recipient.
|
||||||
type TransactionPartnerOther struct {
|
type TransactionPartnerOther struct {
|
||||||
// Type of the transaction partner, always “other”
|
// Type of the transaction partner, always “other”
|
||||||
Type TransactionPartnerOtherType `json:"type"`
|
Type TransactionPartnerType `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON encodes TransactionPartnerOther with the discriminator field
|
// MarshalJSON encodes TransactionPartnerOther with the discriminator field
|
||||||
|
|||||||
@@ -0,0 +1,182 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
json "github.com/goccy/go-json"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestUnifiedEnum_ChatMemberStatus_HasAllConstants asserts the unified
|
||||||
|
// enum exists with the full set of variant values and is a typed string.
|
||||||
|
func TestUnifiedEnum_ChatMemberStatus_HasAllConstants(t *testing.T) {
|
||||||
|
require.IsType(t, ChatMemberStatus(""), ChatMemberStatusCreator)
|
||||||
|
|
||||||
|
values := []ChatMemberStatus{
|
||||||
|
ChatMemberStatusCreator,
|
||||||
|
ChatMemberStatusAdministrator,
|
||||||
|
ChatMemberStatusMember,
|
||||||
|
ChatMemberStatusRestricted,
|
||||||
|
ChatMemberStatusLeft,
|
||||||
|
ChatMemberStatusKicked,
|
||||||
|
}
|
||||||
|
wantWire := []string{"creator", "administrator", "member", "restricted", "left", "kicked"}
|
||||||
|
require.Len(t, values, 6)
|
||||||
|
for i, v := range values {
|
||||||
|
require.Equal(t, wantWire[i], string(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestUnifiedEnum_ChatMember_VariantFieldsRetyped confirms every concrete
|
||||||
|
// variant's discriminator field is the unified enum, NOT a per-variant
|
||||||
|
// alias type. Reflection walks the struct field directly.
|
||||||
|
func TestUnifiedEnum_ChatMember_VariantFieldsRetyped(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
val any
|
||||||
|
}{
|
||||||
|
{"ChatMemberOwner", &ChatMemberOwner{}},
|
||||||
|
{"ChatMemberAdministrator", &ChatMemberAdministrator{}},
|
||||||
|
{"ChatMemberMember", &ChatMemberMember{}},
|
||||||
|
{"ChatMemberRestricted", &ChatMemberRestricted{}},
|
||||||
|
{"ChatMemberLeft", &ChatMemberLeft{}},
|
||||||
|
{"ChatMemberBanned", &ChatMemberBanned{}},
|
||||||
|
}
|
||||||
|
wantType := reflect.TypeOf(ChatMemberStatus(""))
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
f, ok := reflect.TypeOf(tc.val).Elem().FieldByName("Status")
|
||||||
|
require.True(t, ok, "%s missing Status field", tc.name)
|
||||||
|
require.Equal(t, wantType, f.Type, "%s.Status type mismatch", tc.name)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestUnifiedEnum_ChatMember_DirectComparison verifies the unified enum
|
||||||
|
// lets callers compare a variant's Status directly against constants
|
||||||
|
// without conversion.
|
||||||
|
func TestUnifiedEnum_ChatMember_DirectComparison(t *testing.T) {
|
||||||
|
owner := &ChatMemberOwner{Status: ChatMemberStatusCreator}
|
||||||
|
require.True(t, owner.Status == ChatMemberStatusCreator)
|
||||||
|
require.False(t, owner.Status == ChatMemberStatusKicked)
|
||||||
|
|
||||||
|
banned := &ChatMemberBanned{Status: ChatMemberStatusKicked}
|
||||||
|
require.True(t, banned.Status == ChatMemberStatusKicked)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestUnifiedEnum_ChatMember_MarshalDiscriminator verifies the auto-inject
|
||||||
|
// MarshalJSON still emits the right wire discriminator after the enum
|
||||||
|
// retype — no regression from commit 370c9c0.
|
||||||
|
func TestUnifiedEnum_ChatMember_MarshalDiscriminator(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
val any
|
||||||
|
wantWire string
|
||||||
|
}{
|
||||||
|
{&ChatMemberOwner{User: User{ID: 1, FirstName: "a"}}, "creator"},
|
||||||
|
{&ChatMemberAdministrator{User: User{ID: 2, FirstName: "b"}}, "administrator"},
|
||||||
|
{&ChatMemberMember{User: User{ID: 3, FirstName: "c"}}, "member"},
|
||||||
|
{&ChatMemberRestricted{User: User{ID: 4, FirstName: "d"}}, "restricted"},
|
||||||
|
{&ChatMemberLeft{User: User{ID: 5, FirstName: "e"}}, "left"},
|
||||||
|
{&ChatMemberBanned{User: User{ID: 6, FirstName: "f"}}, "kicked"},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
raw, err := json.Marshal(tc.val)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var probe struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
}
|
||||||
|
require.NoError(t, json.Unmarshal(raw, &probe))
|
||||||
|
require.Equal(t, tc.wantWire, probe.Status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestUnifiedEnum_ChatMember_RoundTrip confirms a marshal-unmarshal cycle
|
||||||
|
// preserves the unified-enum field value.
|
||||||
|
func TestUnifiedEnum_ChatMember_RoundTrip(t *testing.T) {
|
||||||
|
orig := &ChatMemberOwner{User: User{ID: 99, FirstName: "owner"}}
|
||||||
|
raw, err := json.Marshal(orig)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
out, err := UnmarshalChatMember(raw)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
round, ok := out.(*ChatMemberOwner)
|
||||||
|
require.True(t, ok, "expected *ChatMemberOwner, got %T", out)
|
||||||
|
require.Equal(t, ChatMemberStatusCreator, round.Status)
|
||||||
|
require.Equal(t, orig.User.ID, round.User.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestUnifiedEnum_MessageOriginType verifies a second union also unifies
|
||||||
|
// correctly — guards against a one-off implementation that only handles
|
||||||
|
// ChatMember.
|
||||||
|
func TestUnifiedEnum_MessageOriginType(t *testing.T) {
|
||||||
|
require.IsType(t, MessageOriginType(""), MessageOriginTypeUser)
|
||||||
|
|
||||||
|
values := []MessageOriginType{
|
||||||
|
MessageOriginTypeUser,
|
||||||
|
MessageOriginTypeHiddenUser,
|
||||||
|
MessageOriginTypeChat,
|
||||||
|
MessageOriginTypeChannel,
|
||||||
|
}
|
||||||
|
wantWire := []string{"user", "hidden_user", "chat", "channel"}
|
||||||
|
for i, v := range values {
|
||||||
|
require.Equal(t, wantWire[i], string(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Variant fields use the unified type.
|
||||||
|
wantType := reflect.TypeOf(MessageOriginType(""))
|
||||||
|
for _, name := range []string{"MessageOriginUser", "MessageOriginHiddenUser", "MessageOriginChat", "MessageOriginChannel"} {
|
||||||
|
switch name {
|
||||||
|
case "MessageOriginUser":
|
||||||
|
f, ok := reflect.TypeOf(&MessageOriginUser{}).Elem().FieldByName("Type")
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, wantType, f.Type)
|
||||||
|
case "MessageOriginHiddenUser":
|
||||||
|
f, ok := reflect.TypeOf(&MessageOriginHiddenUser{}).Elem().FieldByName("Type")
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, wantType, f.Type)
|
||||||
|
case "MessageOriginChat":
|
||||||
|
f, ok := reflect.TypeOf(&MessageOriginChat{}).Elem().FieldByName("Type")
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, wantType, f.Type)
|
||||||
|
case "MessageOriginChannel":
|
||||||
|
f, ok := reflect.TypeOf(&MessageOriginChannel{}).Elem().FieldByName("Type")
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, wantType, f.Type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestUnifiedEnum_StutterSuffix_Kind covers the naming-collision rule:
|
||||||
|
// when the union name ends in a discriminator concept noun, the unified
|
||||||
|
// enum is suffixed with "Kind" to avoid stuttery names like
|
||||||
|
// "BackgroundTypeType".
|
||||||
|
func TestUnifiedEnum_StutterSuffix_Kind(t *testing.T) {
|
||||||
|
require.IsType(t, BackgroundTypeKind(""), BackgroundTypeKindFill)
|
||||||
|
require.IsType(t, ReactionTypeKind(""), ReactionTypeKindEmoji)
|
||||||
|
require.IsType(t, StoryAreaTypeKind(""), StoryAreaTypeKindLocation)
|
||||||
|
require.IsType(t, ChatBoostSourceKind(""), ChatBoostSourceKindPremium)
|
||||||
|
require.IsType(t, RevenueWithdrawalStateKind(""), RevenueWithdrawalStateKindPending)
|
||||||
|
|
||||||
|
// Variant struct field types match the unified enum.
|
||||||
|
wantType := reflect.TypeOf(BackgroundTypeKind(""))
|
||||||
|
f, ok := reflect.TypeOf(&BackgroundTypeFill{}).Elem().FieldByName("Type")
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, wantType, f.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestUnifiedEnum_PerVariantTypesNotEmitted asserts the obsolete
|
||||||
|
// per-variant single-value enum types (e.g. ChatMemberOwnerStatus) are
|
||||||
|
// gone — ensures the codegen doesn't double-emit. We rely on compile-time
|
||||||
|
// behaviour: if any of these names existed, a referencing package would
|
||||||
|
// fail to build. Instead we verify the variant struct field type's name
|
||||||
|
// is the unified one.
|
||||||
|
func TestUnifiedEnum_PerVariantTypesNotEmitted(t *testing.T) {
|
||||||
|
got := reflect.TypeOf(&ChatMemberOwner{}).Elem()
|
||||||
|
statusField, ok := got.FieldByName("Status")
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "ChatMemberStatus", statusField.Type.Name(),
|
||||||
|
"ChatMemberOwner.Status should be ChatMemberStatus, not ChatMemberOwnerStatus")
|
||||||
|
}
|
||||||
@@ -41,12 +41,25 @@ func planEnums(api *spec.API) *enumPlan {
|
|||||||
valueKey string // canonical key for value-set dedup
|
valueKey string // canonical key for value-set dedup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unification pass: for each sealed-interface union, fold per-variant
|
||||||
|
// single-value enum fields that share a discriminator name into ONE
|
||||||
|
// unified enum at union level. Claimed (parent,fieldName) tuples are
|
||||||
|
// excluded from the per-field grouping below.
|
||||||
|
unifiedDecls, unifiedByField := planUnifiedUnionEnums(api)
|
||||||
|
claimed := func(parent, fieldName string) bool {
|
||||||
|
_, ok := unifiedByField[enumKey(parent, fieldName)]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
var refs []ref
|
var refs []ref
|
||||||
collect := func(parent string, fields []spec.Field) {
|
collect := func(parent string, fields []spec.Field) {
|
||||||
for _, f := range fields {
|
for _, f := range fields {
|
||||||
if len(f.EnumValues) == 0 {
|
if len(f.EnumValues) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if claimed(parent, f.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
refs = append(refs, ref{
|
refs = append(refs, ref{
|
||||||
parent: parent,
|
parent: parent,
|
||||||
fieldName: f.Name,
|
fieldName: f.Name,
|
||||||
@@ -190,9 +203,172 @@ func planEnums(api *spec.API) *enumPlan {
|
|||||||
plan.decls[g.name] = enumDecl{Name: g.name, Values: g.values}
|
plan.decls[g.name] = enumDecl{Name: g.name, Values: g.values}
|
||||||
_ = vk
|
_ = vk
|
||||||
}
|
}
|
||||||
|
// Merge unified union enums (already named with stutter handling and
|
||||||
|
// keyed per-variant in unifiedByField).
|
||||||
|
for k, name := range unifiedByField {
|
||||||
|
plan.byField[k] = name
|
||||||
|
}
|
||||||
|
for name, d := range unifiedDecls {
|
||||||
|
plan.decls[name] = d
|
||||||
|
}
|
||||||
return plan
|
return plan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// planUnifiedUnionEnums detects sealed-interface unions whose variants
|
||||||
|
// share a single discriminator field with one enum value each, and emits
|
||||||
|
// ONE unified enum per union covering all variant values. Returns the
|
||||||
|
// declarations to emit and the per-(variant,fieldName) map to point each
|
||||||
|
// variant's field at the unified enum.
|
||||||
|
//
|
||||||
|
// A union qualifies when EVERY variant in t.OneOf:
|
||||||
|
// 1. defines a field with the same Go-name (e.g. "Status", "Type", "Source");
|
||||||
|
// 2. that field is a required string with len(EnumValues)==1.
|
||||||
|
//
|
||||||
|
// The picked Go-name is the first one tried in this priority order:
|
||||||
|
// - knownDiscriminators[union].Field's Go-name (resolved via JSONName match);
|
||||||
|
// - "Type", "Status", "Source" (the three discriminators Telegram uses).
|
||||||
|
//
|
||||||
|
// First match wins; if none qualify, the union is skipped (variants keep
|
||||||
|
// their existing per-field treatment, which still single-emits via the
|
||||||
|
// regular grouping pass).
|
||||||
|
func planUnifiedUnionEnums(api *spec.API) (map[string]enumDecl, map[string]string) {
|
||||||
|
decls := map[string]enumDecl{}
|
||||||
|
byField := map[string]string{}
|
||||||
|
|
||||||
|
typeByName := make(map[string]*spec.TypeDecl, len(api.Types))
|
||||||
|
for i := range api.Types {
|
||||||
|
typeByName[api.Types[i].Name] = &api.Types[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate unions in deterministic (declaration) order.
|
||||||
|
for ui := range api.Types {
|
||||||
|
u := &api.Types[ui]
|
||||||
|
if len(u.OneOf) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve the variants. Skip unions where any variant is missing
|
||||||
|
// (defensive — shouldn't happen in a well-formed IR).
|
||||||
|
variants := make([]*spec.TypeDecl, 0, len(u.OneOf))
|
||||||
|
for _, vName := range u.OneOf {
|
||||||
|
v, ok := typeByName[vName]
|
||||||
|
if !ok {
|
||||||
|
variants = nil
|
||||||
|
break
|
||||||
|
}
|
||||||
|
variants = append(variants, v)
|
||||||
|
}
|
||||||
|
if len(variants) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the candidate Go-name list. Priority order:
|
||||||
|
// 1. discriminator GoField from knownDiscriminators (resolved via JSONName);
|
||||||
|
// 2. "Type", "Status", "Source".
|
||||||
|
var candidateNames []string
|
||||||
|
seen := map[string]bool{}
|
||||||
|
add := func(name string) {
|
||||||
|
if name == "" || seen[name] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
seen[name] = true
|
||||||
|
candidateNames = append(candidateNames, name)
|
||||||
|
}
|
||||||
|
if ds, ok := knownDiscriminators[u.Name]; ok && ds.Field != "" {
|
||||||
|
// Resolve Go-name from the first variant whose field matches the JSON name.
|
||||||
|
for _, v := range variants {
|
||||||
|
for _, f := range v.Fields {
|
||||||
|
if f.JSONName == ds.Field {
|
||||||
|
add(f.Name)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, n := range []string{"Type", "Status", "Source"} {
|
||||||
|
add(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the first candidate Go-name where every variant has a
|
||||||
|
// matching single-value string-enum field.
|
||||||
|
var (
|
||||||
|
pickedName string
|
||||||
|
pickedDocs map[string]spec.Field // variant name -> field
|
||||||
|
)
|
||||||
|
for _, name := range candidateNames {
|
||||||
|
matches := map[string]spec.Field{}
|
||||||
|
ok := true
|
||||||
|
for _, v := range variants {
|
||||||
|
var hit *spec.Field
|
||||||
|
for fi := range v.Fields {
|
||||||
|
if v.Fields[fi].Name == name {
|
||||||
|
hit = &v.Fields[fi]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hit == nil ||
|
||||||
|
hit.Type.Kind != spec.KindPrimitive ||
|
||||||
|
hit.Type.Name != "string" ||
|
||||||
|
len(hit.EnumValues) != 1 {
|
||||||
|
ok = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
matches[v.Name] = *hit
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
pickedName = name
|
||||||
|
pickedDocs = matches
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pickedName == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the unified enum name with stutter handling.
|
||||||
|
enumName := unifiedEnumName(u.Name, pickedName)
|
||||||
|
|
||||||
|
// Collect values across variants in deterministic order, deduping.
|
||||||
|
valueOrder := make([]string, 0, len(variants))
|
||||||
|
valueSeen := map[string]bool{}
|
||||||
|
for _, v := range u.OneOf {
|
||||||
|
f := pickedDocs[v]
|
||||||
|
val := f.EnumValues[0]
|
||||||
|
if valueSeen[val] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
valueSeen[val] = true
|
||||||
|
valueOrder = append(valueOrder, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
decls[enumName] = enumDecl{Name: enumName, Values: valueOrder}
|
||||||
|
for _, v := range variants {
|
||||||
|
byField[enumKey(v.Name, pickedName)] = enumName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return decls, byField
|
||||||
|
}
|
||||||
|
|
||||||
|
// unifiedEnumName builds the union-level enum name. Falls back to a
|
||||||
|
// "Kind" suffix when the naive concatenation reads as a stutter:
|
||||||
|
//
|
||||||
|
// - union name ends in the field name verbatim (e.g. BackgroundType+Type);
|
||||||
|
// - union name ends in any "concept noun" — Type/Status/Source/State —
|
||||||
|
// so appending another such noun would duplicate the suffix
|
||||||
|
// (e.g. ChatBoostSource+Source, RevenueWithdrawalState+Type).
|
||||||
|
//
|
||||||
|
// Otherwise the natural concatenation wins (ChatMember+Status →
|
||||||
|
// ChatMemberStatus, MessageOrigin+Type → MessageOriginType).
|
||||||
|
func unifiedEnumName(unionName, fieldName string) string {
|
||||||
|
for _, suf := range []string{"Type", "Status", "Source", "State"} {
|
||||||
|
if strings.HasSuffix(unionName, suf) {
|
||||||
|
return unionName + "Kind"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return unionName + fieldName
|
||||||
|
}
|
||||||
|
|
||||||
// All returns the enum declarations sorted by name for deterministic emit.
|
// All returns the enum declarations sorted by name for deterministic emit.
|
||||||
func (p *enumPlan) All() []enumDecl {
|
func (p *enumPlan) All() []enumDecl {
|
||||||
out := make([]enumDecl, 0, len(p.decls))
|
out := make([]enumDecl, 0, len(p.decls))
|
||||||
|
|||||||
@@ -12,15 +12,15 @@ func memberUpdate(status string, fromID int64) *api.ChatMemberUpdated {
|
|||||||
var newMember api.ChatMember
|
var newMember api.ChatMember
|
||||||
switch status {
|
switch status {
|
||||||
case "member":
|
case "member":
|
||||||
newMember = &api.ChatMemberMember{Status: api.ChatMemberMemberStatusMember}
|
newMember = &api.ChatMemberMember{Status: api.ChatMemberStatusMember}
|
||||||
case "administrator":
|
case "administrator":
|
||||||
newMember = &api.ChatMemberAdministrator{Status: api.ChatMemberAdministratorStatusAdministrator}
|
newMember = &api.ChatMemberAdministrator{Status: api.ChatMemberStatusAdministrator}
|
||||||
case "kicked":
|
case "kicked":
|
||||||
newMember = &api.ChatMemberBanned{Status: api.ChatMemberBannedStatusKicked}
|
newMember = &api.ChatMemberBanned{Status: api.ChatMemberStatusKicked}
|
||||||
case "left":
|
case "left":
|
||||||
newMember = &api.ChatMemberLeft{Status: api.ChatMemberLeftStatusLeft}
|
newMember = &api.ChatMemberLeft{Status: api.ChatMemberStatusLeft}
|
||||||
default:
|
default:
|
||||||
newMember = &api.ChatMemberMember{Status: api.ChatMemberMemberStatusMember}
|
newMember = &api.ChatMemberMember{Status: api.ChatMemberStatusMember}
|
||||||
}
|
}
|
||||||
return &api.ChatMemberUpdated{
|
return &api.ChatMemberUpdated{
|
||||||
From: api.User{ID: fromID},
|
From: api.User{ID: fromID},
|
||||||
@@ -70,7 +70,7 @@ func TestComposedFilters(t *testing.T) {
|
|||||||
func TestNewStatus_Owner(t *testing.T) {
|
func TestNewStatus_Owner(t *testing.T) {
|
||||||
u := &api.ChatMemberUpdated{
|
u := &api.ChatMemberUpdated{
|
||||||
From: api.User{ID: 1},
|
From: api.User{ID: 1},
|
||||||
NewChatMember: &api.ChatMemberOwner{Status: api.ChatMemberOwnerStatusCreator},
|
NewChatMember: &api.ChatMemberOwner{Status: api.ChatMemberStatusCreator},
|
||||||
}
|
}
|
||||||
require.True(t, cmfilter.NewStatus("creator")(u))
|
require.True(t, cmfilter.NewStatus("creator")(u))
|
||||||
require.False(t, cmfilter.NewStatus("member")(u))
|
require.False(t, cmfilter.NewStatus("member")(u))
|
||||||
@@ -79,7 +79,7 @@ func TestNewStatus_Owner(t *testing.T) {
|
|||||||
func TestNewStatus_Restricted(t *testing.T) {
|
func TestNewStatus_Restricted(t *testing.T) {
|
||||||
u := &api.ChatMemberUpdated{
|
u := &api.ChatMemberUpdated{
|
||||||
From: api.User{ID: 1},
|
From: api.User{ID: 1},
|
||||||
NewChatMember: &api.ChatMemberRestricted{Status: api.ChatMemberRestrictedStatusRestricted},
|
NewChatMember: &api.ChatMemberRestricted{Status: api.ChatMemberStatusRestricted},
|
||||||
}
|
}
|
||||||
require.True(t, cmfilter.NewStatus("restricted")(u))
|
require.True(t, cmfilter.NewStatus("restricted")(u))
|
||||||
require.False(t, cmfilter.NewStatus("member")(u))
|
require.False(t, cmfilter.NewStatus("member")(u))
|
||||||
|
|||||||
+191
-716
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user