Bot API 7.4 implementation

master^2^2
stdkhai 2024-05-31 19:21:42 +03:00
parent 9b9c5c57d2
commit bece330506
4 changed files with 122 additions and 36 deletions

View File

@ -384,6 +384,7 @@ type CopyMessageConfig struct {
Caption string Caption string
ParseMode string ParseMode string
CaptionEntities []MessageEntity CaptionEntities []MessageEntity
ShowCaptionAboveMedia bool
} }
func (config CopyMessageConfig) params() (Params, error) { func (config CopyMessageConfig) params() (Params, error) {
@ -400,6 +401,7 @@ func (config CopyMessageConfig) params() (Params, error) {
params.AddNonZero("message_id", config.MessageID) params.AddNonZero("message_id", config.MessageID)
params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
params.AddBool("show_caption_above_media", config.ShowCaptionAboveMedia)
err = params.AddInterface("caption_entities", config.CaptionEntities) err = params.AddInterface("caption_entities", config.CaptionEntities)
return params, err return params, err
@ -446,6 +448,7 @@ type PhotoConfig struct {
Caption string Caption string
ParseMode string ParseMode string
CaptionEntities []MessageEntity CaptionEntities []MessageEntity
ShowCaptionAboveMedia bool
} }
func (config PhotoConfig) params() (Params, error) { func (config PhotoConfig) params() (Params, error) {
@ -456,6 +459,7 @@ func (config PhotoConfig) params() (Params, error) {
params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
params.AddBool("show_caption_above_media", config.ShowCaptionAboveMedia)
err = params.AddInterface("caption_entities", config.CaptionEntities) err = params.AddInterface("caption_entities", config.CaptionEntities)
if err != nil { if err != nil {
return params, err return params, err
@ -614,6 +618,7 @@ type VideoConfig struct {
Caption string Caption string
ParseMode string ParseMode string
CaptionEntities []MessageEntity CaptionEntities []MessageEntity
ShowCaptionAboveMedia bool
SupportsStreaming bool SupportsStreaming bool
} }
@ -627,6 +632,7 @@ func (config VideoConfig) params() (Params, error) {
params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
params.AddBool("supports_streaming", config.SupportsStreaming) params.AddBool("supports_streaming", config.SupportsStreaming)
params.AddBool("show_caption_above_media", config.ShowCaptionAboveMedia)
err = params.AddInterface("caption_entities", config.CaptionEntities) err = params.AddInterface("caption_entities", config.CaptionEntities)
if err != nil { if err != nil {
return params, err return params, err
@ -670,6 +676,7 @@ type AnimationConfig struct {
Caption string Caption string
ParseMode string ParseMode string
CaptionEntities []MessageEntity CaptionEntities []MessageEntity
ShowCaptionAboveMedia bool
} }
func (config AnimationConfig) params() (Params, error) { func (config AnimationConfig) params() (Params, error) {
@ -681,6 +688,7 @@ func (config AnimationConfig) params() (Params, error) {
params.AddNonZero("duration", config.Duration) params.AddNonZero("duration", config.Duration)
params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
params.AddBool("show_caption_above_media", config.ShowCaptionAboveMedia)
err = params.AddInterface("caption_entities", config.CaptionEntities) err = params.AddInterface("caption_entities", config.CaptionEntities)
if err != nil { if err != nil {
return params, err return params, err
@ -1112,6 +1120,7 @@ type EditMessageCaptionConfig struct {
Caption string Caption string
ParseMode string ParseMode string
CaptionEntities []MessageEntity CaptionEntities []MessageEntity
ShowCaptionAboveMedia bool
} }
func (config EditMessageCaptionConfig) params() (Params, error) { func (config EditMessageCaptionConfig) params() (Params, error) {
@ -1122,6 +1131,7 @@ func (config EditMessageCaptionConfig) params() (Params, error) {
params["caption"] = config.Caption params["caption"] = config.Caption
params.AddNonEmpty("parse_mode", config.ParseMode) params.AddNonEmpty("parse_mode", config.ParseMode)
params.AddBool("show_caption_above_media", config.ShowCaptionAboveMedia)
err = params.AddInterface("caption_entities", config.CaptionEntities) err = params.AddInterface("caption_entities", config.CaptionEntities)
return params, err return params, err
@ -1894,12 +1904,12 @@ func (config InvoiceConfig) params() (Params, error) {
params["title"] = config.Title params["title"] = config.Title
params["description"] = config.Description params["description"] = config.Description
params["payload"] = config.Payload params["payload"] = config.Payload
params["provider_token"] = config.ProviderToken
params["currency"] = config.Currency params["currency"] = config.Currency
if err = params.AddInterface("prices", config.Prices); err != nil { if err = params.AddInterface("prices", config.Prices); err != nil {
return params, err return params, err
} }
params.AddNonEmpty("provider_token", config.ProviderToken)
params.AddNonZero("max_tip_amount", config.MaxTipAmount) params.AddNonZero("max_tip_amount", config.MaxTipAmount)
err = params.AddInterface("suggested_tip_amounts", config.SuggestedTipAmounts) err = params.AddInterface("suggested_tip_amounts", config.SuggestedTipAmounts)
params.AddNonEmpty("start_parameter", config.StartParameter) params.AddNonEmpty("start_parameter", config.StartParameter)
@ -1953,12 +1963,12 @@ func (config InvoiceLinkConfig) params() (Params, error) {
params["title"] = config.Title params["title"] = config.Title
params["description"] = config.Description params["description"] = config.Description
params["payload"] = config.Payload params["payload"] = config.Payload
params["provider_token"] = config.ProviderToken
params["currency"] = config.Currency params["currency"] = config.Currency
if err := params.AddInterface("prices", config.Prices); err != nil { if err := params.AddInterface("prices", config.Prices); err != nil {
return params, err return params, err
} }
params.AddNonEmpty("provider_token", config.ProviderToken)
params.AddNonZero("max_tip_amount", config.MaxTipAmount) params.AddNonZero("max_tip_amount", config.MaxTipAmount)
err := params.AddInterface("suggested_tip_amounts", config.SuggestedTipAmounts) err := params.AddInterface("suggested_tip_amounts", config.SuggestedTipAmounts)
params.AddNonEmpty("provider_data", config.ProviderData) params.AddNonEmpty("provider_data", config.ProviderData)
@ -2025,6 +2035,26 @@ func (config PreCheckoutConfig) params() (Params, error) {
return params, nil return params, nil
} }
// RefundStarPaymentConfig refunds a successful payment in Telegram Stars.
// Returns True on success.
type RefundStarPaymentConfig struct {
UserID int64 //required
TelegramPaymentChargeID string //required
}
func (config RefundStarPaymentConfig) method() string {
return "refundStarPayment"
}
func (config RefundStarPaymentConfig) params() (Params, error) {
params := make(Params)
params["telegram_payment_charge_id"] = config.TelegramPaymentChargeID
params.AddNonZero64("user_id", config.UserID)
return params, nil
}
// DeleteMessageConfig contains information of a message in a chat to delete. // DeleteMessageConfig contains information of a message in a chat to delete.
type DeleteMessageConfig struct { type DeleteMessageConfig struct {
BaseChatMessage BaseChatMessage

View File

@ -24,6 +24,7 @@ type BaseChat struct {
ProtectContent bool ProtectContent bool
ReplyMarkup interface{} ReplyMarkup interface{}
DisableNotification bool DisableNotification bool
MessageEffectID string // for private chats only
ReplyParameters ReplyParameters ReplyParameters ReplyParameters
} }
@ -41,6 +42,7 @@ func (chat *BaseChat) params() (Params, error) {
params.AddNonZero("message_thread_id", chat.MessageThreadID) params.AddNonZero("message_thread_id", chat.MessageThreadID)
params.AddBool("disable_notification", chat.DisableNotification) params.AddBool("disable_notification", chat.DisableNotification)
params.AddBool("protect_content", chat.ProtectContent) params.AddBool("protect_content", chat.ProtectContent)
params.AddNonEmpty("message_effect_id", chat.MessageEffectID)
err = params.AddInterface("reply_markup", chat.ReplyMarkup) err = params.AddInterface("reply_markup", chat.ReplyMarkup)
if err != nil { if err != nil {

View File

@ -651,6 +651,10 @@ type Message struct {
// //
// Optional // Optional
LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"` LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"`
// EffectID is the unique identifier of the message effect added to the message
//
// optional
EffectID string `json:"effect_id,omitempty"`
// Animation message is an animation, information about the animation. // Animation message is an animation, information about the animation.
// For backward compatibility, when this field is set, the document field will also be set; // For backward compatibility, when this field is set, the document field will also be set;
// //
@ -701,6 +705,10 @@ type Message struct {
// //
// optional // optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// ShowCaptionAboveMedia is True, if the caption must be shown above the message media
//
// optional
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
// HasSpoiler True, if the message media is covered by a spoiler animation // HasSpoiler True, if the message media is covered by a spoiler animation
// //
// optional // optional
@ -1003,6 +1011,7 @@ type MessageEntity struct {
// “strikethrough” (strikethrough text), // “strikethrough” (strikethrough text),
// "spoiler" (spoiler message), // "spoiler" (spoiler message),
// “blockquote” (block quotation), // “blockquote” (block quotation),
// “expandable_blockquote” (collapsed-by-default block quotation),
// “code” (monowidth string), // “code” (monowidth string),
// “pre” (monowidth block), // “pre” (monowidth block),
// “text_link” (for clickable text URLs), // “text_link” (for clickable text URLs),
@ -2415,6 +2424,7 @@ type InlineKeyboardButton struct {
// optional // optional
CallbackGame *CallbackGame `json:"callback_game,omitempty"` CallbackGame *CallbackGame `json:"callback_game,omitempty"`
// Pay specify True, to send a Pay button. // Pay specify True, to send a Pay button.
// Substrings “⭐” and “XTR” in the buttons's text will be replaced with a Telegram Star icon.
// //
// NOTE: This type of button must always be the first button in the first row. // NOTE: This type of button must always be the first button in the first row.
// //
@ -3289,6 +3299,10 @@ type BaseInputMedia struct {
// //
// optional // optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// Pass True, if the caption must be shown above the message media
//
// optional
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
// HasSpoiler pass True, if the photo needs to be covered with a spoiler animation // HasSpoiler pass True, if the photo needs to be covered with a spoiler animation
// //
// optional // optional
@ -3778,6 +3792,10 @@ type InlineQueryResultCachedGIF struct {
// //
// optional // optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// Pass True, if the caption must be shown above the message media
//
// optional
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
// ReplyMarkup inline keyboard attached to the message. // ReplyMarkup inline keyboard attached to the message.
// //
// optional // optional
@ -3817,6 +3835,10 @@ type InlineQueryResultCachedMPEG4GIF struct {
// //
// optional // optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// Pass True, if the caption must be shown above the message media
//
// optional
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
// ReplyMarkup inline keyboard attached to the message. // ReplyMarkup inline keyboard attached to the message.
// //
// optional // optional
@ -3858,6 +3880,10 @@ type InlineQueryResultCachedPhoto struct {
// //
// optional // optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// Pass True, if the caption must be shown above the message media
//
// optional
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
// ReplyMarkup inline keyboard attached to the message. // ReplyMarkup inline keyboard attached to the message.
// //
// optional // optional
@ -3917,6 +3943,10 @@ type InlineQueryResultCachedVideo struct {
// //
// optional // optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// Pass True, if the caption must be shown above the message media
//
// optional
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
// ReplyMarkup inline keyboard attached to the message // ReplyMarkup inline keyboard attached to the message
// //
// optional // optional
@ -4159,6 +4189,10 @@ type InlineQueryResultGIF struct {
// //
// optional // optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// Pass True, if the caption must be shown above the message media
//
// optional
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
// ReplyMarkup inline keyboard attached to the message // ReplyMarkup inline keyboard attached to the message
// //
// optional // optional
@ -4267,6 +4301,10 @@ type InlineQueryResultMPEG4GIF struct {
// //
// optional // optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// Pass True, if the caption must be shown above the message media
//
// optional
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
// ReplyMarkup inline keyboard attached to the message // ReplyMarkup inline keyboard attached to the message
// //
// optional // optional
@ -4327,6 +4365,10 @@ type InlineQueryResultPhoto struct {
// //
// optional // optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// Pass True, if the caption must be shown above the message media
//
// optional
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
// InputMessageContent content of the message to be sent instead of the photo. // InputMessageContent content of the message to be sent instead of the photo.
// //
// optional // optional
@ -4406,6 +4448,15 @@ type InlineQueryResultVideo struct {
// //
// optional // optional
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// CaptionEntities is a list of special entities that appear in the caption,
// which can be specified instead of parse_mode
//
// optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// Pass True, if the caption must be shown above the message media
//
// optional
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
// ParseMode mode for parsing entities in the video caption. // ParseMode mode for parsing entities in the video caption.
// See formatting options for more details // See formatting options for more details
// (https://core.telegram.org/bots/api#formatting-options). // (https://core.telegram.org/bots/api#formatting-options).
@ -4617,9 +4668,11 @@ type InputInvoiceMessageContent struct {
// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to // Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
// the user, use for your internal processes. // the user, use for your internal processes.
Payload string `json:"payload"` Payload string `json:"payload"`
// Payment provider token, obtained via Botfather // Payment provider token, obtained via Botfather. Pass an empty string for payments in Telegram Stars.
//
// optional
ProviderToken string `json:"provider_token"` ProviderToken string `json:"provider_token"`
// Three-letter ISO 4217 currency code // Three-letter ISO 4217 currency code. Pass “XTR” for payments in Telegram Stars.
Currency string `json:"currency"` Currency string `json:"currency"`
// Price breakdown, a JSON-serialized list of components (e.g. product // Price breakdown, a JSON-serialized list of components (e.g. product
// price, tax, discount, delivery cost, delivery tax, bonus, etc.) // price, tax, discount, delivery cost, delivery tax, bonus, etc.)
@ -4711,7 +4764,7 @@ type Invoice struct {
Description string `json:"description"` Description string `json:"description"`
// StartParameter unique bot deep-linking parameter that can be used to generate this invoice // StartParameter unique bot deep-linking parameter that can be used to generate this invoice
StartParameter string `json:"start_parameter"` StartParameter string `json:"start_parameter"`
// Currency three-letter ISO 4217 currency code // Currency three-letter ISO 4217 currency code, or “XTR” for payments in Telegram Stars
// (see https://core.telegram.org/bots/payments#supported-currencies) // (see https://core.telegram.org/bots/payments#supported-currencies)
Currency string `json:"currency"` Currency string `json:"currency"`
// TotalAmount total price in the smallest units of the currency (integer, not float/double). // TotalAmount total price in the smallest units of the currency (integer, not float/double).
@ -4771,7 +4824,7 @@ type ShippingOption struct {
// SuccessfulPayment contains basic information about a successful payment. // SuccessfulPayment contains basic information about a successful payment.
type SuccessfulPayment struct { type SuccessfulPayment struct {
// Currency three-letter ISO 4217 currency code // Currency three-letter ISO 4217 currency code, or “XTR” for payments in Telegram Stars
// (see https://core.telegram.org/bots/payments#supported-currencies) // (see https://core.telegram.org/bots/payments#supported-currencies)
Currency string `json:"currency"` Currency string `json:"currency"`
// TotalAmount total price in the smallest units of the currency (integer, not float/double). // TotalAmount total price in the smallest units of the currency (integer, not float/double).
@ -4815,7 +4868,7 @@ type PreCheckoutQuery struct {
ID string `json:"id"` ID string `json:"id"`
// From user who sent the query // From user who sent the query
From *User `json:"from"` From *User `json:"from"`
// Currency three-letter ISO 4217 currency code // Currency three-letter ISO 4217 currency code, or “XTR” for payments in Telegram Stars
// // (see https://core.telegram.org/bots/payments#supported-currencies) // // (see https://core.telegram.org/bots/payments#supported-currencies)
Currency string `json:"currency"` Currency string `json:"currency"`
// TotalAmount total price in the smallest units of the currency (integer, not float/double). // TotalAmount total price in the smallest units of the currency (integer, not float/double).

View File

@ -375,6 +375,7 @@ var (
_ Chattable = SetMyShortDescriptionConfig{} _ Chattable = SetMyShortDescriptionConfig{}
_ Chattable = GetMyNameConfig{} _ Chattable = GetMyNameConfig{}
_ Chattable = SetMyNameConfig{} _ Chattable = SetMyNameConfig{}
_ Chattable = RefundStarPaymentConfig{}
) )
// Ensure all Fileable types are correct. // Ensure all Fileable types are correct.