(new): support Bot API 10.3
Golang lint / lint (push) Failing after 1m37s

(fix): finalize v2 contracts
(tests): cover v2 migration
(doc): prepare release guidance
This commit is contained in:
2026-09-08 23:21:38 +03:00
parent 24040fe164
commit d78526242b
88 changed files with 2321 additions and 918 deletions
+21 -50
View File
@@ -7,7 +7,7 @@ import (
"math"
"net/http"
"git.scuroneko.dev/scuroneko/laniakea/utils"
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
)
// UpdateParams holds parameters for the getUpdates method.
@@ -38,7 +38,7 @@ type UpdateParams struct {
// See https://core.telegram.org/bots/api#getme
func (api *API) GetMe() (User, error) {
req := NewRequest[User]("getMe", NoParams)
return req.Do(api)
return api.Do(req)
}
// GetMeWithContext is the context-aware variant of GetMe.
@@ -46,7 +46,7 @@ func (api *API) GetMe() (User, error) {
// See https://core.telegram.org/bots/api#getme
func (api *API) GetMeWithContext(ctx context.Context) (User, error) {
req := NewRequest[User]("getMe", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetManagedBotToken holds parameters for the getManagedBotToken method.
@@ -60,7 +60,7 @@ type GetManagedBotToken struct {
// See https://core.telegram.org/bots/api#getmanagedbottoken
func (api *API) GetManagedBotToken(params GetManagedBotToken) (string, error) {
req := NewRequest[string]("getManagedBotToken", params)
return req.Do(api)
return api.Do(req)
}
// GetManagedBotTokenWithContext is the context-aware variant of GetManagedBotToken.
@@ -68,7 +68,7 @@ func (api *API) GetManagedBotToken(params GetManagedBotToken) (string, error) {
// See https://core.telegram.org/bots/api#getmanagedbottoken
func (api *API) GetManagedBotTokenWithContext(ctx context.Context, params GetManagedBotToken) (string, error) {
req := NewRequest[string]("getManagedBotToken", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// ReplaceManagedBotToken holds parameters for the replaceManagedBotToken method.
@@ -82,7 +82,7 @@ type ReplaceManagedBotToken struct {
// See https://core.telegram.org/bots/api#replacemanagedbottoken
func (api *API) ReplaceManagedBotToken(params ReplaceManagedBotToken) (string, error) {
req := NewRequest[string]("replaceManagedBotToken", params)
return req.Do(api)
return api.Do(req)
}
// ReplaceManagedBotTokenWithContext is the context-aware variant of ReplaceManagedBotToken.
@@ -90,7 +90,7 @@ func (api *API) ReplaceManagedBotToken(params ReplaceManagedBotToken) (string, e
// See https://core.telegram.org/bots/api#replacemanagedbottoken
func (api *API) ReplaceManagedBotTokenWithContext(ctx context.Context, params ReplaceManagedBotToken) (string, error) {
req := NewRequest[string]("replaceManagedBotToken", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// LogOut logs the bot out from the cloud Bot API server.
@@ -98,7 +98,7 @@ func (api *API) ReplaceManagedBotTokenWithContext(ctx context.Context, params Re
// See https://core.telegram.org/bots/api#logout
func (api *API) LogOut() (bool, error) {
req := NewRequest[bool]("logOut", NoParams)
return req.Do(api)
return api.Do(req)
}
// LogOutWithContext is the context-aware variant of LogOut.
@@ -106,7 +106,7 @@ func (api *API) LogOut() (bool, error) {
// See https://core.telegram.org/bots/api#logout
func (api *API) LogOutWithContext(ctx context.Context) (bool, error) {
req := NewRequest[bool]("logOut", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// CloseRemote closes the bot instance on the local server.
@@ -114,7 +114,7 @@ func (api *API) LogOutWithContext(ctx context.Context) (bool, error) {
// See https://core.telegram.org/bots/api#close
func (api *API) CloseRemote() (bool, error) {
req := NewRequest[bool]("close", NoParams)
return req.Do(api)
return api.Do(req)
}
// CloseRemoteWithContext is the context-aware variant of CloseRemote.
@@ -122,14 +122,14 @@ func (api *API) CloseRemote() (bool, error) {
// See https://core.telegram.org/bots/api#close
func (api *API) CloseRemoteWithContext(ctx context.Context) (bool, error) {
req := NewRequest[bool]("close", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetUpdates receives incoming updates using long polling.
// See https://core.telegram.org/bots/api#getupdates
func (api *API) GetUpdates(params UpdateParams) ([]Update, error) {
req := NewRequest[[]Update]("getUpdates", params)
return req.Do(api)
return api.Do(req)
}
// GetUpdatesWithContext is the context-aware variant of GetUpdates.
@@ -137,7 +137,7 @@ func (api *API) GetUpdates(params UpdateParams) ([]Update, error) {
// See https://core.telegram.org/bots/api#getupdates
func (api *API) GetUpdatesWithContext(ctx context.Context, params UpdateParams) ([]Update, error) {
req := NewRequest[[]Update]("getUpdates", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// SetWebhook holds parameters for the setWebhook method.
@@ -175,7 +175,7 @@ type SetWebhook struct {
// See https://core.telegram.org/bots/api#setwebhook
func (api *API) SetWebhook(params SetWebhook) (bool, error) {
req := NewRequest[bool]("setWebhook", params)
return req.Do(api)
return api.Do(req)
}
// SetWebhookWithContext is the context-aware variant of SetWebhook.
@@ -184,7 +184,7 @@ func (api *API) SetWebhook(params SetWebhook) (bool, error) {
// See https://core.telegram.org/bots/api#setwebhook
func (api *API) SetWebhookWithContext(ctx context.Context, params SetWebhook) (bool, error) {
req := NewRequest[bool]("setWebhook", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// DeleteWebhook holds parameters for the deleteWebhook method.
@@ -199,7 +199,7 @@ type DeleteWebhook struct {
// See https://core.telegram.org/bots/api#deletewebhook
func (api *API) DeleteWebhook(params DeleteWebhook) (bool, error) {
req := NewRequest[bool]("deleteWebhook", params)
return req.Do(api)
return api.Do(req)
}
// DeleteWebhookWithContext is the context-aware variant of DeleteWebhook.
@@ -207,14 +207,14 @@ func (api *API) DeleteWebhook(params DeleteWebhook) (bool, error) {
// See https://core.telegram.org/bots/api#deletewebhook
func (api *API) DeleteWebhookWithContext(ctx context.Context, params DeleteWebhook) (bool, error) {
req := NewRequest[bool]("deleteWebhook", params)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetWebhookInfo returns the current webhook status.
// See https://core.telegram.org/bots/api#getwebhookinfo
func (api *API) GetWebhookInfo() (WebhookInfo, error) {
req := NewRequest[WebhookInfo]("getWebhookInfo", NoParams)
return req.Do(api)
return api.Do(req)
}
// GetWebhookInfoWithContext is the context-aware variant of GetWebhookInfo.
@@ -222,7 +222,7 @@ func (api *API) GetWebhookInfo() (WebhookInfo, error) {
// See https://core.telegram.org/bots/api#getwebhookinfo
func (api *API) GetWebhookInfoWithContext(ctx context.Context) (WebhookInfo, error) {
req := NewRequest[WebhookInfo]("getWebhookInfo", NoParams)
return req.DoWithContext(ctx, api)
return api.DoWithContext(ctx, req)
}
// GetFile holds parameters for the getFile method.
@@ -236,7 +236,7 @@ type GetFile struct {
// See https://core.telegram.org/bots/api#getfile
func (api *API) GetFile(params GetFile) (File, error) {
req := NewRequest[File]("getFile", params)
return req.Do(api)
return api.Do(req)
}
// GetFileWithContext is the context-aware variant of GetFile.
@@ -244,25 +244,7 @@ func (api *API) GetFile(params GetFile) (File, error) {
// See https://core.telegram.org/bots/api#getfile
func (api *API) GetFileWithContext(ctx context.Context, params GetFile) (File, error) {
req := NewRequest[File]("getFile", params)
return req.DoWithContext(ctx, api)
}
// GetFileByLink downloads a file from Telegram's file server using the provided file link.
// The link is usually obtained from File.FilePath.
// For large files, prefer OpenFileByLink or OpenFileByLinkWithContext to stream the response body.
// This unbounded helper is retained for v1 compatibility and is subject to change in v2;
// prefer GetFileByLinkLimit for untrusted or potentially large files.
// See https://core.telegram.org/bots/api#file
func (api *API) GetFileByLink(link string) ([]byte, error) {
return api.getFileByLink(context.Background(), link)
}
// GetFileByLinkWithContext is the context-aware variant of GetFileByLink.
// It executes the same request but uses ctx for cancellation and deadlines.
// For large files, prefer OpenFileByLinkWithContext to stream the response body.
// See https://core.telegram.org/bots/api#file
func (api *API) GetFileByLinkWithContext(ctx context.Context, link string) ([]byte, error) {
return api.getFileByLink(ctx, link)
return api.DoWithContext(ctx, req)
}
// GetFileByLinkLimit downloads at most maxBytes from Telegram's file server.
@@ -310,17 +292,6 @@ func (api *API) OpenFileByLinkWithContext(ctx context.Context, link string) (io.
return api.openFileByLink(ctx, link)
}
func (api *API) getFileByLink(ctx context.Context, link string) ([]byte, error) {
body, err := api.openFileByLink(ctx, link)
if err != nil {
return nil, err
}
defer func() {
_ = body.Close()
}()
return io.ReadAll(body)
}
func (api *API) openFileByLink(ctx context.Context, link string) (io.ReadCloser, error) {
methodPrefix := ""
if api.useTestServer {