From 6c989b2cc8d025645c2f182a8e1373855797f0f0 Mon Sep 17 00:00:00 2001 From: ScuroNeko Date: Thu, 12 Feb 2026 11:16:01 +0300 Subject: [PATCH] WIP v0.5.0 --- bot.go | 14 +- handler.go | 4 +- methods.go | 15 +- msg_context.go | 18 +-- tgapi/attachments_methods.go | 8 +- tgapi/bot_methods.go | 64 ++++---- tgapi/business_methods.go | 92 +++++------ tgapi/chat_methods.go | 124 +++++++-------- tgapi/forum_methods.go | 48 +++--- tgapi/messages_methods.go | 183 +++++++++++++++++++++- tgapi/methods.go | 4 + tgapi/stickers_methods.go | 60 ++++---- tgapi/uploader.go | 288 +++++++++++++++++++++++++++++------ tgapi/users_methods.go | 16 +- 14 files changed, 651 insertions(+), 287 deletions(-) diff --git a/bot.go b/bot.go index e92db57..884a3e2 100644 --- a/bot.go +++ b/bot.go @@ -35,13 +35,13 @@ type Bot struct { dbWriterRequested extypes.Slice[*slog.Logger] updateOffset int - updateTypes []string + updateTypes []tgapi.UpdateType updateQueue *extypes.Queue[*tgapi.Update] } func (b *Bot) GetUpdateOffset() int { return b.updateOffset } func (b *Bot) SetUpdateOffset(offset int) { b.updateOffset = offset } -func (b *Bot) GetUpdateTypes() []string { return b.updateTypes } +func (b *Bot) GetUpdateTypes() []tgapi.UpdateType { return b.updateTypes } func (b *Bot) GetQueue() *extypes.Queue[*tgapi.Update] { return b.updateQueue } type BotSettings struct { @@ -79,7 +79,7 @@ func NewBot(settings *BotSettings) *Bot { api := tgapi.NewAPI(settings.Token) bot := &Bot{ updateOffset: 0, plugins: make([]Plugin, 0), debug: settings.Debug, errorTemplate: "%s", - prefixes: settings.Prefixes, updateTypes: make([]string, 0), runners: make([]Runner, 0), + prefixes: settings.Prefixes, updateTypes: make([]tgapi.UpdateType, 0), runners: make([]Runner, 0), updateQueue: updateQueue, api: api, dbWriterRequested: make([]*slog.Logger, 0), token: settings.Token, } @@ -163,12 +163,12 @@ func (b *Bot) DatabaseContext(ctx *DatabaseContext) *Bot { b.dbContext = ctx return b } -func (b *Bot) UpdateTypes(t ...string) *Bot { - b.updateTypes = make([]string, 0) +func (b *Bot) UpdateTypes(t ...tgapi.UpdateType) *Bot { + b.updateTypes = make([]tgapi.UpdateType, 0) b.updateTypes = append(b.updateTypes, t...) return b } -func (b *Bot) AddUpdateType(t ...string) *Bot { +func (b *Bot) AddUpdateType(t ...tgapi.UpdateType) *Bot { b.updateTypes = append(b.updateTypes, t...) return b } @@ -257,7 +257,7 @@ func (b *Bot) Run() { continue } - ctx := &MsgContext{Bot: b, Update: u, Api: b.api} + ctx := &MsgContext{Bot: b, Update: *u, Api: b.api} for _, middleware := range b.middlewares { middleware.Execute(ctx, b.dbContext) } diff --git a/handler.go b/handler.go index 464161c..064f96e 100644 --- a/handler.go +++ b/handler.go @@ -71,8 +71,8 @@ func (b *Bot) handleCallback(update *tgapi.Update, ctx *MsgContext) { } ctx.FromID = update.CallbackQuery.From.ID - ctx.From = update.CallbackQuery.From - ctx.Msg = update.CallbackQuery.Message + ctx.From = &update.CallbackQuery.From + ctx.Msg = &update.CallbackQuery.Message ctx.CallbackMsgId = update.CallbackQuery.Message.MessageID ctx.CallbackQueryId = update.CallbackQuery.ID ctx.Args = data.Args diff --git a/methods.go b/methods.go index f2b240b..d2a1f10 100644 --- a/methods.go +++ b/methods.go @@ -9,23 +9,22 @@ import ( "git.nix13.pw/scuroneko/laniakea/tgapi" ) -func (b *Bot) Updates() ([]*tgapi.Update, error) { +func (b *Bot) Updates() ([]tgapi.Update, error) { offset := b.GetUpdateOffset() params := tgapi.UpdateParams{ - Offset: offset, - Timeout: 30, + Offset: Ptr(offset), + Timeout: Ptr(30), AllowedUpdates: b.GetUpdateTypes(), } - req := tgapi.NewRequest[[]*tgapi.Update]("getUpdates", params) - res, err := req.Do(b.api) + updates, err := b.api.GetUpdates(params) if err != nil { return nil, err } - for _, u := range *res { + for _, u := range updates { b.SetUpdateOffset(u.UpdateID + 1) - err = b.GetQueue().Enqueue(u) + err = b.GetQueue().Enqueue(&u) if err != nil { return nil, err } @@ -38,7 +37,7 @@ func (b *Bot) Updates() ([]*tgapi.Update, error) { b.RequestLogger.Debugf("UPDATE %s\n", j) } } - return *res, err + return updates, err } func (b *Bot) GetFileByLink(link string) ([]byte, error) { diff --git a/msg_context.go b/msg_context.go index 922ba4f..d19274f 100644 --- a/msg_context.go +++ b/msg_context.go @@ -12,7 +12,7 @@ type MsgContext struct { Api *tgapi.Api Msg *tgapi.Message - Update *tgapi.Update + Update tgapi.Update From *tgapi.User CallbackMsgId int CallbackQueryId string @@ -31,7 +31,7 @@ type AnswerMessage struct { } func (ctx *MsgContext) edit(messageId int, text string, keyboard *InlineKeyboard) *AnswerMessage { - params := &tgapi.EditMessageTextP{ + params := tgapi.EditMessageTextP{ MessageID: messageId, ChatID: ctx.Msg.Chat.ID, Text: text, @@ -40,7 +40,7 @@ func (ctx *MsgContext) edit(messageId int, text string, keyboard *InlineKeyboard if keyboard != nil { params.ReplyMarkup = keyboard.Get() } - msg, err := ctx.Api.EditMessageText(params) + msg, _, err := ctx.Api.EditMessageText(params) if err != nil { ctx.Api.Logger.Errorln(err) return nil @@ -65,7 +65,7 @@ func (ctx *MsgContext) EditCallbackf(format string, keyboard *InlineKeyboard, ar } func (ctx *MsgContext) editPhotoText(messageId int, text string, kb *InlineKeyboard) *AnswerMessage { - params := &tgapi.EditMessageCaptionP{ + params := tgapi.EditMessageCaptionP{ ChatID: ctx.Msg.Chat.ID, MessageID: messageId, Caption: text, @@ -74,7 +74,7 @@ func (ctx *MsgContext) editPhotoText(messageId int, text string, kb *InlineKeybo if kb != nil { params.ReplyMarkup = kb.Get() } - msg, err := ctx.Api.EditMessageCaption(params) + msg, _, err := ctx.Api.EditMessageCaption(params) if err != nil { ctx.Api.Logger.Errorln(err) } @@ -94,7 +94,7 @@ func (m *AnswerMessage) EditCaptionKeyboard(text string, kb *InlineKeyboard) *An } func (ctx *MsgContext) answer(text string, keyboard *InlineKeyboard) *AnswerMessage { - params := &tgapi.SendMessageP{ + params := tgapi.SendMessageP{ ChatID: ctx.Msg.Chat.ID, Text: text, ParseMode: tgapi.ParseMD, @@ -123,7 +123,7 @@ func (ctx *MsgContext) Keyboard(text string, kb *InlineKeyboard) *AnswerMessage } func (ctx *MsgContext) answerPhoto(photoId, text string, kb *InlineKeyboard) *AnswerMessage { - params := &tgapi.SendPhotoP{ + params := tgapi.SendPhotoP{ ChatID: ctx.Msg.Chat.ID, Caption: text, ParseMode: tgapi.ParseMD, @@ -151,7 +151,7 @@ func (ctx *MsgContext) AnswerPhotoKeyboard(photoId, text string, kb *InlineKeybo } func (ctx *MsgContext) delete(messageId int) { - _, err := ctx.Api.DeleteMessage(&tgapi.DeleteMessageP{ + _, err := ctx.Api.DeleteMessage(tgapi.DeleteMessageP{ ChatID: ctx.Msg.Chat.ID, MessageID: messageId, }) @@ -170,7 +170,7 @@ func (ctx *MsgContext) answerCallbackQuery(url, text string, showAlert bool) { if len(ctx.CallbackQueryId) == 0 { return } - _, err := ctx.Api.AnswerCallbackQuery(&tgapi.AnswerCallbackQueryP{ + _, err := ctx.Api.AnswerCallbackQuery(tgapi.AnswerCallbackQueryP{ CallbackQueryID: ctx.CallbackQueryId, Text: text, ShowAlert: showAlert, URL: url, }) diff --git a/tgapi/attachments_methods.go b/tgapi/attachments_methods.go index 9241a68..2e38771 100644 --- a/tgapi/attachments_methods.go +++ b/tgapi/attachments_methods.go @@ -144,8 +144,8 @@ type SendAnimationP struct { ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"` } -func (api *Api) SendAnimation(p SendAnimationP) (Message, error) { - req := NewRequest[Message]("sendAnimation", p) +func (api *Api) SendAnimation(params SendAnimationP) (Message, error) { + req := NewRequest[Message]("sendAnimation", params) return req.Do(api) } @@ -240,7 +240,7 @@ type SendMediaGroupP struct { ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"` } -func (api *Api) SendMediaGroup(p SendMediaGroupP) (Message, error) { - req := NewRequest[Message]("sendMediaGroup", p) +func (api *Api) SendMediaGroup(params SendMediaGroupP) (Message, error) { + req := NewRequest[Message]("sendMediaGroup", params) return req.Do(api) } diff --git a/tgapi/bot_methods.go b/tgapi/bot_methods.go index 97e72b8..05741ae 100644 --- a/tgapi/bot_methods.go +++ b/tgapi/bot_methods.go @@ -6,8 +6,8 @@ type SetMyCommandsP struct { Language string `json:"language_code,omitempty"` } -func (api *Api) SetMyCommands(p SetMyCommandsP) (bool, error) { - req := NewRequest[bool]("setMyCommands", p) +func (api *Api) SetMyCommands(params SetMyCommandsP) (bool, error) { + req := NewRequest[bool]("setMyCommands", params) return req.Do(api) } @@ -16,8 +16,8 @@ type DeleteMyCommandsP struct { Language string `json:"language_code,omitempty"` } -func (api *Api) DeleteMyCommands(p DeleteMyCommandsP) (bool, error) { - req := NewRequest[bool]("deleteMyCommands", p) +func (api *Api) DeleteMyCommands(params DeleteMyCommandsP) (bool, error) { + req := NewRequest[bool]("deleteMyCommands", params) return req.Do(api) } @@ -26,8 +26,8 @@ type GetMyCommands struct { Language string `json:"language_code,omitempty"` } -func (api *Api) GetMyCommands(p GetMyCommands) ([]BotCommand, error) { - req := NewRequest[[]BotCommand]("getMyCommands", p) +func (api *Api) GetMyCommands(params GetMyCommands) ([]BotCommand, error) { + req := NewRequest[[]BotCommand]("getMyCommands", params) return req.Do(api) } @@ -36,8 +36,8 @@ type SetMyName struct { Language string `json:"language_code,omitempty"` } -func (api *Api) SetMyName(p SetMyName) (bool, error) { - req := NewRequest[bool]("setMyName", p) +func (api *Api) SetMyName(params SetMyName) (bool, error) { + req := NewRequest[bool]("setMyName", params) return req.Do(api) } @@ -45,8 +45,8 @@ type GetMyName struct { Language string `json:"language_code,omitempty"` } -func (api *Api) GetMyName(p GetMyName) (BotName, error) { - req := NewRequest[BotName]("getMyName", p) +func (api *Api) GetMyName(params GetMyName) (BotName, error) { + req := NewRequest[BotName]("getMyName", params) return req.Do(api) } @@ -55,8 +55,8 @@ type SetMyDescription struct { Language string `json:"language_code,omitempty"` } -func (api *Api) SetMyDescription(p SetMyDescription) (bool, error) { - req := NewRequest[bool]("setMyDescription", p) +func (api *Api) SetMyDescription(params SetMyDescription) (bool, error) { + req := NewRequest[bool]("setMyDescription", params) return req.Do(api) } @@ -64,8 +64,8 @@ type GetMyDescription struct { Language string `json:"language_code,omitempty"` } -func (api *Api) GetMyDescription(p GetMyDescription) (BotDescription, error) { - req := NewRequest[BotDescription]("getMyDescription", p) +func (api *Api) GetMyDescription(params GetMyDescription) (BotDescription, error) { + req := NewRequest[BotDescription]("getMyDescription", params) return req.Do(api) } @@ -74,8 +74,8 @@ type SetMyShortDescription struct { Language string `json:"language_code,omitempty"` } -func (api *Api) SetMyShortDescription(p SetMyShortDescription) (bool, error) { - req := NewRequest[bool]("setMyShortDescription", p) +func (api *Api) SetMyShortDescription(params SetMyShortDescription) (bool, error) { + req := NewRequest[bool]("setMyShortDescription", params) return req.Do(api) } @@ -83,8 +83,8 @@ type GetMyShortDescription struct { Language string `json:"language_code,omitempty"` } -func (api *Api) GetMyShortDescription(p GetMyShortDescription) (BotShortDescription, error) { - req := NewRequest[BotShortDescription]("getMyShortDescription", p) +func (api *Api) GetMyShortDescription(params GetMyShortDescription) (BotShortDescription, error) { + req := NewRequest[BotShortDescription]("getMyShortDescription", params) return req.Do(api) } @@ -92,8 +92,8 @@ type SetMyProfilePhotoP struct { Photo InputProfilePhoto `json:"photo"` } -func (api *Api) SetMyProfilePhoto(p SetMyProfilePhotoP) (bool, error) { - req := NewRequest[bool]("setMyProfilePhoto", p) +func (api *Api) SetMyProfilePhoto(params SetMyProfilePhotoP) (bool, error) { + req := NewRequest[bool]("setMyProfilePhoto", params) return req.Do(api) } func (api *Api) RemoveMyProfilePhoto() (bool, error) { @@ -106,8 +106,8 @@ type SetChatMenuButtonP struct { MenuButton MenuButtonType `json:"menu_button"` } -func (api *Api) SetChatMenuButton(p SetChatMenuButtonP) (bool, error) { - req := NewRequest[bool]("setChatMenuButton", p) +func (api *Api) SetChatMenuButton(params SetChatMenuButtonP) (bool, error) { + req := NewRequest[bool]("setChatMenuButton", params) return req.Do(api) } @@ -115,8 +115,8 @@ type GetChatMenuButtonP struct { ChatID int `json:"chat_id"` } -func (api *Api) GetChatMenuButton(p GetChatMenuButtonP) (BaseMenuButton, error) { - req := NewRequest[BaseMenuButton]("getChatMenuButton", p) +func (api *Api) GetChatMenuButton(params GetChatMenuButtonP) (BaseMenuButton, error) { + req := NewRequest[BaseMenuButton]("getChatMenuButton", params) return req.Do(api) } @@ -125,8 +125,8 @@ type SetMyDefaultAdministratorRightsP struct { ForChannels bool `json:"for_channels"` } -func (api *Api) SetMyDefaultAdministratorRights(p SetMyDefaultAdministratorRightsP) (bool, error) { - req := NewRequest[bool]("setMyDefaultAdministratorRights", p) +func (api *Api) SetMyDefaultAdministratorRights(params SetMyDefaultAdministratorRightsP) (bool, error) { + req := NewRequest[bool]("setMyDefaultAdministratorRights", params) return req.Do(api) } @@ -134,8 +134,8 @@ type GetMyDefaultAdministratorRightsP struct { ForChannels bool `json:"for_channels"` } -func (api *Api) GetMyDefaultAdministratorRights(p GetMyDefaultAdministratorRightsP) (ChatAdministratorRights, error) { - req := NewRequest[ChatAdministratorRights]("getMyDefaultAdministratorRights", p) +func (api *Api) GetMyDefaultAdministratorRights(params GetMyDefaultAdministratorRightsP) (ChatAdministratorRights, error) { + req := NewRequest[ChatAdministratorRights]("getMyDefaultAdministratorRights", params) return req.Do(api) } @@ -154,8 +154,8 @@ type SendGiftP struct { TextEntities []MessageEntity `json:"text_entities,omitempty"` } -func (api *Api) SendGift(p SendGiftP) (bool, error) { - req := NewRequest[bool]("sendGift", p) +func (api *Api) SendGift(params SendGiftP) (bool, error) { + req := NewRequest[bool]("sendGift", params) return req.Do(api) } @@ -168,7 +168,7 @@ type GiftPremiumSubscriptionP struct { TextEntities []MessageEntity `json:"text_entities,omitempty"` } -func (api *Api) GiftPremiumSubscription(p GiftPremiumSubscriptionP) (bool, error) { - req := NewRequest[bool]("giftPremiumSubscription", p) +func (api *Api) GiftPremiumSubscription(params GiftPremiumSubscriptionP) (bool, error) { + req := NewRequest[bool]("giftPremiumSubscription", params) return req.Do(api) } diff --git a/tgapi/business_methods.go b/tgapi/business_methods.go index fcc4660..ff6792c 100644 --- a/tgapi/business_methods.go +++ b/tgapi/business_methods.go @@ -5,8 +5,8 @@ type VerifyUserP struct { CustomDescription string `json:"custom_description,omitempty"` } -func (api *Api) VerifyUser(p VerifyUserP) (bool, error) { - req := NewRequest[bool]("verifyUser", p) +func (api *Api) VerifyUser(params VerifyUserP) (bool, error) { + req := NewRequest[bool]("verifyUser", params) return req.Do(api) } @@ -15,8 +15,8 @@ type VerifyChatP struct { CustomDescription string `json:"custom_description,omitempty"` } -func (api *Api) VerifyChat(p VerifyChatP) (bool, error) { - req := NewRequest[bool]("verifyChat", p) +func (api *Api) VerifyChat(params VerifyChatP) (bool, error) { + req := NewRequest[bool]("verifyChat", params) return req.Do(api) } @@ -24,8 +24,8 @@ type RemoveUserVerificationP struct { UserID int `json:"user_id"` } -func (api *Api) RemoveUserVerification(p RemoveUserVerificationP) (bool, error) { - req := NewRequest[bool]("removeUserVerification", p) +func (api *Api) RemoveUserVerification(params RemoveUserVerificationP) (bool, error) { + req := NewRequest[bool]("removeUserVerification", params) return req.Do(api) } @@ -33,8 +33,8 @@ type RemoveChatVerificationP struct { ChatID int `json:"chat_id"` } -func (api *Api) RemoveChatVerification(p RemoveChatVerificationP) (bool, error) { - req := NewRequest[bool]("removeChatVerification", p) +func (api *Api) RemoveChatVerification(params RemoveChatVerificationP) (bool, error) { + req := NewRequest[bool]("removeChatVerification", params) return req.Do(api) } @@ -44,8 +44,8 @@ type ReadBusinessMessageP struct { MessageID int `json:"message_id"` } -func (api *Api) ReadBusinessMessage(p ReadBusinessMessageP) (bool, error) { - req := NewRequest[bool]("readBusinessMessage", p) +func (api *Api) ReadBusinessMessage(params ReadBusinessMessageP) (bool, error) { + req := NewRequest[bool]("readBusinessMessage", params) return req.Do(api) } @@ -54,8 +54,8 @@ type DeleteBusinessMessageP struct { MessageIDs []int `json:"message_ids"` } -func (api *Api) DeleteBusinessMessage(p DeleteBusinessMessageP) (bool, error) { - req := NewRequest[bool]("deleteBusinessMessage", p) +func (api *Api) DeleteBusinessMessage(params DeleteBusinessMessageP) (bool, error) { + req := NewRequest[bool]("deleteBusinessMessage", params) return req.Do(api) } @@ -65,8 +65,8 @@ type SetBusinessAccountNameP struct { LastName string `json:"last_name,omitempty"` } -func (api *Api) SetBusinessAccountName(p SetBusinessAccountNameP) (bool, error) { - req := NewRequest[bool]("setBusinessAccountName", p) +func (api *Api) SetBusinessAccountName(params SetBusinessAccountNameP) (bool, error) { + req := NewRequest[bool]("setBusinessAccountName", params) return req.Do(api) } @@ -75,8 +75,8 @@ type SetBusinessAccountUsernameP struct { Username string `json:"username,omitempty"` } -func (api *Api) SetBusinessAccountUsername(p SetBusinessAccountUsernameP) (bool, error) { - req := NewRequest[bool]("setBusinessAccountUsername", p) +func (api *Api) SetBusinessAccountUsername(params SetBusinessAccountUsernameP) (bool, error) { + req := NewRequest[bool]("setBusinessAccountUsername", params) return req.Do(api) } @@ -85,8 +85,8 @@ type SetBusinessAccountBioP struct { Bio string `json:"bio,omitempty"` } -func (api *Api) SetBusinessAccountBio(p SetBusinessAccountBioP) (bool, error) { - req := NewRequest[bool]("setBusinessAccountBio", p) +func (api *Api) SetBusinessAccountBio(params SetBusinessAccountBioP) (bool, error) { + req := NewRequest[bool]("setBusinessAccountBio", params) return req.Do(api) } @@ -96,8 +96,8 @@ type SetBusinessAccountProfilePhoto struct { IsPublic bool `json:"is_public,omitempty"` } -func (api *Api) SetBusinessAccountProfilePhoto(p SetBusinessAccountProfilePhoto) (bool, error) { - req := NewRequest[bool]("setBusinessAccountProfilePhoto", p) +func (api *Api) SetBusinessAccountProfilePhoto(params SetBusinessAccountProfilePhoto) (bool, error) { + req := NewRequest[bool]("setBusinessAccountProfilePhoto", params) return req.Do(api) } @@ -106,8 +106,8 @@ type RemoveBusinessAccountProfilePhotoP struct { IsPublic bool `json:"is_public,omitempty"` } -func (api *Api) RemoveBusinessAccountProfilePhoto(p RemoveBusinessAccountProfilePhotoP) (bool, error) { - req := NewRequest[bool]("removeBusinessAccountProfilePhoto", p) +func (api *Api) RemoveBusinessAccountProfilePhoto(params RemoveBusinessAccountProfilePhotoP) (bool, error) { + req := NewRequest[bool]("removeBusinessAccountProfilePhoto", params) return req.Do(api) } @@ -117,8 +117,8 @@ type SetBusinessAccountGiftSettingsP struct { AcceptedGiftTypes AcceptedGiftTypes `json:"accepted_gift_types"` } -func (api *Api) SetBusinessAccountGiftSettings(p SetBusinessAccountGiftSettingsP) (bool, error) { - req := NewRequest[bool]("setBusinessAccountGiftSettings", p) +func (api *Api) SetBusinessAccountGiftSettings(params SetBusinessAccountGiftSettingsP) (bool, error) { + req := NewRequest[bool]("setBusinessAccountGiftSettings", params) return req.Do(api) } @@ -126,8 +126,8 @@ type GetBusinessAccountStarBalanceP struct { BusinessConnectionID string `json:"business_connection_id"` } -func (api *Api) GetBusinessAccountStarBalance(p GetBusinessAccountStarBalanceP) (StarAmount, error) { - req := NewRequest[StarAmount]("getBusinessAccountGiftSettings", p) +func (api *Api) GetBusinessAccountStarBalance(params GetBusinessAccountStarBalanceP) (StarAmount, error) { + req := NewRequest[StarAmount]("getBusinessAccountGiftSettings", params) return req.Do(api) } @@ -136,8 +136,8 @@ type TransferBusinessAccountStartP struct { StarCount int `json:"star_count"` } -func (api *Api) TransferBusinessAccountStart(p TransferBusinessAccountStartP) (bool, error) { - req := NewRequest[bool]("transferBusinessAccountStart", p) +func (api *Api) TransferBusinessAccountStart(params TransferBusinessAccountStartP) (bool, error) { + req := NewRequest[bool]("transferBusinessAccountStart", params) return req.Do(api) } @@ -155,8 +155,8 @@ type GetBusinessAccountGiftsP struct { Limit int `json:"limit,omitempty"` } -func (api *Api) GetBusinessAccountGifts(p GetBusinessAccountGiftsP) (OwnedGifts, error) { - req := NewRequest[OwnedGifts]("getBusinessAccountGifts", p) +func (api *Api) GetBusinessAccountGifts(params GetBusinessAccountGiftsP) (OwnedGifts, error) { + req := NewRequest[OwnedGifts]("getBusinessAccountGifts", params) return req.Do(api) } @@ -165,8 +165,8 @@ type ConvertGiftToStarsP struct { OwnedGiftID string `json:"owned_gift_id"` } -func (api *Api) ConvertGiftToStars(p ConvertGiftToStarsP) (bool, error) { - req := NewRequest[bool]("convertGiftToStars", p) +func (api *Api) ConvertGiftToStars(params ConvertGiftToStarsP) (bool, error) { + req := NewRequest[bool]("convertGiftToStars", params) return req.Do(api) } @@ -177,8 +177,8 @@ type UpgradeGiftP struct { StarCount int `json:"star_count,omitempty"` } -func (api *Api) UpgradeGift(p UpgradeGiftP) (bool, error) { - req := NewRequest[bool]("upgradeGift", p) +func (api *Api) UpgradeGift(params UpgradeGiftP) (bool, error) { + req := NewRequest[bool]("upgradeGift", params) return req.Do(api) } @@ -189,8 +189,8 @@ type TransferGiftP struct { StarCount int `json:"star_count,omitempty"` } -func (api *Api) TransferGift(p TransferGiftP) (bool, error) { - req := NewRequest[bool]("transferGift", p) +func (api *Api) TransferGift(params TransferGiftP) (bool, error) { + req := NewRequest[bool]("transferGift", params) return req.Do(api) } @@ -208,12 +208,12 @@ type PostStoryP struct { ProtectContent bool `json:"protect_content,omitempty"` } -func (api *Api) PostStoryPhoto(p PostStoryP) (Story, error) { - req := NewRequest[Story]("postStory", p) +func (api *Api) PostStoryPhoto(params PostStoryP) (Story, error) { + req := NewRequest[Story]("postStory", params) return req.Do(api) } -func (api *Api) PostStoryVideo(p PostStoryP) (Story, error) { - req := NewRequest[Story]("postStory", p) +func (api *Api) PostStoryVideo(params PostStoryP) (Story, error) { + req := NewRequest[Story]("postStory", params) return req.Do(api) } @@ -226,8 +226,8 @@ type RepostStoryP struct { ProtectContent bool `json:"protect_content,omitempty"` } -func (api *Api) RepostStory(p RepostStoryP) (Story, error) { - req := NewRequest[Story]("repostStory", p) +func (api *Api) RepostStory(params RepostStoryP) (Story, error) { + req := NewRequest[Story]("repostStory", params) return req.Do(api) } @@ -242,8 +242,8 @@ type EditStoryP struct { Areas []StoryArea `json:"areas,omitempty"` } -func (api *Api) EditStory(p EditStoryP) (Story, error) { - req := NewRequest[Story]("editStory", p) +func (api *Api) EditStory(params EditStoryP) (Story, error) { + req := NewRequest[Story]("editStory", params) return req.Do(api) } @@ -252,7 +252,7 @@ type DeleteStoryP struct { StoryID int `json:"story_id"` } -func (api *Api) DeleteStory(p DeleteStoryP) (bool, error) { - req := NewRequest[bool]("deleteStory", p) +func (api *Api) DeleteStory(params DeleteStoryP) (bool, error) { + req := NewRequest[bool]("deleteStory", params) return req.Do(api) } diff --git a/tgapi/chat_methods.go b/tgapi/chat_methods.go index 386c118..f75bee5 100644 --- a/tgapi/chat_methods.go +++ b/tgapi/chat_methods.go @@ -7,8 +7,8 @@ type BanChatMemberP struct { RevokeMessages bool `json:"revoke_messages,omitempty"` } -func (api *Api) BanChatMember(p BanChatMemberP) (bool, error) { - req := NewRequest[bool]("banChatMember", p) +func (api *Api) BanChatMember(params BanChatMemberP) (bool, error) { + req := NewRequest[bool]("banChatMember", params) return req.Do(api) } @@ -18,8 +18,8 @@ type UnbanChatMemberP struct { OnlyIfBanned bool `json:"only_if_banned"` } -func (api *Api) UnbanChatMember(p UnbanChatMemberP) (bool, error) { - req := NewRequest[bool]("unbanChatMember", p) +func (api *Api) UnbanChatMember(params UnbanChatMemberP) (bool, error) { + req := NewRequest[bool]("unbanChatMember", params) return req.Do(api) } @@ -31,8 +31,8 @@ type RestrictChatMemberP struct { UntilDate int `json:"until_date,omitempty"` } -func (api *Api) RestrictChatMember(p RestrictChatMemberP) (bool, error) { - req := NewRequest[bool]("restrictChatMember", p) +func (api *Api) RestrictChatMember(params RestrictChatMemberP) (bool, error) { + req := NewRequest[bool]("restrictChatMember", params) return req.Do(api) } @@ -58,8 +58,8 @@ type PromoteChatMember struct { CanManageDirectMessages bool `json:"can_manage_direct_messages,omitempty"` } -func (api *Api) PromoteChatMember(p PromoteChatMember) (bool, error) { - req := NewRequest[bool]("promoteChatMember", p) +func (api *Api) PromoteChatMember(params PromoteChatMember) (bool, error) { + req := NewRequest[bool]("promoteChatMember", params) return req.Do(api) } @@ -69,8 +69,8 @@ type SetChatAdministratorCustomTitleP struct { CustomTitle string `json:"custom_title"` } -func (api *Api) SetChatAdministratorCustomTitle(p SetChatAdministratorCustomTitleP) (bool, error) { - req := NewRequest[bool]("setChatAdministratorCustomTitle", p) +func (api *Api) SetChatAdministratorCustomTitle(params SetChatAdministratorCustomTitleP) (bool, error) { + req := NewRequest[bool]("setChatAdministratorCustomTitle", params) return req.Do(api) } @@ -79,8 +79,8 @@ type BanChatSenderChatP struct { SenderChatID int `json:"sender_chat_id"` } -func (api *Api) BanChatSenderChat(p BanChatSenderChatP) (bool, error) { - req := NewRequest[bool]("banChatSenderChat", p) +func (api *Api) BanChatSenderChat(params BanChatSenderChatP) (bool, error) { + req := NewRequest[bool]("banChatSenderChat", params) return req.Do(api) } @@ -89,8 +89,8 @@ type UnbanChatSenderChatP struct { SenderChatID int `json:"sender_chat_id"` } -func (api *Api) UnbanChatSenderChat(p BanChatSenderChatP) (bool, error) { - req := NewRequest[bool]("unbanChatSenderChat", p) +func (api *Api) UnbanChatSenderChat(params BanChatSenderChatP) (bool, error) { + req := NewRequest[bool]("unbanChatSenderChat", params) return req.Do(api) } @@ -100,8 +100,8 @@ type SetChatPermissionsP struct { UseIndependentChatPermissions bool `json:"use_independent_chat_permissions,omitempty"` } -func (api *Api) SetChatPermissions(p SetChatPermissionsP) (bool, error) { - req := NewRequest[bool]("setChatPermissions", p) +func (api *Api) SetChatPermissions(params SetChatPermissionsP) (bool, error) { + req := NewRequest[bool]("setChatPermissions", params) return req.Do(api) } @@ -109,8 +109,8 @@ type ExportChatInviteLinkP struct { ChatID int `json:"chat_id"` } -func (api *Api) ExportChatInviteLink(p ExportChatInviteLinkP) (string, error) { - req := NewRequest[string]("exportChatInviteLink", p) +func (api *Api) ExportChatInviteLink(params ExportChatInviteLinkP) (string, error) { + req := NewRequest[string]("exportChatInviteLink", params) return req.Do(api) } @@ -122,8 +122,8 @@ type CreateChatInviteLinkP struct { CreatesJoinRequest int `json:"creates_join_request,omitempty"` } -func (api *Api) CreateChatInviteLink(p CreateChatInviteLinkP) (ChatInviteLink, error) { - req := NewRequest[ChatInviteLink]("createChatInviteLink", p) +func (api *Api) CreateChatInviteLink(params CreateChatInviteLinkP) (ChatInviteLink, error) { + req := NewRequest[ChatInviteLink]("createChatInviteLink", params) return req.Do(api) } @@ -137,8 +137,8 @@ type EditChatInviteLinkP struct { CreatesJoinRequest int `json:"creates_join_request,omitempty"` } -func (api *Api) EditChatInviteLink(p EditChatInviteLinkP) (ChatInviteLink, error) { - req := NewRequest[ChatInviteLink]("editChatInviteLink", p) +func (api *Api) EditChatInviteLink(params EditChatInviteLinkP) (ChatInviteLink, error) { + req := NewRequest[ChatInviteLink]("editChatInviteLink", params) return req.Do(api) } @@ -149,8 +149,8 @@ type CreateChatSubscriptionInviteLinkP struct { SubscriptionPrice int `json:"subscription_price,omitempty"` } -func (api *Api) CreateChatSubscriptionInviteLink(p CreateChatSubscriptionInviteLinkP) (ChatInviteLink, error) { - req := NewRequest[ChatInviteLink]("createChatSubscriptionInviteLink", p) +func (api *Api) CreateChatSubscriptionInviteLink(params CreateChatSubscriptionInviteLinkP) (ChatInviteLink, error) { + req := NewRequest[ChatInviteLink]("createChatSubscriptionInviteLink", params) return req.Do(api) } @@ -160,8 +160,8 @@ type EditChatSubscriptionInviteLinkP struct { Name string `json:"name,omitempty"` } -func (api *Api) EditChatSubscriptionInviteLink(p EditChatSubscriptionInviteLinkP) (ChatInviteLink, error) { - req := NewRequest[ChatInviteLink]("editChatSubscriptionInviteLink", p) +func (api *Api) EditChatSubscriptionInviteLink(params EditChatSubscriptionInviteLinkP) (ChatInviteLink, error) { + req := NewRequest[ChatInviteLink]("editChatSubscriptionInviteLink", params) return req.Do(api) } @@ -170,8 +170,8 @@ type RevokeChatInviteLinkP struct { InviteLink string `json:"invite_link"` } -func (api *Api) RevokeChatInviteLink(p RevokeChatInviteLinkP) (ChatInviteLink, error) { - req := NewRequest[ChatInviteLink]("revokeChatInviteLink", p) +func (api *Api) RevokeChatInviteLink(params RevokeChatInviteLinkP) (ChatInviteLink, error) { + req := NewRequest[ChatInviteLink]("revokeChatInviteLink", params) return req.Do(api) } @@ -180,8 +180,8 @@ type ApproveChatJoinRequestP struct { UserID int `json:"user_id"` } -func (api *Api) ApproveChatJoinRequest(p ApproveChatJoinRequestP) (bool, error) { - req := NewRequest[bool]("approveChatJoinRequest", p) +func (api *Api) ApproveChatJoinRequest(params ApproveChatJoinRequestP) (bool, error) { + req := NewRequest[bool]("approveChatJoinRequest", params) return req.Do(api) } @@ -190,8 +190,8 @@ type DeclineChatJoinRequestP struct { UserID int `json:"user_id"` } -func (api *Api) DeclineChatJoinRequest(p DeclineChatJoinRequestP) (bool, error) { - req := NewRequest[bool]("declineChatJoinRequest", p) +func (api *Api) DeclineChatJoinRequest(params DeclineChatJoinRequestP) (bool, error) { + req := NewRequest[bool]("declineChatJoinRequest", params) return req.Do(api) } @@ -204,8 +204,8 @@ type DeleteChatPhotoP struct { ChatID int `json:"chat_id"` } -func (api *Api) DeleteChatPhoto(p DeleteChatPhotoP) (bool, error) { - req := NewRequest[bool]("deleteChatPhoto", p) +func (api *Api) DeleteChatPhoto(params DeleteChatPhotoP) (bool, error) { + req := NewRequest[bool]("deleteChatPhoto", params) return req.Do(api) } @@ -214,8 +214,8 @@ type SetChatTitleP struct { Title string `json:"title"` } -func (api *Api) SetChatTitle(p SetChatTitleP) (bool, error) { - req := NewRequest[bool]("setChatTitle", p) +func (api *Api) SetChatTitle(params SetChatTitleP) (bool, error) { + req := NewRequest[bool]("setChatTitle", params) return req.Do(api) } @@ -224,8 +224,8 @@ type SetChatDescriptionP struct { Description string `json:"description"` } -func (api *Api) SetChatDescription(p SetChatDescriptionP) (bool, error) { - req := NewRequest[bool]("setChatDescription", p) +func (api *Api) SetChatDescription(params SetChatDescriptionP) (bool, error) { + req := NewRequest[bool]("setChatDescription", params) return req.Do(api) } @@ -236,8 +236,8 @@ type PinChatMessageP struct { DisableNotification bool `json:"disable_notification,omitempty"` } -func (api *Api) PinChatMessage(p PinChatMessageP) (bool, error) { - req := NewRequest[bool]("pinChatMessage", p) +func (api *Api) PinChatMessage(params PinChatMessageP) (bool, error) { + req := NewRequest[bool]("pinChatMessage", params) return req.Do(api) } @@ -247,8 +247,8 @@ type UnpinChatMessageP struct { MessageID int `json:"message_id"` } -func (api *Api) UnpinChatMessage(p UnpinChatMessageP) (bool, error) { - req := NewRequest[bool]("unpinChatMessage", p) +func (api *Api) UnpinChatMessage(params UnpinChatMessageP) (bool, error) { + req := NewRequest[bool]("unpinChatMessage", params) return req.Do(api) } @@ -256,8 +256,8 @@ type UnpinAllChatMessagesP struct { ChatID int `json:"chat_id"` } -func (api *Api) UnpinAllChatMessages(p UnpinAllChatMessagesP) (bool, error) { - req := NewRequest[bool]("unpinAllChatMessages", p) +func (api *Api) UnpinAllChatMessages(params UnpinAllChatMessagesP) (bool, error) { + req := NewRequest[bool]("unpinAllChatMessages", params) return req.Do(api) } @@ -265,8 +265,8 @@ type LeaveChatP struct { ChatID int `json:"chat_id"` } -func (api *Api) LeaveChat(p LeaveChatP) (bool, error) { - req := NewRequest[bool]("leaveChatP", p) +func (api *Api) LeaveChat(params LeaveChatP) (bool, error) { + req := NewRequest[bool]("leaveChatP", params) return req.Do(api) } @@ -274,8 +274,8 @@ type GetChatP struct { ChatID int `json:"chat_id"` } -func (api *Api) GetChatP(p GetChatP) (ChatFullInfo, error) { - req := NewRequest[ChatFullInfo]("getChatP", p) +func (api *Api) GetChatP(params GetChatP) (ChatFullInfo, error) { + req := NewRequest[ChatFullInfo]("getChatP", params) return req.Do(api) } @@ -283,8 +283,8 @@ type GetChatAdministratorsP struct { ChatID int `json:"chat_id"` } -func (api *Api) GetChatAdministrators(p GetChatAdministratorsP) ([]ChatMember, error) { - req := NewRequest[[]ChatMember]("getChatAdministrators", p) +func (api *Api) GetChatAdministrators(params GetChatAdministratorsP) ([]ChatMember, error) { + req := NewRequest[[]ChatMember]("getChatAdministrators", params) return req.Do(api) } @@ -292,8 +292,8 @@ type GetChatMembersCountP struct { ChatID int `json:"chat_id"` } -func (api *Api) GetChatMemberCount(p GetChatMembersCountP) (int, error) { - req := NewRequest[int]("getChatMemberCount", p) +func (api *Api) GetChatMemberCount(params GetChatMembersCountP) (int, error) { + req := NewRequest[int]("getChatMemberCount", params) return req.Do(api) } @@ -302,8 +302,8 @@ type GetChatMemberP struct { UserID int `json:"user_id"` } -func (api *Api) GetChatMember(p GetChatMemberP) (ChatMember, error) { - req := NewRequest[ChatMember]("getChatMember", p) +func (api *Api) GetChatMember(params GetChatMemberP) (ChatMember, error) { + req := NewRequest[ChatMember]("getChatMember", params) return req.Do(api) } @@ -312,8 +312,8 @@ type SetChatStickerSetP struct { StickerSetName string `json:"sticker_set_name"` } -func (api *Api) SetChatStickerSet(p SetChatStickerSetP) (bool, error) { - req := NewRequest[bool]("setChatStickerSet", p) +func (api *Api) SetChatStickerSet(params SetChatStickerSetP) (bool, error) { + req := NewRequest[bool]("setChatStickerSet", params) return req.Do(api) } @@ -321,8 +321,8 @@ type DeleteChatStickerSetP struct { ChatID int `json:"chat_id"` } -func (api *Api) DeleteChatStickerSet(p DeleteChatStickerSetP) (bool, error) { - req := NewRequest[bool]("deleteChatStickerSet", p) +func (api *Api) DeleteChatStickerSet(params DeleteChatStickerSetP) (bool, error) { + req := NewRequest[bool]("deleteChatStickerSet", params) return req.Do(api) } @@ -331,8 +331,8 @@ type GetUserChatBoostsP struct { UserID int `json:"user_id"` } -func (api *Api) GetUserChatBoosts(p GetUserChatBoostsP) (UserChatBoosts, error) { - req := NewRequest[UserChatBoosts]("getUserChatBoosts", p) +func (api *Api) GetUserChatBoosts(params GetUserChatBoostsP) (UserChatBoosts, error) { + req := NewRequest[UserChatBoosts]("getUserChatBoosts", params) return req.Do(api) } @@ -350,7 +350,7 @@ type GetChatGiftsP struct { Limit int `json:"limit,omitempty"` } -func (api *Api) GetChatGifts(p GetChatGiftsP) (OwnedGifts, error) { - req := NewRequest[OwnedGifts]("getChatGifts", p) +func (api *Api) GetChatGifts(params GetChatGiftsP) (OwnedGifts, error) { + req := NewRequest[OwnedGifts]("getChatGifts", params) return req.Do(api) } diff --git a/tgapi/forum_methods.go b/tgapi/forum_methods.go index 48e31e2..df2da3a 100644 --- a/tgapi/forum_methods.go +++ b/tgapi/forum_methods.go @@ -17,8 +17,8 @@ type CreateForumTopicP struct { IconCustomEmojiID string `json:"icon_custom_emoji_id"` } -func (api *Api) CreateForumTopic(p CreateForumTopicP) (ForumTopic, error) { - req := NewRequest[ForumTopic]("createForumTopic", p) +func (api *Api) CreateForumTopic(params CreateForumTopicP) (ForumTopic, error) { + req := NewRequest[ForumTopic]("createForumTopic", params) return req.Do(api) } @@ -28,25 +28,25 @@ type EditForumTopicP struct { IconCustomEmojiID string `json:"icon_custom_emoji_id"` } -func (api *Api) EditForumTopic(p EditForumTopicP) (bool, error) { - req := NewRequest[bool]("editForumTopic", p) +func (api *Api) EditForumTopic(params EditForumTopicP) (bool, error) { + req := NewRequest[bool]("editForumTopic", params) return req.Do(api) } -func (api *Api) CloseForumTopic(p BaseForumTopicP) (bool, error) { - req := NewRequest[bool]("closeForumTopic", p) +func (api *Api) CloseForumTopic(params BaseForumTopicP) (bool, error) { + req := NewRequest[bool]("closeForumTopic", params) return req.Do(api) } -func (api *Api) ReopenForumTopic(p BaseForumTopicP) (bool, error) { - req := NewRequest[bool]("reopenForumTopic", p) +func (api *Api) ReopenForumTopic(params BaseForumTopicP) (bool, error) { + req := NewRequest[bool]("reopenForumTopic", params) return req.Do(api) } -func (api *Api) DeleteForumTopic(p BaseForumTopicP) (bool, error) { - req := NewRequest[bool]("deleteForumTopic", p) +func (api *Api) DeleteForumTopic(params BaseForumTopicP) (bool, error) { + req := NewRequest[bool]("deleteForumTopic", params) return req.Do(api) } -func (api *Api) UnpinAllForumTopicMessages(p BaseForumTopicP) (bool, error) { - req := NewRequest[bool]("unpinAllForumTopicMessages", p) +func (api *Api) UnpinAllForumTopicMessages(params BaseForumTopicP) (bool, error) { + req := NewRequest[bool]("unpinAllForumTopicMessages", params) return req.Do(api) } @@ -59,28 +59,28 @@ type EditGeneralForumTopicP struct { Name string `json:"name"` } -func (api *Api) EditGeneralForumTopic(p EditGeneralForumTopicP) (bool, error) { - req := NewRequest[bool]("editGeneralForumTopic", p) +func (api *Api) EditGeneralForumTopic(params EditGeneralForumTopicP) (bool, error) { + req := NewRequest[bool]("editGeneralForumTopic", params) return req.Do(api) } -func (api *Api) CloseGeneralForumTopic(p BaseGeneralForumTopicP) (bool, error) { - req := NewRequest[bool]("closeGeneralForumTopic", p) +func (api *Api) CloseGeneralForumTopic(params BaseGeneralForumTopicP) (bool, error) { + req := NewRequest[bool]("closeGeneralForumTopic", params) return req.Do(api) } -func (api *Api) ReopenGeneralForumTopic(p BaseGeneralForumTopicP) (bool, error) { - req := NewRequest[bool]("reopenGeneralForumTopic", p) +func (api *Api) ReopenGeneralForumTopic(params BaseGeneralForumTopicP) (bool, error) { + req := NewRequest[bool]("reopenGeneralForumTopic", params) return req.Do(api) } -func (api *Api) HideGeneralForumTopic(p BaseGeneralForumTopicP) (bool, error) { - req := NewRequest[bool]("hideGeneralForumTopic", p) +func (api *Api) HideGeneralForumTopic(params BaseGeneralForumTopicP) (bool, error) { + req := NewRequest[bool]("hideGeneralForumTopic", params) return req.Do(api) } -func (api *Api) UnhideGeneralForumTopic(p BaseGeneralForumTopicP) (bool, error) { - req := NewRequest[bool]("unhideGeneralForumTopic", p) +func (api *Api) UnhideGeneralForumTopic(params BaseGeneralForumTopicP) (bool, error) { + req := NewRequest[bool]("unhideGeneralForumTopic", params) return req.Do(api) } -func (api *Api) UnpinAllGeneralForumTopicMessages(p BaseGeneralForumTopicP) (bool, error) { - req := NewRequest[bool]("unpinAllGeneralForumTopicMessages", p) +func (api *Api) UnpinAllGeneralForumTopicMessages(params BaseGeneralForumTopicP) (bool, error) { + req := NewRequest[bool]("unpinAllGeneralForumTopicMessages", params) return req.Do(api) } diff --git a/tgapi/messages_methods.go b/tgapi/messages_methods.go index ba8a1ff..09fc098 100644 --- a/tgapi/messages_methods.go +++ b/tgapi/messages_methods.go @@ -20,8 +20,8 @@ type SendMessageP struct { ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"` } -func (api *Api) SendMessage(params *SendMessageP) (Message, error) { - req := NewRequest[Message, SendMessageP]("sendMessage", *params) +func (api *Api) SendMessage(params SendMessageP) (Message, error) { + req := NewRequest[Message, SendMessageP]("sendMessage", params) return req.Do(api) } @@ -315,9 +315,18 @@ type EditMessageTextP struct { ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"` } -func (api *Api) EditMessageText(params *EditMessageTextP) (Message, error) { +// EditMessageText If inline message, first return will be zero-valued, and second will boolean +// Otherwise, first return will be Message, and second false +func (api *Api) EditMessageText(params EditMessageTextP) (Message, bool, error) { + var zero Message + if params.InlineMessageID != "" { + req := NewRequest[bool]("editMessageText", params) + res, err := req.Do(api) + return zero, res, err + } req := NewRequest[Message]("editMessageText", params) - return req.Do(api) + res, err := req.Do(api) + return res, false, err } type EditMessageCaptionP struct { @@ -330,8 +339,158 @@ type EditMessageCaptionP struct { ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"` } -func (api *Api) EditMessageCaption(params *EditMessageCaptionP) (Message, error) { +// EditMessageCaption If inline message, first return will be zero-valued, and second will boolean +// Otherwise, first return will be Message, and second false +func (api *Api) EditMessageCaption(params EditMessageCaptionP) (Message, bool, error) { + var zero Message + if params.InlineMessageID != "" { + req := NewRequest[bool]("editMessageCaption", params) + res, err := req.Do(api) + return zero, res, err + } req := NewRequest[Message]("editMessageCaption", params) + res, err := req.Do(api) + return res, false, err +} + +type EditMessageMediaP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id,omitempty"` + MessageID int `json:"message_id,omitempty"` + InlineMessageID string `json:"inline_message_id,omitempty"` + Message InputMedia `json:"message"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` +} + +// EditMessageMedia If inline message, first return will be zero-valued, and second will boolean +// Otherwise, first return will be Message, and second false +func (api *Api) EditMessageMedia(params EditMessageMediaP) (Message, bool, error) { + var zero Message + if params.InlineMessageID != "" { + req := NewRequest[bool]("editMessageMedia", params) + res, err := req.Do(api) + return zero, res, err + } + req := NewRequest[Message]("editMessageMedia", params) + res, err := req.Do(api) + return res, false, err +} + +type EditMessageLiveLocationP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id,omitempty"` + MessageID int `json:"message_id,omitempty"` + InlineMessageID string `json:"inline_message_id,omitempty"` + + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + LivePeriod int `json:"live_period,omitempty"` + HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"` + Heading int `json:"heading,omitempty"` + ProximityAlertRadius int `json:"proximity_alert_radius,omitempty"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` +} + +// EditMessageLiveLocation If inline message, first return will be zero-valued, and second will boolean +// Otherwise, first return will be Message, and second false +func (api *Api) EditMessageLiveLocation(params EditMessageLiveLocationP) (Message, bool, error) { + var zero Message + if params.InlineMessageID != "" { + req := NewRequest[bool]("editMessageLiveLocation", params) + res, err := req.Do(api) + return zero, res, err + } + req := NewRequest[Message]("editMessageLiveLocation", params) + res, err := req.Do(api) + return res, false, err +} + +type StopMessageLiveLocationP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id,omitempty"` + MessageID int `json:"message_id,omitempty"` + InlineMessageID string `json:"inline_message_id,omitempty"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` +} + +// StopMessageLiveLocation If inline message, first return will be zero-valued, and second will boolean +// Otherwise, first return will be Message, and second false +func (api *Api) StopMessageLiveLocation(params StopMessageLiveLocationP) (Message, bool, error) { + var zero Message + if params.InlineMessageID != "" { + req := NewRequest[bool]("stopMessageLiveLocation", params) + res, err := req.Do(api) + return zero, res, err + } + req := NewRequest[Message]("stopMessageLiveLocation", params) + res, err := req.Do(api) + return res, false, err +} + +type EditMessageChecklistP struct { + BusinessConnectionID string `json:"business_connection_id"` + ChatID int `json:"chat_id"` + MessageID int `json:"message_id"` + Checklist InputChecklist `json:"checklist"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` +} + +func (api *Api) EditMessageChecklist(params EditMessageChecklistP) (Message, error) { + req := NewRequest[Message]("editMessageChecklist", params) + return req.Do(api) +} + +type EditMessageReplyMarkupP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id,omitempty"` + MessageID int `json:"message_id,omitempty"` + InlineMessageID string `json:"inline_message_id,omitempty"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` +} + +func (api *Api) EditMessageReplyMarkup(params EditMessageReplyMarkupP) (Message, bool, error) { + var zero Message + if params.InlineMessageID != "" { + req := NewRequest[bool]("editMessageReplyMarkup", params) + res, err := req.Do(api) + return zero, res, err + } + req := NewRequest[Message]("editMessageReplyMarkup", params) + res, err := req.Do(api) + return res, false, err +} + +type StopPollP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id"` + MessageID int `json:"message_id"` + InlineMessageID string `json:"inline_message_id,omitempty"` +} + +func (api *Api) StopPoll(params StopPollP) (Poll, error) { + req := NewRequest[Poll]("stopPoll", params) + return req.Do(api) +} + +type ApproveSuggestedPostP struct { + ChatID int `json:"chat_id"` + MessageID int `json:"message_id"` + SendDate int `json:"send_date,omitempty"` +} + +func (api *Api) ApproveSuggestedPost(params ApproveSuggestedPostP) (bool, error) { + req := NewRequest[bool]("approveSuggestedPost", params) + return req.Do(api) +} + +type DeclineSuggestedPostP struct { + ChatID int `json:"chat_id"` + MessageID int `json:"message_id"` + Comment string `json:"comment,omitempty"` +} + +func (api *Api) DeclineSuggestedPost(params DeclineSuggestedPostP) (bool, error) { + req := NewRequest[bool]("declineSuggestedPost", params) return req.Do(api) } @@ -340,11 +499,21 @@ type DeleteMessageP struct { MessageID int `json:"message_id"` } -func (api *Api) DeleteMessage(params *DeleteMessageP) (bool, error) { +func (api *Api) DeleteMessage(params DeleteMessageP) (bool, error) { req := NewRequest[bool]("deleteMessage", params) return req.Do(api) } +type DeleteMessagesP struct { + ChatID int `json:"chat_id"` + MessageIDs []int `json:"message_ids"` +} + +func (api *Api) DeleteMessages(params DeleteMessagesP) (bool, error) { + req := NewRequest[bool]("deleteMessages", params) + return req.Do(api) +} + type AnswerCallbackQueryP struct { CallbackQueryID string `json:"callback_query_id"` Text string `json:"text,omitempty"` @@ -353,7 +522,7 @@ type AnswerCallbackQueryP struct { CacheTime int `json:"cache_time,omitempty"` } -func (api *Api) AnswerCallbackQuery(params *AnswerCallbackQueryP) (bool, error) { +func (api *Api) AnswerCallbackQuery(params AnswerCallbackQueryP) (bool, error) { req := NewRequest[bool]("answerCallbackQuery", params) return req.Do(api) } diff --git a/tgapi/methods.go b/tgapi/methods.go index c75e2e8..9c20e88 100644 --- a/tgapi/methods.go +++ b/tgapi/methods.go @@ -31,6 +31,10 @@ func (api *Api) Close() (bool, error) { req := NewRequest[bool, EmptyParams]("close", NoParams) return req.Do(api) } +func (api *Api) GetUpdates(params UpdateParams) ([]Update, error) { + req := NewRequest[[]Update]("getUpdates", params) + return req.Do(api) +} type GetFileP struct { FileId string `json:"file_id"` diff --git a/tgapi/stickers_methods.go b/tgapi/stickers_methods.go index f86977d..99feeb8 100644 --- a/tgapi/stickers_methods.go +++ b/tgapi/stickers_methods.go @@ -14,8 +14,8 @@ type SendStickerP struct { MessageEffectID string `json:"message_effect_id,omitempty"` } -func (api *Api) SendSticker(p SendStickerP) (Message, error) { - req := NewRequest[Message]("sendSticker", p) +func (api *Api) SendSticker(params SendStickerP) (Message, error) { + req := NewRequest[Message]("sendSticker", params) return req.Do(api) } @@ -23,8 +23,8 @@ type GetStickerSetP struct { Name string `json:"name"` } -func (api *Api) GetStickerSet(p GetStickerSetP) (StickerSet, error) { - req := NewRequest[StickerSet]("getStickerSet", p) +func (api *Api) GetStickerSet(params GetStickerSetP) (StickerSet, error) { + req := NewRequest[StickerSet]("getStickerSet", params) return req.Do(api) } @@ -32,8 +32,8 @@ type GetCustomEmojiStickersP struct { CustomEmojiIDs []string `json:"custom_emoji_ids"` } -func (api *Api) GetCustomEmojiStickers(p GetCustomEmojiStickersP) ([]Sticker, error) { - req := NewRequest[[]Sticker]("getCustomEmojiStickers", p) +func (api *Api) GetCustomEmojiStickers(params GetCustomEmojiStickersP) ([]Sticker, error) { + req := NewRequest[[]Sticker]("getCustomEmojiStickers", params) return req.Do(api) } @@ -47,8 +47,8 @@ type CreateNewStickerSetP struct { NeedsRepainting bool `json:"needs_repainting,omitempty"` } -func (api *Api) CreateNewStickerSet(p CreateNewStickerSetP) (bool, error) { - req := NewRequest[bool]("createNewStickerSet", p) +func (api *Api) CreateNewStickerSet(params CreateNewStickerSetP) (bool, error) { + req := NewRequest[bool]("createNewStickerSet", params) return req.Do(api) } @@ -58,8 +58,8 @@ type AddStickerToSetP struct { Sticker InputSticker `json:"sticker"` } -func (api *Api) AddStickerToSet(p AddStickerToSetP) (bool, error) { - req := NewRequest[bool]("addStickerToSet", p) +func (api *Api) AddStickerToSet(params AddStickerToSetP) (bool, error) { + req := NewRequest[bool]("addStickerToSet", params) return req.Do(api) } @@ -68,8 +68,8 @@ type SetStickerPositionInSetP struct { Position int `json:"position"` } -func (api *Api) SetStickerPosition(p SetStickerPositionInSetP) (bool, error) { - req := NewRequest[bool]("setStickerPosition", p) +func (api *Api) SetStickerPosition(params SetStickerPositionInSetP) (bool, error) { + req := NewRequest[bool]("setStickerPosition", params) return req.Do(api) } @@ -77,8 +77,8 @@ type DeleteStickerFromSetP struct { Sticker string `json:"sticker"` } -func (api *Api) DeleteStickerFromSet(p DeleteStickerFromSetP) (bool, error) { - req := NewRequest[bool]("deleteStickerFromSet", p) +func (api *Api) DeleteStickerFromSet(params DeleteStickerFromSetP) (bool, error) { + req := NewRequest[bool]("deleteStickerFromSet", params) return req.Do(api) } @@ -89,8 +89,8 @@ type ReplaceStickerInSetP struct { Sticker InputSticker `json:"sticker"` } -func (api *Api) ReplaceStickerInSet(p ReplaceStickerInSetP) (bool, error) { - req := NewRequest[bool]("replaceStickerInSet", p) +func (api *Api) ReplaceStickerInSet(params ReplaceStickerInSetP) (bool, error) { + req := NewRequest[bool]("replaceStickerInSet", params) return req.Do(api) } @@ -99,8 +99,8 @@ type SetStickerEmojiListP struct { EmojiList []string `json:"emoji_list"` } -func (api *Api) SetStickerEmojiList(p SetStickerEmojiListP) (bool, error) { - req := NewRequest[bool]("setStickerEmojiList", p) +func (api *Api) SetStickerEmojiList(params SetStickerEmojiListP) (bool, error) { + req := NewRequest[bool]("setStickerEmojiList", params) return req.Do(api) } @@ -109,8 +109,8 @@ type SetStickerKeywordsP struct { Keywords []string `json:"keywords"` } -func (api *Api) SetStickerKeywords(p SetStickerKeywordsP) (bool, error) { - req := NewRequest[bool]("setStickerKeywords", p) +func (api *Api) SetStickerKeywords(params SetStickerKeywordsP) (bool, error) { + req := NewRequest[bool]("setStickerKeywords", params) return req.Do(api) } @@ -119,8 +119,8 @@ type SetStickerMaskPositionP struct { MaskPosition *MaskPosition `json:"mask_position,omitempty"` } -func (api *Api) SetStickerMaskPosition(p SetStickerMaskPositionP) (bool, error) { - req := NewRequest[bool]("setStickerMaskPosition", p) +func (api *Api) SetStickerMaskPosition(params SetStickerMaskPositionP) (bool, error) { + req := NewRequest[bool]("setStickerMaskPosition", params) return req.Do(api) } @@ -129,8 +129,8 @@ type SetStickerSetTitleP struct { Title string `json:"title"` } -func (api *Api) SetStickerSetTitle(p SetStickerSetTitleP) (bool, error) { - req := NewRequest[bool]("setStickerSetTitle", p) +func (api *Api) SetStickerSetTitle(params SetStickerSetTitleP) (bool, error) { + req := NewRequest[bool]("setStickerSetTitle", params) return req.Do(api) } @@ -141,8 +141,8 @@ type SetStickerSetThumbnailP struct { Format InputStickerFormat `json:"format"` } -func (api *Api) SetStickerSetThumbnail(p SetStickerSetThumbnailP) (bool, error) { - req := NewRequest[bool]("setStickerSetThumbnail", p) +func (api *Api) SetStickerSetThumbnail(params SetStickerSetThumbnailP) (bool, error) { + req := NewRequest[bool]("setStickerSetThumbnail", params) return req.Do(api) } @@ -151,8 +151,8 @@ type SetCustomEmojiStickerSetThumbnailP struct { CustomEmojiID string `json:"custom_emoji_id,omitempty"` } -func (api *Api) SetCustomEmojiStickerSetThumbnail(p SetStickerSetThumbnailP) (bool, error) { - req := NewRequest[bool]("setCustomEmojiStickerSetThumbnail", p) +func (api *Api) SetCustomEmojiStickerSetThumbnail(params SetStickerSetThumbnailP) (bool, error) { + req := NewRequest[bool]("setCustomEmojiStickerSetThumbnail", params) return req.Do(api) } @@ -160,7 +160,7 @@ type DeleteStickerSetP struct { Name string `json:"name"` } -func (api *Api) DeleteStickerSet(p DeleteStickerSetP) (bool, error) { - req := NewRequest[bool]("deleteStickerSet", p) +func (api *Api) DeleteStickerSet(params DeleteStickerSetP) (bool, error) { + req := NewRequest[bool]("deleteStickerSet", params) return req.Do(api) } diff --git a/tgapi/uploader.go b/tgapi/uploader.go index 33b9b52..7062503 100644 --- a/tgapi/uploader.go +++ b/tgapi/uploader.go @@ -2,6 +2,7 @@ package tgapi import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -36,116 +37,307 @@ const ( UploaderDocumentType UploaderFileType = "document" UploaderVoiceType UploaderFileType = "voice" UploaderVideoNoteType UploaderFileType = "video_note" + UploaderThumbnailType UploaderFileType = "thumbnail" ) type UploaderFile struct { filename string data []byte - t UploaderFileType + field UploaderFileType } func NewUploaderFile(name string, data []byte) UploaderFile { t := uploaderTypeByExt(name) - return UploaderFile{filename: name, data: data, t: t} + return UploaderFile{filename: name, data: data, field: t} } -// SetType used when auto-detect failed. I.e. you sending a voice message, but it detects as audio +// SetType used when auto-detect failed. I.e. you sending a voice message, but it detects as audio, or if you send audio with thumbnail func (f UploaderFile) SetType(t UploaderFileType) UploaderFile { - f.t = t + f.field = t return f } type UploaderRequest[R, P any] struct { method string - file UploaderFile + files []UploaderFile params P } -func NewUploaderRequest[R, P any](method string, file UploaderFile, params P) UploaderRequest[R, P] { - return UploaderRequest[R, P]{method, file, params} +func NewUploaderRequest[R, P any](method string, params P, files ...UploaderFile) UploaderRequest[R, P] { + return UploaderRequest[R, P]{method, files, params} } - -func (u UploaderRequest[R, P]) Do(up *Uploader) (*R, error) { +func (u UploaderRequest[R, P]) DoWithContext(ctx context.Context, up *Uploader) (R, error) { + var zero R url := fmt.Sprintf("https://api.telegram.org/bot%s/%s", up.api.token, u.method) buf := bytes.NewBuffer(nil) w := multipart.NewWriter(buf) - fw, err := w.CreateFormFile(string(u.file.t), u.file.filename) - if err != nil { - w.Close() - return nil, err + for _, file := range u.files { + fw, err := w.CreateFormFile(string(file.field), file.filename) + if err != nil { + w.Close() + return zero, err + } + _, err = fw.Write(file.data) + if err != nil { + w.Close() + return zero, err + } } - _, err = fw.Write(u.file.data) + + err := utils.Encode(w, u.params) if err != nil { w.Close() - return nil, err - } - err = utils.Encode(w, u.params) - if err != nil { - w.Close() - return nil, err + return zero, err } err = w.Close() if err != nil { - return nil, err + return zero, err } - req, err := http.NewRequest("POST", url, buf) + req, err := http.NewRequestWithContext(ctx, "POST", url, buf) if err != nil { - return nil, err + return zero, err } req.Header.Set("Content-Type", w.FormDataContentType()) + req.Header.Set("User-Agent", fmt.Sprintf("Laniakea/%s", utils.VersionString)) + up.logger.Debugln("UPLOADER REQ", u.method) - res, err := http.DefaultClient.Do(req) + res, err := up.api.client.Do(req) if err != nil { - return nil, err + return zero, err } defer res.Body.Close() body, err := io.ReadAll(res.Body) if err != nil { - return nil, err + return zero, err } up.logger.Debugln("UPLOADER RES", u.method, string(body)) if res.StatusCode != http.StatusOK { - return nil, fmt.Errorf("[%d] %s", res.StatusCode, string(body)) + return zero, fmt.Errorf("[%d] %s", res.StatusCode, string(body)) } - response := new(ApiResponse[*R]) - err = json.Unmarshal(body, response) + var response ApiResponse[R] + err = json.Unmarshal(body, &response) if err != nil { - return nil, err + return zero, err } if !response.Ok { - return nil, fmt.Errorf("[%d] %s", response.ErrorCode, response.Description) + return zero, fmt.Errorf("[%d] %s", response.ErrorCode, response.Description) } return response.Result, nil } - -type UploadPhotoP struct { - BusinessConnectionID string `json:"business_connection_id,omitempty"` - ChatID int `json:"chat_id"` - MessageThreadID int `json:"message_thread_id,omitempty"` - ParseMode ParseMode `json:"parse_mode,omitempty"` - Caption string `json:"caption,omitempty"` - CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` - ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` - HasSpoiler bool `json:"has_spoiler,omitempty"` - DisableNotifications bool `json:"disable_notifications,omitempty"` - ProtectContent bool `json:"protect_content,omitempty"` - AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"` - MessageEffectID string `json:"message_effect_id,omitempty"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` +func (u UploaderRequest[R, P]) Do(up *Uploader) (R, error) { + ctx := context.Background() + return u.DoWithContext(ctx, up) } -func (u *Uploader) UploadPhoto(file UploaderFile, params UploadPhotoP) (*Message, error) { - req := NewUploaderRequest[Message]("sendPhoto", file, params) +type UploadPhotoP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id"` + MessageThreadID int `json:"message_thread_id,omitempty"` + DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"` + + Caption string `json:"caption,omitempty"` + ParseMode ParseMode `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` + HasSpoiler bool `json:"has_spoiler,omitempty"` + DisableNotification bool `json:"disable_notification,omitempty"` + ProtectContent bool `json:"protect_content,omitempty"` + AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"` + MessageEffectID string `json:"message_effect_id,omitempty"` + + SuggestedPostParameters *SuggestedPostParameters `json:"suggested_post_parameters,omitempty"` + ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"` + ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"` +} + +func (u *Uploader) UploadPhoto(params UploadPhotoP, file UploaderFile) (Message, error) { + req := NewUploaderRequest[Message]("sendPhoto", params, file) + return req.Do(u) +} + +type UploadAudioP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id"` + MessageThreadID int `json:"message_thread_id,omitempty"` + DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"` + + Caption string `json:"caption,omitempty"` + ParseMode ParseMode `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + + Duration int `json:"duration,omitempty"` + Performer string `json:"performer,omitempty"` + Title string `json:"title,omitempty"` + + DisableNotification bool `json:"disable_notification,omitempty"` + ProtectContent bool `json:"protect_content,omitempty"` + AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"` + MessageEffectID string `json:"message_effect_id,omitempty"` + + SuggestedPostParameters *SuggestedPostParameters `json:"suggested_post_parameters,omitempty"` + ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"` + ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"` +} + +func (u *Uploader) UploadAudio(params UploadAudioP, files ...UploaderFile) (Message, error) { + req := NewUploaderRequest[Message]("sendAudio", params, files...) + return req.Do(u) +} + +type UploadDocumentP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id"` + MessageThreadID int `json:"message_thread_id,omitempty"` + DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"` + + Caption string `json:"caption,omitempty"` + ParseMode ParseMode `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + + DisableContentTypeDetection bool `json:"disable_content_type_detection,omitempty"` + DisableNotification bool `json:"disable_notification,omitempty"` + ProtectContent bool `json:"protect_content,omitempty"` + AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"` + MessageEffectID string `json:"message_effect_id,omitempty"` + + SuggestedPostParameters *SuggestedPostParameters `json:"suggested_post_parameters,omitempty"` + ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"` + ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"` +} + +func (u *Uploader) UploadDocument(params UploadDocumentP, files ...UploaderFile) (Message, error) { + req := NewUploaderRequest[Message]("sendDocument", params, files...) + return req.Do(u) +} + +type UploadVideoP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id"` + MessageThreadID int `json:"message_thread_id,omitempty"` + DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"` + + Duration int `json:"duration,omitempty"` + Width int `json:"width,omitempty"` + Height int `json:"height,omitempty"` + + StartTimestamp int64 `json:"start_timestamp,omitempty"` + Caption string `json:"caption,omitempty"` + ParseMode ParseMode `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` + HasSpoiler bool `json:"has_spoiler,omitempty"` + SupportsStreaming bool `json:"supports_streaming,omitempty"` + DisableNotification bool `json:"disable_notification,omitempty"` + ProtectContent bool `json:"protect_content,omitempty"` + AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"` + MessageEffectID string `json:"message_effect_id,omitempty"` + + SuggestedPostParameters *SuggestedPostParameters `json:"suggested_post_parameters,omitempty"` + ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"` + ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"` +} + +func (u *Uploader) UploadVideo(params UploadVideoP, files ...UploaderFile) (Message, error) { + req := NewUploaderRequest[Message]("sendVideo", params, files...) + return req.Do(u) +} + +type UploadAnimationP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id"` + MessageThreadID int `json:"message_thread_id,omitempty"` + DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"` + + Duration int `json:"duration,omitempty"` + Width int `json:"width,omitempty"` + Height int `json:"height,omitempty"` + + Caption string `json:"caption,omitempty"` + ParseMode ParseMode `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` + HasSpoiler bool `json:"has_spoiler,omitempty"` + DisableNotification bool `json:"disable_notification,omitempty"` + ProtectContent bool `json:"protect_content,omitempty"` + AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"` + MessageEffectID string `json:"message_effect_id,omitempty"` + + SuggestedPostParameters *SuggestedPostParameters `json:"suggested_post_parameters,omitempty"` + ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"` + ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"` +} + +func (u *Uploader) UploadAnimation(params UploadAnimationP, files ...UploaderFile) (Message, error) { + req := NewUploaderRequest[Message]("sendAnimation", params, files...) + return req.Do(u) +} + +type UploadVoiceP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id"` + MessageThreadID int `json:"message_thread_id,omitempty"` + DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"` + + Caption string `json:"caption,omitempty"` + ParseMode ParseMode `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + Duration int `json:"duration,omitempty"` + + DisableNotification bool `json:"disable_notification,omitempty"` + ProtectContent bool `json:"protect_content,omitempty"` + AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"` + MessageEffectID string `json:"message_effect_id,omitempty"` + + SuggestedPostParameters *SuggestedPostParameters `json:"suggested_post_parameters,omitempty"` + ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"` + ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"` +} + +func (u *Uploader) UploadVoice(params UploadVoiceP, files ...UploaderFile) (Message, error) { + req := NewUploaderRequest[Message]("sendVoice", params, files...) + return req.Do(u) +} + +type UploadVideoNoteP struct { + BusinessConnectionID string `json:"business_connection_id,omitempty"` + ChatID int `json:"chat_id"` + MessageThreadID int `json:"message_thread_id,omitempty"` + DirectMessagesTopicID int `json:"direct_messages_topic_id,omitempty"` + + Duration int `json:"duration,omitempty"` + Length int `json:"length,omitempty"` + + DisableNotification bool `json:"disable_notification,omitempty"` + ProtectContent bool `json:"protect_content,omitempty"` + AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"` + MessageEffectID string `json:"message_effect_id,omitempty"` + + SuggestedPostParameters *SuggestedPostParameters `json:"suggested_post_parameters,omitempty"` + ReplyParameters *ReplyParameters `json:"reply_parameters,omitempty"` + ReplyMarkup *ReplyMarkup `json:"reply_markup,omitempty"` +} + +func (u *Uploader) UploadVideoNote(params UploadVideoNoteP, files ...UploaderFile) (Message, error) { + req := NewUploaderRequest[Message]("sendVideoNote", params, files...) return req.Do(u) } // setChatPhoto https://core.telegram.org/bots/api#setchatphoto type UploadChatPhotoP struct { + ChatID int `json:"chat_id"` +} + +func (u *Uploader) UploadChatPhoto(params UploadChatPhotoP, photo UploaderFile) (Message, error) { + req := NewUploaderRequest[Message]("sendChatPhoto", params, photo) + return req.Do(u) } func uploaderTypeByExt(filename string) UploaderFileType { diff --git a/tgapi/users_methods.go b/tgapi/users_methods.go index 24cb024..d254140 100644 --- a/tgapi/users_methods.go +++ b/tgapi/users_methods.go @@ -6,8 +6,8 @@ type GetUserProfilePhotosP struct { Limit int `json:"limit,omitempty"` } -func (api *Api) GetUserProfilePhotos(p GetUserProfilePhotosP) (UserProfilePhotos, error) { - req := NewRequest[UserProfilePhotos]("getUserProfilePhotos", p) +func (api *Api) GetUserProfilePhotos(params GetUserProfilePhotosP) (UserProfilePhotos, error) { + req := NewRequest[UserProfilePhotos]("getUserProfilePhotos", params) return req.Do(api) } @@ -17,8 +17,8 @@ type GetUserProfileAudiosP struct { Limit int `json:"limit,omitempty"` } -func (api *Api) GetUserProfileAudios(p GetUserProfileAudiosP) (UserProfileAudios, error) { - req := NewRequest[UserProfileAudios]("getUserProfileAudios", p) +func (api *Api) GetUserProfileAudios(params GetUserProfileAudiosP) (UserProfileAudios, error) { + req := NewRequest[UserProfileAudios]("getUserProfileAudios", params) return req.Do(api) } @@ -28,8 +28,8 @@ type SetUserEmojiStatusP struct { ExpirationDate int `json:"emoji_status_expiration_date,omitempty"` } -func (api *Api) SetUserEmojiStatus(p SetUserEmojiStatusP) (bool, error) { - req := NewRequest[bool]("setUserEmojiStatus", p) +func (api *Api) SetUserEmojiStatus(params SetUserEmojiStatusP) (bool, error) { + req := NewRequest[bool]("setUserEmojiStatus", params) return req.Do(api) } @@ -45,7 +45,7 @@ type GetUserGiftsP struct { Limit int `json:"limit,omitempty"` } -func (api *Api) GetUserGifts(p GetUserGiftsP) (OwnedGifts, error) { - req := NewRequest[OwnedGifts]("getUserGifts", p) +func (api *Api) GetUserGifts(params GetUserGiftsP) (OwnedGifts, error) { + req := NewRequest[OwnedGifts]("getUserGifts", params) return req.Do(api) }