Skip to content

Commit 4baff31

Browse files
authored
Merge pull request #60 from OvyFlash/bot-api-8.0
BotAPI 8.0 implementation
2 parents 958048e + 8249a39 commit 4baff31

File tree

4 files changed

+235
-1
lines changed

4 files changed

+235
-1
lines changed

configs.go

Lines changed: 133 additions & 1 deletion
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"`
@@ -2087,12 +2143,14 @@ func (config InvoiceConfig) method() string {
20872143

20882144
// InvoiceLinkConfig contains information for createInvoiceLink method
20892145
type InvoiceLinkConfig struct {
2146+
BusinessConnectionID BusinessConnectionID
20902147
Title string // Required
20912148
Description string // Required
20922149
Payload string // Required
20932150
ProviderToken string // Required
20942151
Currency string // Required
20952152
Prices []LabeledPrice // Required
2153+
SubscriptionPeriod int
20962154
MaxTipAmount int
20972155
SuggestedTipAmounts []int
20982156
ProviderData string
@@ -2110,7 +2168,10 @@ type InvoiceLinkConfig struct {
21102168
}
21112169

21122170
func (config InvoiceLinkConfig) params() (Params, error) {
2113-
params := make(Params)
2171+
params, err := config.BusinessConnectionID.params()
2172+
if err != nil {
2173+
return params, err
2174+
}
21142175

21152176
params["title"] = config.Title
21162177
params["description"] = config.Description
@@ -2120,6 +2181,7 @@ func (config InvoiceLinkConfig) params() (Params, error) {
21202181
return params, err
21212182
}
21222183

2184+
params.AddNonZero("subscription_period", config.SubscriptionPeriod)
21232185
params.AddNonEmpty("provider_token", config.ProviderToken)
21242186
params.AddNonZero("max_tip_amount", config.MaxTipAmount)
21252187
if len(config.SuggestedTipAmounts) > 0 {
@@ -2233,6 +2295,28 @@ func (config RefundStarPaymentConfig) params() (Params, error) {
22332295
return params, nil
22342296
}
22352297

2298+
// EditUserStarSubscriptionConfig allows the bot to cancel or re-enable extension
2299+
// of a subscription paid in Telegram Stars. Returns True on success.
2300+
type EditUserStarSubscriptionConfig struct {
2301+
UserID int64 // required
2302+
TelegramPaymentChargeID string // required
2303+
IsCanceled bool // required
2304+
}
2305+
2306+
func (config EditUserStarSubscriptionConfig) method() string {
2307+
return "editUserStarSubscription"
2308+
}
2309+
2310+
func (config EditUserStarSubscriptionConfig) params() (Params, error) {
2311+
params := make(Params)
2312+
2313+
params["telegram_payment_charge_id"] = config.TelegramPaymentChargeID
2314+
params.AddNonZero64("user_id", config.UserID)
2315+
params.AddBool("is_canceled", config.IsCanceled)
2316+
2317+
return params, nil
2318+
}
2319+
22362320
// DeleteMessageConfig contains information of a message in a chat to delete.
22372321
type DeleteMessageConfig struct {
22382322
BaseChatMessage
@@ -2259,6 +2343,54 @@ func (config DeleteMessagesConfig) params() (Params, error) {
22592343
return config.BaseChatMessages.params()
22602344
}
22612345

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