Skip to content

Commit 090d2e4

Browse files
committed
BotAPI 8.0 implementation
1 parent 13667f2 commit 090d2e4

File tree

4 files changed

+239
-2
lines changed

4 files changed

+239
-2
lines changed

configs.go

Lines changed: 137 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,30 @@ func (config UserProfilePhotosConfig) params() (Params, error) {
13311331
return params, nil
13321332
}
13331333

1334+
// SetUserEmojiStatusConfig changes the emoji status for a given user that
1335+
// previously allowed the bot to manage their emoji status via
1336+
// the Mini App method requestEmojiStatusAccess.
1337+
// Returns True on success.
1338+
type SetUserEmojiStatusConfig struct {
1339+
UserID int64 // required
1340+
EmojiStatusCustomEmojiID string
1341+
EmojiStatusExpirationDate int64
1342+
}
1343+
1344+
func (SetUserEmojiStatusConfig) method() string {
1345+
return "setUserEmojiStatus"
1346+
}
1347+
1348+
func (config SetUserEmojiStatusConfig) params() (Params, error) {
1349+
params := make(Params)
1350+
1351+
params.AddNonZero64("user_id", config.UserID)
1352+
params.AddNonEmpty("emoji_status_custom_emoji_id", config.EmojiStatusCustomEmojiID)
1353+
params.AddNonZero64("emoji_status_expiration_date ", config.EmojiStatusExpirationDate)
1354+
1355+
return params, nil
1356+
}
1357+
13341358
// FileConfig has information about a file hosted on Telegram.
13351359
type FileConfig struct {
13361360
FileID string
@@ -1497,6 +1521,38 @@ func (config AnswerWebAppQueryConfig) params() (Params, error) {
14971521
return params, err
14981522
}
14991523

1524+
// SavePreparedInlineMessageConfig stores a message that can be sent by a user of a Mini App.
1525+
// Returns a PreparedInlineMessage object.
1526+
type SavePreparedInlineMessageConfig[T InlineQueryResults] struct {
1527+
UserID int64 // required
1528+
Result T // required
1529+
AllowUserChats bool
1530+
AllowBotChats bool
1531+
AllowGroupChats bool
1532+
AllowChannelChats bool
1533+
}
1534+
1535+
func (config SavePreparedInlineMessageConfig[T]) method() string {
1536+
return "savePreparedInlineMessage"
1537+
}
1538+
1539+
func (config SavePreparedInlineMessageConfig[T]) params() (Params, error) {
1540+
params := make(Params)
1541+
1542+
params.AddNonZero64("user_id", config.UserID)
1543+
err := params.AddInterface("result", config.Result)
1544+
if err != nil {
1545+
return params, err
1546+
}
1547+
1548+
params.AddBool("allow_user_chats", config.AllowUserChats)
1549+
params.AddBool("allow_bot_chats", config.AllowBotChats)
1550+
params.AddBool("allow_group_chats", config.AllowGroupChats)
1551+
params.AddBool("allow_channel_chats", config.AllowChannelChats)
1552+
1553+
return params, err
1554+
}
1555+
15001556
// CallbackConfig contains information on making a CallbackQuery response.
15011557
type CallbackConfig struct {
15021558
CallbackQueryID string `json:"callback_query_id"`
@@ -2082,12 +2138,14 @@ func (config InvoiceConfig) method() string {
20822138

20832139
// InvoiceLinkConfig contains information for createInvoiceLink method
20842140
type InvoiceLinkConfig struct {
2141+
BusinessConnectionID BusinessConnectionID
20852142
Title string // Required
20862143
Description string // Required
20872144
Payload string // Required
20882145
ProviderToken string // Required
20892146
Currency string // Required
20902147
Prices []LabeledPrice // Required
2148+
SubscriptionPeriod int
20912149
MaxTipAmount int
20922150
SuggestedTipAmounts []int
20932151
ProviderData string
@@ -2105,7 +2163,10 @@ type InvoiceLinkConfig struct {
21052163
}
21062164

21072165
func (config InvoiceLinkConfig) params() (Params, error) {
2108-
params := make(Params)
2166+
params, err := config.BusinessConnectionID.params()
2167+
if err != nil {
2168+
return params, err
2169+
}
21092170

21102171
params["title"] = config.Title
21112172
params["description"] = config.Description
@@ -2115,9 +2176,13 @@ func (config InvoiceLinkConfig) params() (Params, error) {
21152176
return params, err
21162177
}
21172178

2179+
params.AddNonZero("subscription_period", config.SubscriptionPeriod)
21182180
params.AddNonEmpty("provider_token", config.ProviderToken)
21192181
params.AddNonZero("max_tip_amount", config.MaxTipAmount)
2120-
err := params.AddInterface("suggested_tip_amounts", config.SuggestedTipAmounts)
2182+
err = params.AddInterface("suggested_tip_amounts", config.SuggestedTipAmounts)
2183+
if err != nil {
2184+
return params, err
2185+
}
21212186
params.AddNonEmpty("provider_data", config.ProviderData)
21222187
params.AddNonEmpty("photo_url", config.PhotoURL)
21232188
params.AddNonZero("photo_size", config.PhotoSize)
@@ -2223,6 +2288,28 @@ func (config RefundStarPaymentConfig) params() (Params, error) {
22232288
return params, nil
22242289
}
22252290

2291+
// EditUserStarSubscriptionConfig allows the bot to cancel or re-enable extension
2292+
// of a subscription paid in Telegram Stars. Returns True on success.
2293+
type EditUserStarSubscriptionConfig struct {
2294+
UserID int64 // required
2295+
TelegramPaymentChargeID string // required
2296+
IsCanceled bool // required
2297+
}
2298+
2299+
func (config EditUserStarSubscriptionConfig) method() string {
2300+
return "editUserStarSubscription"
2301+
}
2302+
2303+
func (config EditUserStarSubscriptionConfig) params() (Params, error) {
2304+
params := make(Params)
2305+
2306+
params["telegram_payment_charge_id"] = config.TelegramPaymentChargeID
2307+
params.AddNonZero64("user_id", config.UserID)
2308+
params.AddBool("is_canceled", config.IsCanceled)
2309+
2310+
return params, nil
2311+
}
2312+
22262313
// DeleteMessageConfig contains information of a message in a chat to delete.
22272314
type DeleteMessageConfig struct {
22282315
BaseChatMessage
@@ -2249,6 +2336,54 @@ func (config DeleteMessagesConfig) params() (Params, error) {
22492336
return config.BaseChatMessages.params()
22502337
}
22512338

2339+
// GetAvailableGiftsConfig returns the list of gifts that can be sent by the bot
2340+
// to users and channel chats. Requires no parameters. Returns a Gifts object.
2341+
type GetAvailableGiftsConfig struct{}
2342+
2343+
func (config GetAvailableGiftsConfig) method() string {
2344+
return "getAvailableGifts"
2345+
}
2346+
2347+
func (config GetAvailableGiftsConfig) params() (Params, error) {
2348+
return nil, nil
2349+
}
2350+
2351+
// SendGiftConfig sends a gift to the given user or channel chat.
2352+
// The gift can't be converted to Telegram Stars by the receiver.
2353+
// Returns True on success.
2354+
type SendGiftConfig struct {
2355+
UserID int64
2356+
Chat ChatConfig
2357+
GiftID string // required
2358+
PayForUpgrade bool
2359+
Text string
2360+
TextParseMode string
2361+
TextEntities []MessageEntity
2362+
}
2363+
2364+
func (config SendGiftConfig) method() string {
2365+
return "sendGift"
2366+
}
2367+
2368+
func (config SendGiftConfig) params() (Params, error) {
2369+
params := make(Params)
2370+
params.AddNonZero64("user_id", config.UserID)
2371+
2372+
p1, err := config.Chat.params()
2373+
if err != nil {
2374+
return params, err
2375+
}
2376+
params.Merge(p1)
2377+
2378+
params.AddNonEmpty("gift_id", config.GiftID)
2379+
params.AddBool("pay_for_upgrade", config.PayForUpgrade)
2380+
params.AddNonEmpty("text", config.Text)
2381+
params.AddNonEmpty("text_parse_mode", config.Text)
2382+
params.AddInterface("text_entities", config.TextEntities)
2383+
2384+
return params, nil
2385+
}
2386+
22522387
// PinChatMessageConfig contains information of a message in a chat to pin.
22532388
type PinChatMessageConfig struct {
22542389
BaseChatMessage

helper_methods.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,17 @@ func NewUserProfilePhotos(userID int64) UserProfilePhotosConfig {
345345
}
346346
}
347347

348+
// NewSetUserEmojiStatus changes the user's emoji status.
349+
//
350+
// userID is the ID of the user you wish to get profile photos from.
351+
func NewSetUserEmojiStatus(userID int64, emojiID string, statusExpDate int64) SetUserEmojiStatusConfig {
352+
return SetUserEmojiStatusConfig{
353+
UserID: userID,
354+
EmojiStatusCustomEmojiID: emojiID,
355+
EmojiStatusExpirationDate: statusExpDate,
356+
}
357+
}
358+
348359
// NewUpdate gets updates since the last Offset.
349360
//
350361
// offset is the last Update ID to include.

types.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,38 @@ type ForumTopic struct {
32263226
IconCustomEmojiID string `json:"icon_custom_emoji_id,omitempty"`
32273227
}
32283228

3229+
// Gift object represents a gift that can be sent by the bot.
3230+
type Gift struct {
3231+
// ID is an unique identifier of the gift
3232+
ID string `json:"id"`
3233+
// Sticker is the sticker that represents the gift
3234+
Sticker Sticker `json:"sticker"`
3235+
// StarCount is the number of Telegram Stars that
3236+
// must be paid to send the sticker
3237+
StarCount int `json:"star_count"`
3238+
// UpgradeStarCount is the number of Telegram Stars that
3239+
// must be paid to upgrade the gift to a unique one
3240+
//
3241+
// optional
3242+
UpgradeStarCount int `json:"upgrade_star_count,omitempty"`
3243+
// TotalCount is the total number of the gifts of this type that
3244+
// can be sent; for limited gifts only
3245+
//
3246+
// optional
3247+
TotalCount int `json:"total_count,omitempty"`
3248+
// RemainingCount is the number of remaining gifts of this type that
3249+
// can be sent; for limited gifts only
3250+
//
3251+
// optional
3252+
RemainingCount int `json:"remaining_count,omitempty"`
3253+
}
3254+
3255+
// Gifts object represents a list of gifts.
3256+
type Gifts struct {
3257+
// Gifts is the list of gifts
3258+
Gifts []Gift `json:"gifts"`
3259+
}
3260+
32293261
// BotCommand represents a bot command.
32303262
type BotCommand struct {
32313263
// Command text of the command, 1-32 characters.
@@ -3993,6 +4025,29 @@ type InlineQuery struct {
39934025
Location *Location `json:"location,omitempty"`
39944026
}
39954027

4028+
// InlineQueryResults defines a type constraint interface that includes all valid
4029+
// inline query result types supported by the Telegram Bot API. This interface
4030+
// allows methods to accept any of these result types, enabling strict type checking
4031+
// and ensuring only supported inline query results are used.
4032+
type InlineQueryResults interface {
4033+
InlineQueryResultCachedAudio |
4034+
InlineQueryResultCachedDocument |
4035+
InlineQueryResultCachedPhoto |
4036+
InlineQueryResultCachedSticker |
4037+
InlineQueryResultCachedVideo |
4038+
InlineQueryResultCachedVoice |
4039+
InlineQueryResultArticle |
4040+
InlineQueryResultAudio |
4041+
InlineQueryResultContact |
4042+
InlineQueryResultGame |
4043+
InlineQueryResultDocument |
4044+
InlineQueryResultLocation |
4045+
InlineQueryResultPhoto |
4046+
InlineQueryResultVenue |
4047+
InlineQueryResultVideo |
4048+
InlineQueryResultVoice
4049+
}
4050+
39964051
// InlineQueryResultCachedAudio is an inline query response with cached audio.
39974052
type InlineQueryResultCachedAudio struct {
39984053
// Type of the result, must be audio
@@ -4862,6 +4917,15 @@ type SentWebAppMessage struct {
48624917
InlineMessageID string `json:"inline_message_id,omitempty"`
48634918
}
48644919

4920+
// PreparedInlineMessage describes an inline message to be sent by a user of a Mini App.
4921+
type PreparedInlineMessage struct {
4922+
// ID is an unique identifier of the prepared message
4923+
ID string `json:"id"`
4924+
// ExpirationDate of the prepared message, in Unix time.
4925+
// Expired prepared messages can no longer be used
4926+
ExpirationDate int64 `json:"expiration_date"`
4927+
}
4928+
48654929
// InputTextMessageContent contains text for displaying
48664930
// as an inline query result.
48674931
type InputTextMessageContent struct {
@@ -5138,6 +5202,19 @@ type SuccessfulPayment struct {
51385202
TotalAmount int `json:"total_amount"`
51395203
// InvoicePayload bot specified invoice payload
51405204
InvoicePayload string `json:"invoice_payload"`
5205+
// SubscriptionExpirationDate is an expiration date of the subscription,
5206+
// in Unix time; for recurring payments only
5207+
//
5208+
// optional
5209+
SubscriptionExpirationDate int64 `json:"subscription_expiration_date,omitempty"`
5210+
// IsRecurring is True, if the payment is a recurring payment for a subscription
5211+
//
5212+
// optional
5213+
IsRecurring bool `json:"is_recurring,omitempty"`
5214+
// IsFirstRecurring is True, if the payment is the first payment for a subscription
5215+
//
5216+
// optional
5217+
IsFirstRecurring bool `json:"is_first_recurring,omitempty"`
51415218
// ShippingOptionID identifier of the shipping option chosen by the user
51425219
//
51435220
// optional
@@ -5266,12 +5343,24 @@ type TransactionPartner struct {
52665343
//
52675344
// optional
52685345
InvoicePayload string `json:"invoice_payload,omitempty"`
5346+
// SubscriptionPeriod is the duration of the paid subscription.
5347+
// Can be available only for “invoice_payment” transactions.
5348+
// Represent only in "user" state
5349+
//
5350+
// optional
5351+
SubscriptionPeriod int64 `json:"subscription_period,omitempty"`
52695352
// PaidMedia is the nformation about the paid media
52705353
// bought by the user
52715354
// Represent only in "user" state
52725355
//
52735356
// optional
52745357
PaidMedia []PaidMedia `json:"paid_media,omitempty"`
5358+
// Gift is the gift sent to the user by the bot;
5359+
// for “gift_purchase” transactions only
5360+
// Represent only in "user" state
5361+
//
5362+
// optional
5363+
Gift *Gift `json:"gift,omitempty"`
52755364
// RequestCount is the number of successful requests that
52765365
// exceeded regular limits and were therefore billed
52775366
// Represent only in "telegram_api" state

types_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ var (
297297
_ Chattable = DeleteChatPhotoConfig{}
298298
_ Chattable = DeleteChatStickerSetConfig{}
299299
_ Chattable = DeleteMessageConfig{}
300+
_ Chattable = GetAvailableGiftsConfig{}
300301
_ Chattable = DeleteMyCommandsConfig{}
301302
_ Chattable = DeleteWebhookConfig{}
302303
_ Chattable = DocumentConfig{}
@@ -347,6 +348,7 @@ var (
347348
_ Chattable = UpdateConfig{}
348349
_ Chattable = SetMessageReactionConfig{}
349350
_ Chattable = UserProfilePhotosConfig{}
351+
_ Chattable = SetUserEmojiStatusConfig{}
350352
_ Chattable = VenueConfig{}
351353
_ Chattable = VideoConfig{}
352354
_ Chattable = VideoNoteConfig{}

0 commit comments

Comments
 (0)