all repos — telegram-bot-api @ a8238b8afdf33cb2cf76730e43cbd5c57d82a299

Golang bindings for the Telegram Bot API

Bot API 7.6 implementation
stdkhai k.o.zhuk@student.khai.edu
Tue, 02 Jul 2024 11:47:58 +0300
commit

a8238b8afdf33cb2cf76730e43cbd5c57d82a299

parent

6bd5d1256a8aea56428054bb7f298b7369a2bbc3

3 files changed, 162 insertions(+), 0 deletions(-)

jump to
M configs.goconfigs.go

@@ -377,6 +377,7 @@ return "forwardMessages"

} // CopyMessageConfig contains information about a copyMessage request. +// Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. type CopyMessageConfig struct { BaseChat FromChat ChatConfig

@@ -412,6 +413,7 @@ return "copyMessage"

} // CopyMessagesConfig contains information about a copyMessages request. +// Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. type CopyMessagesConfig struct { BaseChat FromChat ChatConfig

@@ -758,6 +760,58 @@ })

} return files +} + +// Use this method to send paid media to channel chats. On success, the sent Message is returned. +type PaidMediaConfig struct { + BaseChat + StarCount int64 + Media []InputPaidMedia + Caption string // optional + ParseMode string // optional + CaptionEntities []MessageEntity // optional + ShowCaptionAboveMedia bool // optional +} + +func (config PaidMediaConfig) params() (Params, error) { + params, err := config.BaseChat.params() + if err != nil { + return params, err + } + + params.AddNonZero64("star_count", config.StarCount) + params.AddNonEmpty("caption", config.Caption) + params.AddNonEmpty("parse_mode", config.ParseMode) + params.AddBool("show_caption_above_media", config.ShowCaptionAboveMedia) + + err = params.AddInterface("media", config.Media) + if err != nil { + return params, err + } + err = params.AddInterface("caption_entities", config.CaptionEntities) + return params, err +} + +func (config PaidMediaConfig) files() []RequestFile { + files := []RequestFile{} + for i, v := range config.Media { + files = append(files, RequestFile{ + Name: fmt.Sprintf("%s-%d", v.Type, i), + Data: v.Media, + }) + if v.Thumb != nil { + files = append(files, RequestFile{ + Name: fmt.Sprintf("thumbnail-%d", i), + Data: v.Thumb, + }) + } + } + + return files +} + +func (config PaidMediaConfig) method() string { + return "sendPaidMedia" } // VoiceConfig contains information about a SendVoice request.
M types.gotypes.go

@@ -436,6 +436,11 @@ // supergroups. Returned only in getChat.

// // optional Permissions *ChatPermissions `json:"permissions,omitempty"` + // True, if paid media messages can be sent or forwarded to the channel chat. + // The field is available only for channel chats. + // + // optional + CanSendPaidMedia bool `json:"can_send_paid_media,omitempty"` // SlowModeDelay is for supergroups, the minimum allowed delay between // consecutive messages sent by each unprivileged user. Returned only in // getChat.

@@ -673,6 +678,10 @@ // Document message is a general file, information about the file;

// // optional Document *Document `json:"document,omitempty"` + // Message contains paid media; information about the paid media + // + // optional + PaidMedia *PaidMediaInfo `json:"paid_media,omitempty"` // Photo message is a photo, available sizes of the photo; // // optional

@@ -1153,6 +1162,10 @@ // Document message is a general file, information about the file;

// // optional Document *Document `json:"document,omitempty"` + // Message contains paid media; information about the paid media + // + // optional + PaidMedia *PaidMediaInfo `json:"paid_media,omitempty"` // Photo message is a photo, available sizes of the photo; // // optional

@@ -1514,6 +1527,47 @@ // optional

FileSize int64 `json:"file_size,omitempty"` } +// PaidMediaInfo describes the paid media added to a message. +type PaidMediaInfo struct { + // The number of Telegram Stars that must be paid to buy access to the media + StarCount int64 `json:"star_count"` + // Information about the paid media + PaidMedia []PaidMedia `json:"paid_media"` +} + +// This object describes paid media. Currently, it can be one of +// - PaidMediaPreview +// - PaidMediaPhoto +// - PaidMediaVideo +type PaidMedia struct { + // Type of the paid media, should be one of: + // - "photo" + // - "video" + // - "preview" + Type string `json:"type"` + // PaidMediaPreview only. + // Media width as defined by the sender. + // + // optional + Width int64 `json:"width,omitempty"` + // PaidMediaPreview only. + // Media height as defined by the sender + // + // optional + Height int64 `json:"height,omitempty"` + // PaidMediaPreview only. + // Duration of the media in seconds as defined by the sender + // + // optional + Duration int64 `json:"duration,omitempty"` + // PaidMediaPhoto only. + // The photo + Photo *[]PhotoSize `json:"photo,omitempty"` + // PaidMediaVideo only. + // The video + Video *Video `json:"video,omitempty"` +} + // Contact represents a phone contact. // // Note that LastName and UserID may be empty.

@@ -3153,6 +3207,9 @@ // Text is the text on the button, for `web_app` type.

Text string `json:"text,omitempty"` // WebApp is the description of the Web App that will be launched when the // user presses the button for the `web_app` type. + // + // Alternatively, a t.me link to a Web App of the bot can be specified in the object instead of the Web App's URL, + // in which case the Web App will be opened as if the user pressed the link. WebApp *WebAppInfo `json:"web_app,omitempty"` }

@@ -3414,6 +3471,48 @@ // optional

DisableContentTypeDetection bool `json:"disable_content_type_detection,omitempty"` } +// This object describes the paid media to be sent. Currently, it can be one of: +// - InputPaidMediaPhoto +// - InputPaidMediaVideo +type InputPaidMedia struct { + // Type of the media, must be one of: + // - "photo" + // - "video" + Type string `json:"type"` + // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), + // pass an HTTP URL for Telegram to get a file from the Internet, + // or pass “attach://<file_attach_name>” to upload a new one using multipart/form-data under <file_attach_name> name. + // More information on https://core.telegram.org/bots/api#sending-files + Media RequestFileData `json:"media"` + // InputPaidMediaVideo only. + // Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. + // The thumbnail should be in JPEG format and less than 200 kB in size. + // A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. + // Thumbnails can't be reused and can be only uploaded as a new file, + // so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. + // + // optional + Thumb RequestFileData `json:"thumbnail"` + // InputPaidMediaVideo only. + // Video width + // + // optional + Width int64 `json:"width,omitempty"` + // InputPaidMediaVideo only. + // Video height + // + // optional + Height int64 `json:"height,omitempty"` + // InputPaidMediaVideo only. + // Video duration in seconds + // + // optional + Duration int64 `json:"duration,omitempty"` + // InputPaidMediaVideo only. + // Pass True if the uploaded video is suitable for streaming + SupportsStreaming bool `json:"supports_streaming,omitempty"` +} + // Constant values for sticker types const ( StickerTypeRegular = "regular"

@@ -4918,11 +5017,13 @@ // TransactionPartner describes the source of a transaction, or its recipient for outgoing transactions. Currently, it can be one of

// - TransactionPartnerFragment // - TransactionPartnerUser // - TransactionPartnerOther +// - TransactionPartnerTelegramAds type TransactionPartner struct { //Type of the transaction partner. Must be one of: // - fragment // - user // - other + // - telegram_ads Type string `json:"type"` // State of the transaction if the transaction is outgoing. // Represent only in "fragment" state

@@ -4932,6 +5033,11 @@ WithdrawalState *RevenueWithdrawalState `json:"withdrawal_state,omitempty"`

// Information about the user. // Represent only in "user" state User *User `json:"user,omitempty"` + // TransactionPartnerUser only. + // Bot-specified invoice payload + // + // optional + InvoicePayload string `json:"invoice_payload,omitempty"` } // StarTransaction describes a Telegram Star transaction.
M types_test.gotypes_test.go

@@ -377,6 +377,7 @@ _ Chattable = GetMyNameConfig{}

_ Chattable = SetMyNameConfig{} _ Chattable = RefundStarPaymentConfig{} _ Chattable = GetStarTransactionsConfig{} + _ Chattable = PaidMediaConfig{} ) // Ensure all Fileable types are correct.

@@ -398,6 +399,7 @@ _ Fileable = (*AddStickerConfig)(nil)

_ Fileable = (*MediaGroupConfig)(nil) _ Fileable = (*WebhookConfig)(nil) _ Fileable = (*SetStickerSetThumbConfig)(nil) + _ Fileable = (*PaidMediaConfig)(nil) ) // Ensure all RequestFileData types are correct.