mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-06-05 22:43:59 +00:00
fix(api): generate CallRaw + per-element decode for []<union> returns
GetChatAdministrators returns []ChatMember, where ChatMember is a sealed-interface union. The codegen template emitted the generic client.Call[..., []ChatMember] for it — encoding/json cannot unmarshal a slice of an interface (no discriminator-aware path), so every real response from Telegram failed at the parse step: telegram: parse: json: cannot unmarshal api.ChatMember into Go struct field Result[[]ChatMember].Result of type api.ChatMember Fix is in cmd/genapi/methods.tmpl: add a third branch alongside the existing single-union branch. When a method returns []<union>, emit CallRaw + json.Unmarshal into []json.RawMessage + per-element Unmarshal<Union>(e). Mirrors what GetChatMember (single-element) already does, applied uniformly so any future slice-of-union method Telegram introduces inherits the right shape. Survey of v1.1.1 across all 23 sealed-interface unions confirms GetChatAdministrators was the only broken site; the fix regenerates just that one method body. New regression tests in api/getchatadministrators_test.go cover the typical admin+owner response and the empty-array case.
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/lukaszraczylo/go-telegram/client"
|
||||||
|
"github.com/stretchr/testify/mock"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestGetChatAdministrators_DecodesUnionSlice is a regression test for the
|
||||||
|
// bug where GetChatAdministrators was emitted with the generic client.Call
|
||||||
|
// against []ChatMember — encoding/json cannot unmarshal a slice of an
|
||||||
|
// interface, so the call always failed at the parse step.
|
||||||
|
//
|
||||||
|
// The fix makes the codegen emit CallRaw + per-element UnmarshalChatMember
|
||||||
|
// for any method returning []<sealed-interface union>.
|
||||||
|
func TestGetChatAdministrators_DecodesUnionSlice(t *testing.T) {
|
||||||
|
body := `{"ok":true,"result":[
|
||||||
|
{"status":"creator","user":{"id":1,"is_bot":false,"first_name":"Owner"},"is_anonymous":false},
|
||||||
|
{"status":"administrator","user":{"id":2,"is_bot":false,"first_name":"Admin"},"can_be_edited":false,"is_anonymous":false,"can_manage_chat":true,"can_delete_messages":true,"can_manage_video_chats":false,"can_restrict_members":true,"can_promote_members":false,"can_change_info":true,"can_invite_users":true,"can_post_stories":false,"can_edit_stories":false,"can_delete_stories":false}
|
||||||
|
]}`
|
||||||
|
|
||||||
|
m := &mockDoer{}
|
||||||
|
m.On("Do", mock.Anything).Return(newJSONResp(200, body), nil)
|
||||||
|
bot := client.New("test:token", client.WithHTTPClient(m))
|
||||||
|
|
||||||
|
admins, err := GetChatAdministrators(context.Background(), bot,
|
||||||
|
&GetChatAdministratorsParams{ChatID: ChatIDFromInt(-100123)})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, admins, 2)
|
||||||
|
|
||||||
|
owner, ok := admins[0].(*ChatMemberOwner)
|
||||||
|
require.True(t, ok, "first element must dispatch to ChatMemberOwner, got %T", admins[0])
|
||||||
|
require.Equal(t, int64(1), owner.User.ID)
|
||||||
|
|
||||||
|
admin, ok := admins[1].(*ChatMemberAdministrator)
|
||||||
|
require.True(t, ok, "second element must dispatch to ChatMemberAdministrator, got %T", admins[1])
|
||||||
|
require.True(t, admin.CanManageChat)
|
||||||
|
require.False(t, admin.CanPromoteMembers)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestGetChatAdministrators_EmptyArray covers the zero-admin edge case
|
||||||
|
// (a basic group with no admins, or the bot itself filtered out).
|
||||||
|
func TestGetChatAdministrators_EmptyArray(t *testing.T) {
|
||||||
|
m := &mockDoer{}
|
||||||
|
m.On("Do", mock.Anything).Return(newJSONResp(200, `{"ok":true,"result":[]}`), nil)
|
||||||
|
bot := client.New("test:token", client.WithHTTPClient(m))
|
||||||
|
|
||||||
|
admins, err := GetChatAdministrators(context.Background(), bot,
|
||||||
|
&GetChatAdministratorsParams{ChatID: ChatIDFromInt(-100123)})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Empty(t, admins)
|
||||||
|
}
|
||||||
+17
-1
@@ -2676,7 +2676,23 @@ type GetChatAdministratorsParams struct {
|
|||||||
//
|
//
|
||||||
// Use this method to get a list of administrators in a chat. Returns an Array of ChatMember objects.
|
// Use this method to get a list of administrators in a chat. Returns an Array of ChatMember objects.
|
||||||
func GetChatAdministrators(ctx context.Context, b *client.Bot, p *GetChatAdministratorsParams) ([]ChatMember, error) {
|
func GetChatAdministrators(ctx context.Context, b *client.Bot, p *GetChatAdministratorsParams) ([]ChatMember, error) {
|
||||||
return client.Call[*GetChatAdministratorsParams, []ChatMember](ctx, b, "getChatAdministrators", p)
|
raw, err := client.CallRaw[*GetChatAdministratorsParams](ctx, b, "getChatAdministrators", p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var elems []json.RawMessage
|
||||||
|
if err := json.Unmarshal(raw, &elems); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out := make([]ChatMember, 0, len(elems))
|
||||||
|
for _, e := range elems {
|
||||||
|
v, err := UnmarshalChatMember(e)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out = append(out, v)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChatMemberCountParams is the parameter set for GetChatMemberCount.
|
// GetChatMemberCountParams is the parameter set for GetChatMemberCount.
|
||||||
|
|||||||
@@ -245,6 +245,19 @@ func funcs(plan *enumPlan) template.FuncMap {
|
|||||||
s, ok := knownDiscriminators[tr.Name]
|
s, ok := knownDiscriminators[tr.Name]
|
||||||
return ok && len(s.Variants) > 0
|
return ok && len(s.Variants) > 0
|
||||||
},
|
},
|
||||||
|
"isSealedUnionArrayReturn": func(tr spec.TypeRef) bool {
|
||||||
|
if tr.Kind != spec.KindArray || tr.ElemType == nil || tr.ElemType.Kind != spec.KindNamed {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
s, ok := knownDiscriminators[tr.ElemType.Name]
|
||||||
|
return ok && len(s.Variants) > 0
|
||||||
|
},
|
||||||
|
"sealedUnionElemName": func(tr spec.TypeRef) string {
|
||||||
|
if tr.Kind == spec.KindArray && tr.ElemType != nil {
|
||||||
|
return tr.ElemType.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
},
|
||||||
"isMaybeInaccessibleMessage": func(name string) bool { return name == "MaybeInaccessibleMessage" },
|
"isMaybeInaccessibleMessage": func(name string) bool { return name == "MaybeInaccessibleMessage" },
|
||||||
"discriminatorField": func(name string) string { return knownDiscriminators[name].Field },
|
"discriminatorField": func(name string) string { return knownDiscriminators[name].Field },
|
||||||
"discriminatorMap": func(name string) map[string]string { return knownDiscriminators[name].Variants },
|
"discriminatorMap": func(name string) map[string]string { return knownDiscriminators[name].Variants },
|
||||||
|
|||||||
@@ -51,6 +51,24 @@ func {{title .Name}}(ctx context.Context, b *client.Bot, p *{{title .Name}}Param
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return Unmarshal{{.Returns.Name}}(raw)
|
return Unmarshal{{.Returns.Name}}(raw)
|
||||||
|
{{else if isSealedUnionArrayReturn .Returns -}}
|
||||||
|
raw, err := client.CallRaw[*{{title .Name}}Params](ctx, b, "{{.Name}}", p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var elems []json.RawMessage
|
||||||
|
if err := json.Unmarshal(raw, &elems); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out := make([]{{sealedUnionElemName .Returns}}, 0, len(elems))
|
||||||
|
for _, e := range elems {
|
||||||
|
v, err := Unmarshal{{sealedUnionElemName .Returns}}(e)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out = append(out, v)
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
{{else -}}
|
{{else -}}
|
||||||
return client.Call[*{{title .Name}}Params, {{returnGoType .Returns}}](ctx, b, "{{.Name}}", p)
|
return client.Call[*{{title .Name}}Params, {{returnGoType .Returns}}](ctx, b, "{{.Name}}", p)
|
||||||
{{end -}}
|
{{end -}}
|
||||||
|
|||||||
+827
-827
File diff suppressed because it is too large
Load Diff
+49
-49
@@ -80,7 +80,7 @@ var (
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="Call"></a>
|
<a name="Call"></a>
|
||||||
## func Call
|
## func [Call](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/call.go#L25>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Call[Req any, Resp any](ctx context.Context, b *Bot, method string, req Req) (Resp, error)
|
func Call[Req any, Resp any](ctx context.Context, b *Bot, method string, req Req) (Resp, error)
|
||||||
@@ -93,7 +93,7 @@ It is generic over both request and response types. Methods with no parameters m
|
|||||||
Call is exported because the api package \(which lives outside this one\) invokes it from generated method wrappers. User code should not normally call it directly — use the typed wrappers in package api instead.
|
Call is exported because the api package \(which lives outside this one\) invokes it from generated method wrappers. User code should not normally call it directly — use the typed wrappers in package api instead.
|
||||||
|
|
||||||
<a name="CallRaw"></a>
|
<a name="CallRaw"></a>
|
||||||
## func CallRaw
|
## func [CallRaw](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/call.go#L74>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func CallRaw[Req any](ctx context.Context, b *Bot, method string, req Req) (json.RawMessage, error)
|
func CallRaw[Req any](ctx context.Context, b *Bot, method string, req Req) (json.RawMessage, error)
|
||||||
@@ -104,7 +104,7 @@ CallRaw is like Call but returns the raw JSON of the result field instead of dec
|
|||||||
CallRaw still translates non\-OK responses into \*APIError just like Call.
|
CallRaw still translates non\-OK responses into \*APIError just like Call.
|
||||||
|
|
||||||
<a name="NewDefaultHTTPDoer"></a>
|
<a name="NewDefaultHTTPDoer"></a>
|
||||||
## func NewDefaultHTTPDoer
|
## func [NewDefaultHTTPDoer](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/httpclient.go#L22>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func NewDefaultHTTPDoer() *http.Client
|
func NewDefaultHTTPDoer() *http.Client
|
||||||
@@ -117,7 +117,7 @@ NewDefaultHTTPDoer returns an \*http.Client with sensible defaults for Telegram
|
|||||||
- HTTP/2 enabled \(default in net/http\).
|
- HTTP/2 enabled \(default in net/http\).
|
||||||
|
|
||||||
<a name="APIError"></a>
|
<a name="APIError"></a>
|
||||||
## type APIError
|
## type [APIError](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/errors.go#L13-L21>)
|
||||||
|
|
||||||
APIError represents a non\-OK Telegram Bot API response. It satisfies error and unwraps to a sentinel \(ErrUnauthorized, etc.\) where the description matches a known prefix, enabling errors.Is checks.
|
APIError represents a non\-OK Telegram Bot API response. It satisfies error and unwraps to a sentinel \(ErrUnauthorized, etc.\) where the description matches a known prefix, enabling errors.Is checks.
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ type APIError struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="APIError.Error"></a>
|
<a name="APIError.Error"></a>
|
||||||
### func \(\*APIError\) Error
|
### func \(\*APIError\) [Error](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/errors.go#L24>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (e *APIError) Error() string
|
func (e *APIError) Error() string
|
||||||
@@ -140,7 +140,7 @@ func (e *APIError) Error() string
|
|||||||
Error implements error.
|
Error implements error.
|
||||||
|
|
||||||
<a name="APIError.IsRetryable"></a>
|
<a name="APIError.IsRetryable"></a>
|
||||||
### func \(\*APIError\) IsRetryable
|
### func \(\*APIError\) [IsRetryable](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/errors.go#L32>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (e *APIError) IsRetryable() bool
|
func (e *APIError) IsRetryable() bool
|
||||||
@@ -149,7 +149,7 @@ func (e *APIError) IsRetryable() bool
|
|||||||
IsRetryable returns true for transient HTTP statuses \(429, 5xx\).
|
IsRetryable returns true for transient HTTP statuses \(429, 5xx\).
|
||||||
|
|
||||||
<a name="APIError.RetryAfter"></a>
|
<a name="APIError.RetryAfter"></a>
|
||||||
### func \(\*APIError\) RetryAfter
|
### func \(\*APIError\) [RetryAfter](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/errors.go#L38>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (e *APIError) RetryAfter() time.Duration
|
func (e *APIError) RetryAfter() time.Duration
|
||||||
@@ -158,7 +158,7 @@ func (e *APIError) RetryAfter() time.Duration
|
|||||||
RetryAfter returns the recommended back\-off duration. It honours the Telegram\-supplied retry\_after parameter; if absent, returns 0.
|
RetryAfter returns the recommended back\-off duration. It honours the Telegram\-supplied retry\_after parameter; if absent, returns 0.
|
||||||
|
|
||||||
<a name="APIError.Unwrap"></a>
|
<a name="APIError.Unwrap"></a>
|
||||||
### func \(\*APIError\) Unwrap
|
### func \(\*APIError\) [Unwrap](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/errors.go#L29>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (e *APIError) Unwrap() error
|
func (e *APIError) Unwrap() error
|
||||||
@@ -167,7 +167,7 @@ func (e *APIError) Unwrap() error
|
|||||||
Unwrap returns the matched sentinel error, if any.
|
Unwrap returns the matched sentinel error, if any.
|
||||||
|
|
||||||
<a name="Bot"></a>
|
<a name="Bot"></a>
|
||||||
## type Bot
|
## type [Bot](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/client.go#L7-L13>)
|
||||||
|
|
||||||
Bot is the Telegram Bot API client. Construct via New. All API methods \(declared in package api\) hang off \*Bot via thin wrappers around call.
|
Bot is the Telegram Bot API client. Construct via New. All API methods \(declared in package api\) hang off \*Bot via thin wrappers around call.
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ type Bot struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="New"></a>
|
<a name="New"></a>
|
||||||
### func New
|
### func [New](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/client.go#L36>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func New(token string, opts ...Option) *Bot
|
func New(token string, opts ...Option) *Bot
|
||||||
@@ -187,7 +187,7 @@ func New(token string, opts ...Option) *Bot
|
|||||||
New constructs a Bot with the given token and optional configuration. The default HTTP client is tuned for long\-poll workloads \(see NewDefaultHTTPDoer\); the default codec wraps encoding/json; the default logger discards records.
|
New constructs a Bot with the given token and optional configuration. The default HTTP client is tuned for long\-poll workloads \(see NewDefaultHTTPDoer\); the default codec wraps encoding/json; the default logger discards records.
|
||||||
|
|
||||||
<a name="Bot.BaseURL"></a>
|
<a name="Bot.BaseURL"></a>
|
||||||
### func \(\*Bot\) BaseURL
|
### func \(\*Bot\) [BaseURL](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/client.go#L20>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (b *Bot) BaseURL() string
|
func (b *Bot) BaseURL() string
|
||||||
@@ -196,7 +196,7 @@ func (b *Bot) BaseURL() string
|
|||||||
BaseURL returns the configured Telegram API base URL.
|
BaseURL returns the configured Telegram API base URL.
|
||||||
|
|
||||||
<a name="Bot.Codec"></a>
|
<a name="Bot.Codec"></a>
|
||||||
### func \(\*Bot\) Codec
|
### func \(\*Bot\) [Codec](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/client.go#L27>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (b *Bot) Codec() Codec
|
func (b *Bot) Codec() Codec
|
||||||
@@ -205,7 +205,7 @@ func (b *Bot) Codec() Codec
|
|||||||
Codec returns the configured Codec.
|
Codec returns the configured Codec.
|
||||||
|
|
||||||
<a name="Bot.HTTP"></a>
|
<a name="Bot.HTTP"></a>
|
||||||
### func \(\*Bot\) HTTP
|
### func \(\*Bot\) [HTTP](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/client.go#L24>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (b *Bot) HTTP() HTTPDoer
|
func (b *Bot) HTTP() HTTPDoer
|
||||||
@@ -214,7 +214,7 @@ func (b *Bot) HTTP() HTTPDoer
|
|||||||
HTTP returns the underlying HTTPDoer. Exposed for adapters that need to share connection pools or for diagnostic checks.
|
HTTP returns the underlying HTTPDoer. Exposed for adapters that need to share connection pools or for diagnostic checks.
|
||||||
|
|
||||||
<a name="Bot.Logger"></a>
|
<a name="Bot.Logger"></a>
|
||||||
### func \(\*Bot\) Logger
|
### func \(\*Bot\) [Logger](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/client.go#L30>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (b *Bot) Logger() Logger
|
func (b *Bot) Logger() Logger
|
||||||
@@ -223,7 +223,7 @@ func (b *Bot) Logger() Logger
|
|||||||
Logger returns the configured Logger.
|
Logger returns the configured Logger.
|
||||||
|
|
||||||
<a name="Bot.Token"></a>
|
<a name="Bot.Token"></a>
|
||||||
### func \(\*Bot\) Token
|
### func \(\*Bot\) [Token](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/client.go#L17>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (b *Bot) Token() string
|
func (b *Bot) Token() string
|
||||||
@@ -232,7 +232,7 @@ func (b *Bot) Token() string
|
|||||||
Token returns the bot token. Exposed for advanced use cases \(custom transports, manual URL building\); ordinary code does not need it.
|
Token returns the bot token. Exposed for advanced use cases \(custom transports, manual URL building\); ordinary code does not need it.
|
||||||
|
|
||||||
<a name="Codec"></a>
|
<a name="Codec"></a>
|
||||||
## type Codec
|
## type [Codec](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/codec.go#L10-L13>)
|
||||||
|
|
||||||
Codec encodes/decodes JSON payloads exchanged with the Telegram Bot API. The default implementation wraps goccy/go\-json. Users may plug in bytedance/sonic or any compatible encoder by passing WithCodec to New.
|
Codec encodes/decodes JSON payloads exchanged with the Telegram Bot API. The default implementation wraps goccy/go\-json. Users may plug in bytedance/sonic or any compatible encoder by passing WithCodec to New.
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ type Codec interface {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="DefaultCodec"></a>
|
<a name="DefaultCodec"></a>
|
||||||
## type DefaultCodec
|
## type [DefaultCodec](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/codec.go#L16>)
|
||||||
|
|
||||||
DefaultCodec wraps goccy/go\-json. It is the zero\-value safe default.
|
DefaultCodec wraps goccy/go\-json. It is the zero\-value safe default.
|
||||||
|
|
||||||
@@ -253,7 +253,7 @@ type DefaultCodec struct{}
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="DefaultCodec.Marshal"></a>
|
<a name="DefaultCodec.Marshal"></a>
|
||||||
### func \(DefaultCodec\) Marshal
|
### func \(DefaultCodec\) [Marshal](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/codec.go#L19>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (DefaultCodec) Marshal(v any) ([]byte, error)
|
func (DefaultCodec) Marshal(v any) ([]byte, error)
|
||||||
@@ -262,7 +262,7 @@ func (DefaultCodec) Marshal(v any) ([]byte, error)
|
|||||||
Marshal calls json.Marshal.
|
Marshal calls json.Marshal.
|
||||||
|
|
||||||
<a name="DefaultCodec.Unmarshal"></a>
|
<a name="DefaultCodec.Unmarshal"></a>
|
||||||
### func \(DefaultCodec\) Unmarshal
|
### func \(DefaultCodec\) [Unmarshal](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/codec.go#L22>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (DefaultCodec) Unmarshal(data []byte, v any) error
|
func (DefaultCodec) Unmarshal(data []byte, v any) error
|
||||||
@@ -271,7 +271,7 @@ func (DefaultCodec) Unmarshal(data []byte, v any) error
|
|||||||
Unmarshal calls json.Unmarshal.
|
Unmarshal calls json.Unmarshal.
|
||||||
|
|
||||||
<a name="HTTPDoer"></a>
|
<a name="HTTPDoer"></a>
|
||||||
## type HTTPDoer
|
## type [HTTPDoer](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/httpclient.go#L13-L15>)
|
||||||
|
|
||||||
HTTPDoer abstracts the HTTP transport. The default is a net/http client tuned for Telegram's long\-poll usage. Users may plug in valyala/fasthttp \(via an adapter\), or any custom retry/circuit\-breaker client by passing WithHTTPClient to New.
|
HTTPDoer abstracts the HTTP transport. The default is a net/http client tuned for Telegram's long\-poll usage. Users may plug in valyala/fasthttp \(via an adapter\), or any custom retry/circuit\-breaker client by passing WithHTTPClient to New.
|
||||||
|
|
||||||
@@ -282,7 +282,7 @@ type HTTPDoer interface {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="Logger"></a>
|
<a name="Logger"></a>
|
||||||
## type Logger
|
## type [Logger](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/logger.go#L6-L11>)
|
||||||
|
|
||||||
Logger is a slog\-shaped logging interface. Users pass any compatible implementation via WithLogger. The default is NoopLogger, which discards everything.
|
Logger is a slog\-shaped logging interface. Users pass any compatible implementation via WithLogger. The default is NoopLogger, which discards everything.
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@ type Logger interface {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="MultipartFile"></a>
|
<a name="MultipartFile"></a>
|
||||||
## type MultipartFile
|
## type [MultipartFile](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/multipart.go#L27-L31>)
|
||||||
|
|
||||||
MultipartFile describes a single file part in a multipart upload.
|
MultipartFile describes a single file part in a multipart upload.
|
||||||
|
|
||||||
@@ -309,7 +309,7 @@ type MultipartFile struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="NetworkError"></a>
|
<a name="NetworkError"></a>
|
||||||
## type NetworkError
|
## type [NetworkError](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/errors.go#L47>)
|
||||||
|
|
||||||
NetworkError wraps a transport\-level failure \(DNS, TCP, TLS, timeout short of an HTTP response\).
|
NetworkError wraps a transport\-level failure \(DNS, TCP, TLS, timeout short of an HTTP response\).
|
||||||
|
|
||||||
@@ -318,7 +318,7 @@ type NetworkError struct{ Err error }
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="NetworkError.Error"></a>
|
<a name="NetworkError.Error"></a>
|
||||||
### func \(\*NetworkError\) Error
|
### func \(\*NetworkError\) [Error](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/errors.go#L49>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (e *NetworkError) Error() string
|
func (e *NetworkError) Error() string
|
||||||
@@ -327,7 +327,7 @@ func (e *NetworkError) Error() string
|
|||||||
|
|
||||||
|
|
||||||
<a name="NetworkError.Unwrap"></a>
|
<a name="NetworkError.Unwrap"></a>
|
||||||
### func \(\*NetworkError\) Unwrap
|
### func \(\*NetworkError\) [Unwrap](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/errors.go#L51>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (e *NetworkError) Unwrap() error
|
func (e *NetworkError) Unwrap() error
|
||||||
@@ -336,7 +336,7 @@ func (e *NetworkError) Unwrap() error
|
|||||||
|
|
||||||
|
|
||||||
<a name="NoopLogger"></a>
|
<a name="NoopLogger"></a>
|
||||||
## type NoopLogger
|
## type [NoopLogger](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/logger.go#L14>)
|
||||||
|
|
||||||
NoopLogger discards all log records. It is the zero\-value safe default.
|
NoopLogger discards all log records. It is the zero\-value safe default.
|
||||||
|
|
||||||
@@ -345,7 +345,7 @@ type NoopLogger struct{}
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="NoopLogger.Debug"></a>
|
<a name="NoopLogger.Debug"></a>
|
||||||
### func \(NoopLogger\) Debug
|
### func \(NoopLogger\) [Debug](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/logger.go#L16>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (NoopLogger) Debug(string, ...any)
|
func (NoopLogger) Debug(string, ...any)
|
||||||
@@ -354,7 +354,7 @@ func (NoopLogger) Debug(string, ...any)
|
|||||||
|
|
||||||
|
|
||||||
<a name="NoopLogger.Error"></a>
|
<a name="NoopLogger.Error"></a>
|
||||||
### func \(NoopLogger\) Error
|
### func \(NoopLogger\) [Error](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/logger.go#L19>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (NoopLogger) Error(string, ...any)
|
func (NoopLogger) Error(string, ...any)
|
||||||
@@ -363,7 +363,7 @@ func (NoopLogger) Error(string, ...any)
|
|||||||
|
|
||||||
|
|
||||||
<a name="NoopLogger.Info"></a>
|
<a name="NoopLogger.Info"></a>
|
||||||
### func \(NoopLogger\) Info
|
### func \(NoopLogger\) [Info](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/logger.go#L17>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (NoopLogger) Info(string, ...any)
|
func (NoopLogger) Info(string, ...any)
|
||||||
@@ -372,7 +372,7 @@ func (NoopLogger) Info(string, ...any)
|
|||||||
|
|
||||||
|
|
||||||
<a name="NoopLogger.Warn"></a>
|
<a name="NoopLogger.Warn"></a>
|
||||||
### func \(NoopLogger\) Warn
|
### func \(NoopLogger\) [Warn](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/logger.go#L18>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (NoopLogger) Warn(string, ...any)
|
func (NoopLogger) Warn(string, ...any)
|
||||||
@@ -381,7 +381,7 @@ func (NoopLogger) Warn(string, ...any)
|
|||||||
|
|
||||||
|
|
||||||
<a name="Option"></a>
|
<a name="Option"></a>
|
||||||
## type Option
|
## type [Option](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/options.go#L5>)
|
||||||
|
|
||||||
Option configures a Bot at construction time. Per\-call configuration is expressed via typed parameter structs \(e.g. SendMessageParams\), not options.
|
Option configures a Bot at construction time. Per\-call configuration is expressed via typed parameter structs \(e.g. SendMessageParams\), not options.
|
||||||
|
|
||||||
@@ -390,7 +390,7 @@ type Option func(*Bot)
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="WithBaseURL"></a>
|
<a name="WithBaseURL"></a>
|
||||||
### func WithBaseURL
|
### func [WithBaseURL](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/options.go#L18>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithBaseURL(url string) Option
|
func WithBaseURL(url string) Option
|
||||||
@@ -399,7 +399,7 @@ func WithBaseURL(url string) Option
|
|||||||
WithBaseURL overrides the API base URL. Useful for testing against a local httptest.Server, or for self\-hosted Bot API servers.
|
WithBaseURL overrides the API base URL. Useful for testing against a local httptest.Server, or for self\-hosted Bot API servers.
|
||||||
|
|
||||||
<a name="WithCodec"></a>
|
<a name="WithCodec"></a>
|
||||||
### func WithCodec
|
### func [WithCodec](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/options.go#L14>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithCodec(c Codec) Option
|
func WithCodec(c Codec) Option
|
||||||
@@ -408,7 +408,7 @@ func WithCodec(c Codec) Option
|
|||||||
WithCodec overrides the JSON codec. Pass goccy/go\-json, sonic, or any type implementing Codec to swap out encoding/json.
|
WithCodec overrides the JSON codec. Pass goccy/go\-json, sonic, or any type implementing Codec to swap out encoding/json.
|
||||||
|
|
||||||
<a name="WithHTTPClient"></a>
|
<a name="WithHTTPClient"></a>
|
||||||
### func WithHTTPClient
|
### func [WithHTTPClient](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/options.go#L10>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithHTTPClient(c HTTPDoer) Option
|
func WithHTTPClient(c HTTPDoer) Option
|
||||||
@@ -417,7 +417,7 @@ func WithHTTPClient(c HTTPDoer) Option
|
|||||||
WithHTTPClient overrides the HTTP transport. Pass any HTTPDoer implementation \(e.g. an \*http.Client wrapping a custom RoundTripper, or a fasthttp adapter\).
|
WithHTTPClient overrides the HTTP transport. Pass any HTTPDoer implementation \(e.g. an \*http.Client wrapping a custom RoundTripper, or a fasthttp adapter\).
|
||||||
|
|
||||||
<a name="WithLogger"></a>
|
<a name="WithLogger"></a>
|
||||||
### func WithLogger
|
### func [WithLogger](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/options.go#L22>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithLogger(l Logger) Option
|
func WithLogger(l Logger) Option
|
||||||
@@ -426,7 +426,7 @@ func WithLogger(l Logger) Option
|
|||||||
WithLogger sets the logger used for diagnostic events. Passing nil silently disables logging.
|
WithLogger sets the logger used for diagnostic events. Passing nil silently disables logging.
|
||||||
|
|
||||||
<a name="ParseError"></a>
|
<a name="ParseError"></a>
|
||||||
## type ParseError
|
## type [ParseError](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/errors.go#L55-L58>)
|
||||||
|
|
||||||
ParseError wraps a JSON decode failure on a response body. Body is retained \(truncated to 4 KiB\); Error\(\) displays up to 256 bytes for diagnostics.
|
ParseError wraps a JSON decode failure on a response body. Body is retained \(truncated to 4 KiB\); Error\(\) displays up to 256 bytes for diagnostics.
|
||||||
|
|
||||||
@@ -438,7 +438,7 @@ type ParseError struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="ParseError.Error"></a>
|
<a name="ParseError.Error"></a>
|
||||||
### func \(\*ParseError\) Error
|
### func \(\*ParseError\) [Error](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/errors.go#L60>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (e *ParseError) Error() string
|
func (e *ParseError) Error() string
|
||||||
@@ -447,7 +447,7 @@ func (e *ParseError) Error() string
|
|||||||
|
|
||||||
|
|
||||||
<a name="ParseError.Unwrap"></a>
|
<a name="ParseError.Unwrap"></a>
|
||||||
### func \(\*ParseError\) Unwrap
|
### func \(\*ParseError\) [Unwrap](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/errors.go#L68>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (e *ParseError) Unwrap() error
|
func (e *ParseError) Unwrap() error
|
||||||
@@ -456,7 +456,7 @@ func (e *ParseError) Unwrap() error
|
|||||||
|
|
||||||
|
|
||||||
<a name="ResponseParameters"></a>
|
<a name="ResponseParameters"></a>
|
||||||
## type ResponseParameters
|
## type [ResponseParameters](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/result.go#L24-L27>)
|
||||||
|
|
||||||
ResponseParameters is the optional metadata Telegram includes on certain failures. The most common is RetryAfter \(seconds\) on 429 responses.
|
ResponseParameters is the optional metadata Telegram includes on certain failures. The most common is RetryAfter \(seconds\) on 429 responses.
|
||||||
|
|
||||||
@@ -470,7 +470,7 @@ type ResponseParameters struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="Result"></a>
|
<a name="Result"></a>
|
||||||
## type Result
|
## type [Result](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/result.go#L11-L17>)
|
||||||
|
|
||||||
Result is the universal Telegram API response envelope. Every successful response is shaped \{"ok":true,"result":T,...\}; failure responses set ok to false and populate ErrorCode / Description / Parameters.
|
Result is the universal Telegram API response envelope. Every successful response is shaped \{"ok":true,"result":T,...\}; failure responses set ok to false and populate ErrorCode / Description / Parameters.
|
||||||
|
|
||||||
@@ -487,7 +487,7 @@ type Result[T any] struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="RetryDoer"></a>
|
<a name="RetryDoer"></a>
|
||||||
## type RetryDoer
|
## type [RetryDoer](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/retry.go#L23-L30>)
|
||||||
|
|
||||||
RetryDoer is an HTTPDoer that retries transient failures \(429, 5xx, and network errors\) with exponential backoff. It honours the retry\_after value Telegram supplies on rate\-limit responses.
|
RetryDoer is an HTTPDoer that retries transient failures \(429, 5xx, and network errors\) with exponential backoff. It honours the retry\_after value Telegram supplies on rate\-limit responses.
|
||||||
|
|
||||||
@@ -505,7 +505,7 @@ type RetryDoer struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="NewRetryDoer"></a>
|
<a name="NewRetryDoer"></a>
|
||||||
### func NewRetryDoer
|
### func [NewRetryDoer](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/retry.go#L63>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func NewRetryDoer(inner HTTPDoer, opts ...RetryOption) *RetryDoer
|
func NewRetryDoer(inner HTTPDoer, opts ...RetryOption) *RetryDoer
|
||||||
@@ -514,7 +514,7 @@ func NewRetryDoer(inner HTTPDoer, opts ...RetryOption) *RetryDoer
|
|||||||
NewRetryDoer wraps inner with retry behaviour.
|
NewRetryDoer wraps inner with retry behaviour.
|
||||||
|
|
||||||
<a name="RetryDoer.Do"></a>
|
<a name="RetryDoer.Do"></a>
|
||||||
### func \(\*RetryDoer\) Do
|
### func \(\*RetryDoer\) [Do](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/retry.go#L80>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (d *RetryDoer) Do(req *http.Request) (*http.Response, error)
|
func (d *RetryDoer) Do(req *http.Request) (*http.Response, error)
|
||||||
@@ -523,7 +523,7 @@ func (d *RetryDoer) Do(req *http.Request) (*http.Response, error)
|
|||||||
Do dispatches via the inner HTTPDoer and retries on transient failures. The request body is buffered on first attempt so it can be replayed.
|
Do dispatches via the inner HTTPDoer and retries on transient failures. The request body is buffered on first attempt so it can be replayed.
|
||||||
|
|
||||||
<a name="RetryOption"></a>
|
<a name="RetryOption"></a>
|
||||||
## type RetryOption
|
## type [RetryOption](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/retry.go#L33>)
|
||||||
|
|
||||||
RetryOption configures a RetryDoer.
|
RetryOption configures a RetryDoer.
|
||||||
|
|
||||||
@@ -532,7 +532,7 @@ type RetryOption func(*RetryDoer)
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="WithBackoffFactor"></a>
|
<a name="WithBackoffFactor"></a>
|
||||||
### func WithBackoffFactor
|
### func [WithBackoffFactor](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/retry.go#L52>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithBackoffFactor(f float64) RetryOption
|
func WithBackoffFactor(f float64) RetryOption
|
||||||
@@ -541,7 +541,7 @@ func WithBackoffFactor(f float64) RetryOption
|
|||||||
WithBackoffFactor sets the exponential growth factor. Default 2.0.
|
WithBackoffFactor sets the exponential growth factor. Default 2.0.
|
||||||
|
|
||||||
<a name="WithBaseBackoff"></a>
|
<a name="WithBaseBackoff"></a>
|
||||||
### func WithBaseBackoff
|
### func [WithBaseBackoff](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/retry.go#L42>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithBaseBackoff(d time.Duration) RetryOption
|
func WithBaseBackoff(d time.Duration) RetryOption
|
||||||
@@ -550,7 +550,7 @@ func WithBaseBackoff(d time.Duration) RetryOption
|
|||||||
WithBaseBackoff sets the initial backoff duration. Default 500ms.
|
WithBaseBackoff sets the initial backoff duration. Default 500ms.
|
||||||
|
|
||||||
<a name="WithJitter"></a>
|
<a name="WithJitter"></a>
|
||||||
### func WithJitter
|
### func [WithJitter](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/retry.go#L58>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithJitter(j float64) RetryOption
|
func WithJitter(j float64) RetryOption
|
||||||
@@ -559,7 +559,7 @@ func WithJitter(j float64) RetryOption
|
|||||||
WithJitter sets the jitter fraction \(0..1\) applied to each backoff. Default 0.2.
|
WithJitter sets the jitter fraction \(0..1\) applied to each backoff. Default 0.2.
|
||||||
|
|
||||||
<a name="WithMaxAttempts"></a>
|
<a name="WithMaxAttempts"></a>
|
||||||
### func WithMaxAttempts
|
### func [WithMaxAttempts](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/retry.go#L37>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithMaxAttempts(n int) RetryOption
|
func WithMaxAttempts(n int) RetryOption
|
||||||
@@ -568,7 +568,7 @@ func WithMaxAttempts(n int) RetryOption
|
|||||||
WithMaxAttempts sets the maximum number of attempts \(including the initial one\). Default 4 \(one initial \+ three retries\).
|
WithMaxAttempts sets the maximum number of attempts \(including the initial one\). Default 4 \(one initial \+ three retries\).
|
||||||
|
|
||||||
<a name="WithMaxBackoff"></a>
|
<a name="WithMaxBackoff"></a>
|
||||||
### func WithMaxBackoff
|
### func [WithMaxBackoff](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/retry.go#L47>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithMaxBackoff(d time.Duration) RetryOption
|
func WithMaxBackoff(d time.Duration) RetryOption
|
||||||
|
|||||||
+58
-58
@@ -90,7 +90,7 @@ var ErrEndGroups = errors.New("dispatch: end groups")
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="Context"></a>
|
<a name="Context"></a>
|
||||||
## type Context
|
## type [Context](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/context.go#L29-L34>)
|
||||||
|
|
||||||
Context bundles the per\-update state every handler receives.
|
Context bundles the per\-update state every handler receives.
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ type Context struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="NewContext"></a>
|
<a name="NewContext"></a>
|
||||||
### func NewContext
|
### func [NewContext](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/context.go#L38>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func NewContext(ctx context.Context, b *client.Bot, u *api.Update) *Context
|
func NewContext(ctx context.Context, b *client.Bot, u *api.Update) *Context
|
||||||
@@ -127,7 +127,7 @@ func NewContext(ctx context.Context, b *client.Bot, u *api.Update) *Context
|
|||||||
NewContext constructs a Context. Used by Router internally; exposed for custom test harnesses.
|
NewContext constructs a Context. Used by Router internally; exposed for custom test harnesses.
|
||||||
|
|
||||||
<a name="Filter"></a>
|
<a name="Filter"></a>
|
||||||
## type Filter
|
## type [Filter](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filter.go#L9>)
|
||||||
|
|
||||||
Filter is a predicate over a typed payload \(e.g. \*api.Message\). Filters compose via And/Or/Not for multi\-condition matching.
|
Filter is a predicate over a typed payload \(e.g. \*api.Message\). Filters compose via And/Or/Not for multi\-condition matching.
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ type Filter[T any] func(payload T) bool
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="All"></a>
|
<a name="All"></a>
|
||||||
### func All
|
### func [All](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filter.go#L48>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func All[T any](filters ...Filter[T]) Filter[T]
|
func All[T any](filters ...Filter[T]) Filter[T]
|
||||||
@@ -151,7 +151,7 @@ func All[T any](filters ...Filter[T]) Filter[T]
|
|||||||
All combines filters with AND. Returns a Filter that matches when all match. Returns a filter that always matches when filters is empty.
|
All combines filters with AND. Returns a Filter that matches when all match. Returns a filter that always matches when filters is empty.
|
||||||
|
|
||||||
<a name="Any"></a>
|
<a name="Any"></a>
|
||||||
### func Any
|
### func [Any](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filter.go#L61>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Any[T any](filters ...Filter[T]) Filter[T]
|
func Any[T any](filters ...Filter[T]) Filter[T]
|
||||||
@@ -160,7 +160,7 @@ func Any[T any](filters ...Filter[T]) Filter[T]
|
|||||||
Any combines filters with OR. Returns a Filter that matches when at least one matches. Returns a filter that never matches when filters is empty.
|
Any combines filters with OR. Returns a Filter that matches when at least one matches. Returns a filter that never matches when filters is empty.
|
||||||
|
|
||||||
<a name="Filter[T].And"></a>
|
<a name="Filter[T].And"></a>
|
||||||
### func \(Filter\[T\]\) And
|
### func \(Filter\[T\]\) [And](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filter.go#L12>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (f Filter[T]) And(others ...Filter[T]) Filter[T]
|
func (f Filter[T]) And(others ...Filter[T]) Filter[T]
|
||||||
@@ -169,7 +169,7 @@ func (f Filter[T]) And(others ...Filter[T]) Filter[T]
|
|||||||
And returns a Filter that matches iff f and every one of others matches.
|
And returns a Filter that matches iff f and every one of others matches.
|
||||||
|
|
||||||
<a name="Filter[T].Not"></a>
|
<a name="Filter[T].Not"></a>
|
||||||
### func \(Filter\[T\]\) Not
|
### func \(Filter\[T\]\) [Not](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filter.go#L42>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (f Filter[T]) Not() Filter[T]
|
func (f Filter[T]) Not() Filter[T]
|
||||||
@@ -178,7 +178,7 @@ func (f Filter[T]) Not() Filter[T]
|
|||||||
Not returns a Filter that inverts f.
|
Not returns a Filter that inverts f.
|
||||||
|
|
||||||
<a name="Filter[T].Or"></a>
|
<a name="Filter[T].Or"></a>
|
||||||
### func \(Filter\[T\]\) Or
|
### func \(Filter\[T\]\) [Or](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filter.go#L27>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (f Filter[T]) Or(others ...Filter[T]) Filter[T]
|
func (f Filter[T]) Or(others ...Filter[T]) Filter[T]
|
||||||
@@ -187,7 +187,7 @@ func (f Filter[T]) Or(others ...Filter[T]) Filter[T]
|
|||||||
Or returns a Filter that matches iff f matches OR any of others matches.
|
Or returns a Filter that matches iff f matches OR any of others matches.
|
||||||
|
|
||||||
<a name="Handler"></a>
|
<a name="Handler"></a>
|
||||||
## type Handler
|
## type [Handler](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/handler.go#L6>)
|
||||||
|
|
||||||
Handler is a generic handler over update payload type T. T is typically \*api.Message, \*api.CallbackQuery, \*api.InlineQuery, or \*api.Update for global middleware.
|
Handler is a generic handler over update payload type T. T is typically \*api.Message, \*api.CallbackQuery, \*api.InlineQuery, or \*api.Update for global middleware.
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ type Handler[T any] func(ctx *Context, payload T) error
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="Middleware"></a>
|
<a name="Middleware"></a>
|
||||||
## type Middleware
|
## type [Middleware](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/handler.go#L11>)
|
||||||
|
|
||||||
Middleware wraps a Handler\[T\] with cross\-cutting behaviour \(logging, recovery, auth\). Middleware composition is left\-to\-right: Use\(a,b,c\) runs as a\(b\(c\(handler\)\)\).
|
Middleware wraps a Handler\[T\] with cross\-cutting behaviour \(logging, recovery, auth\). Middleware composition is left\-to\-right: Use\(a,b,c\) runs as a\(b\(c\(handler\)\)\).
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ type Middleware[T any] func(Handler[T]) Handler[T]
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="Chain"></a>
|
<a name="Chain"></a>
|
||||||
### func Chain
|
### func [Chain](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/handler.go#L14>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Chain[T any](mws ...Middleware[T]) Middleware[T]
|
func Chain[T any](mws ...Middleware[T]) Middleware[T]
|
||||||
@@ -214,7 +214,7 @@ func Chain[T any](mws ...Middleware[T]) Middleware[T]
|
|||||||
Chain composes a slice of middleware into a single Middleware\[T\].
|
Chain composes a slice of middleware into a single Middleware\[T\].
|
||||||
|
|
||||||
<a name="Recovery"></a>
|
<a name="Recovery"></a>
|
||||||
### func Recovery
|
### func [Recovery](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/middleware.go#L13>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Recovery() Middleware[*api.Update]
|
func Recovery() Middleware[*api.Update]
|
||||||
@@ -223,7 +223,7 @@ func Recovery() Middleware[*api.Update]
|
|||||||
Recovery returns middleware that recovers from panics in downstream handlers, converting them into a returned error and logging via the bot's configured logger. Registered automatically by NewRouter.
|
Recovery returns middleware that recovers from panics in downstream handlers, converting them into a returned error and logging via the bot's configured logger. Registered automatically by NewRouter.
|
||||||
|
|
||||||
<a name="NamedHandlers"></a>
|
<a name="NamedHandlers"></a>
|
||||||
## type NamedHandlers
|
## type [NamedHandlers](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/named.go#L15-L19>)
|
||||||
|
|
||||||
NamedHandlers manages handlers by string name, allowing runtime registration, replacement, and removal. This complements the Router's registration methods: each registration via Named\*\(\) also gets a name for later lookup.
|
NamedHandlers manages handlers by string name, allowing runtime registration, replacement, and removal. This complements the Router's registration methods: each registration via Named\*\(\) also gets a name for later lookup.
|
||||||
|
|
||||||
@@ -236,7 +236,7 @@ type NamedHandlers[T any] struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="NewNamedHandlers"></a>
|
<a name="NewNamedHandlers"></a>
|
||||||
### func NewNamedHandlers
|
### func [NewNamedHandlers](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/named.go#L22>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func NewNamedHandlers[T any]() *NamedHandlers[T]
|
func NewNamedHandlers[T any]() *NamedHandlers[T]
|
||||||
@@ -245,7 +245,7 @@ func NewNamedHandlers[T any]() *NamedHandlers[T]
|
|||||||
NewNamedHandlers returns a new, empty NamedHandlers\[T\].
|
NewNamedHandlers returns a new, empty NamedHandlers\[T\].
|
||||||
|
|
||||||
<a name="NamedHandlers[T].Handler"></a>
|
<a name="NamedHandlers[T].Handler"></a>
|
||||||
### func \(\*NamedHandlers\[T\]\) Handler
|
### func \(\*NamedHandlers\[T\]\) [Handler](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/named.go#L81>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (n *NamedHandlers[T]) Handler() Handler[T]
|
func (n *NamedHandlers[T]) Handler() Handler[T]
|
||||||
@@ -263,7 +263,7 @@ router.OnCommand("/admin", names.Handler())
|
|||||||
Subsequent Set/Remove calls take effect on the next dispatch.
|
Subsequent Set/Remove calls take effect on the next dispatch.
|
||||||
|
|
||||||
<a name="NamedHandlers[T].Has"></a>
|
<a name="NamedHandlers[T].Has"></a>
|
||||||
### func \(\*NamedHandlers\[T\]\) Has
|
### func \(\*NamedHandlers\[T\]\) [Has](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/named.go#L55>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (n *NamedHandlers[T]) Has(name string) bool
|
func (n *NamedHandlers[T]) Has(name string) bool
|
||||||
@@ -272,7 +272,7 @@ func (n *NamedHandlers[T]) Has(name string) bool
|
|||||||
Has reports whether name is registered.
|
Has reports whether name is registered.
|
||||||
|
|
||||||
<a name="NamedHandlers[T].Names"></a>
|
<a name="NamedHandlers[T].Names"></a>
|
||||||
### func \(\*NamedHandlers\[T\]\) Names
|
### func \(\*NamedHandlers\[T\]\) [Names](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/named.go#L63>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (n *NamedHandlers[T]) Names() []string
|
func (n *NamedHandlers[T]) Names() []string
|
||||||
@@ -281,7 +281,7 @@ func (n *NamedHandlers[T]) Names() []string
|
|||||||
Names returns the registered names in registration order.
|
Names returns the registered names in registration order.
|
||||||
|
|
||||||
<a name="NamedHandlers[T].Remove"></a>
|
<a name="NamedHandlers[T].Remove"></a>
|
||||||
### func \(\*NamedHandlers\[T\]\) Remove
|
### func \(\*NamedHandlers\[T\]\) [Remove](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/named.go#L38>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (n *NamedHandlers[T]) Remove(name string) bool
|
func (n *NamedHandlers[T]) Remove(name string) bool
|
||||||
@@ -290,7 +290,7 @@ func (n *NamedHandlers[T]) Remove(name string) bool
|
|||||||
Remove unregisters the handler under name. Returns true if it existed.
|
Remove unregisters the handler under name. Returns true if it existed.
|
||||||
|
|
||||||
<a name="NamedHandlers[T].Set"></a>
|
<a name="NamedHandlers[T].Set"></a>
|
||||||
### func \(\*NamedHandlers\[T\]\) Set
|
### func \(\*NamedHandlers\[T\]\) [Set](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/named.go#L28>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (n *NamedHandlers[T]) Set(name string, h Handler[T])
|
func (n *NamedHandlers[T]) Set(name string, h Handler[T])
|
||||||
@@ -299,7 +299,7 @@ func (n *NamedHandlers[T]) Set(name string, h Handler[T])
|
|||||||
Set registers or replaces the handler under name. If name is new, it is appended to the end of the registration order.
|
Set registers or replaces the handler under name. If name is new, it is appended to the end of the registration order.
|
||||||
|
|
||||||
<a name="Router"></a>
|
<a name="Router"></a>
|
||||||
## type Router
|
## type [Router](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L19-L64>)
|
||||||
|
|
||||||
Router dispatches updates from any Updater to typed handlers.
|
Router dispatches updates from any Updater to typed handlers.
|
||||||
|
|
||||||
@@ -312,7 +312,7 @@ type Router struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="New"></a>
|
<a name="New"></a>
|
||||||
### func New
|
### func [New](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L128>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func New(b *client.Bot, opts ...RouterOption) *Router
|
func New(b *client.Bot, opts ...RouterOption) *Router
|
||||||
@@ -321,7 +321,7 @@ func New(b *client.Bot, opts ...RouterOption) *Router
|
|||||||
New constructs a Router. Recovery middleware is added by default; users can disable it by passing WithoutRecovery \(not implemented here, but the hook is in place via Use\).
|
New constructs a Router. Recovery middleware is added by default; users can disable it by passing WithoutRecovery \(not implemented here, but the hook is in place via Use\).
|
||||||
|
|
||||||
<a name="Router.Group"></a>
|
<a name="Router.Group"></a>
|
||||||
### func \(\*Router\) Group
|
### func \(\*Router\) [Group](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/groups.go#L40>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) Group(group int) *RouterScope
|
func (r *Router) Group(group int) *RouterScope
|
||||||
@@ -330,7 +330,7 @@ func (r *Router) Group(group int) *RouterScope
|
|||||||
Group returns a RouterScope that registers handlers in the given group. Group 0 \(the default\) runs first, then group 1, etc. Within a group, handlers run in registration order; the first non\-skipped match terminates dispatch unless the handler returns ErrContinueGroups.
|
Group returns a RouterScope that registers handlers in the given group. Group 0 \(the default\) runs first, then group 1, etc. Within a group, handlers run in registration order; the first non\-skipped match terminates dispatch unless the handler returns ErrContinueGroups.
|
||||||
|
|
||||||
<a name="Router.OnBusinessConnection"></a>
|
<a name="Router.OnBusinessConnection"></a>
|
||||||
### func \(\*Router\) OnBusinessConnection
|
### func \(\*Router\) [OnBusinessConnection](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L285>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnBusinessConnection(h Handler[*api.BusinessConnection])
|
func (r *Router) OnBusinessConnection(h Handler[*api.BusinessConnection])
|
||||||
@@ -339,7 +339,7 @@ func (r *Router) OnBusinessConnection(h Handler[*api.BusinessConnection])
|
|||||||
OnBusinessConnection registers a handler for business connection updates.
|
OnBusinessConnection registers a handler for business connection updates.
|
||||||
|
|
||||||
<a name="Router.OnCallback"></a>
|
<a name="Router.OnCallback"></a>
|
||||||
### func \(\*Router\) OnCallback
|
### func \(\*Router\) [OnCallback](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L161>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnCallback(pattern string, h Handler[*api.CallbackQuery])
|
func (r *Router) OnCallback(pattern string, h Handler[*api.CallbackQuery])
|
||||||
@@ -350,7 +350,7 @@ OnCallback registers a handler for callback queries whose Data matches the regex
|
|||||||
Panics at registration time if pattern is not a valid regular expression.
|
Panics at registration time if pattern is not a valid regular expression.
|
||||||
|
|
||||||
<a name="Router.OnCallbackFilter"></a>
|
<a name="Router.OnCallbackFilter"></a>
|
||||||
### func \(\*Router\) OnCallbackFilter
|
### func \(\*Router\) [OnCallbackFilter](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L194>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnCallbackFilter(f Filter[*api.CallbackQuery], h Handler[*api.CallbackQuery])
|
func (r *Router) OnCallbackFilter(f Filter[*api.CallbackQuery], h Handler[*api.CallbackQuery])
|
||||||
@@ -359,7 +359,7 @@ func (r *Router) OnCallbackFilter(f Filter[*api.CallbackQuery], h Handler[*api.C
|
|||||||
OnCallbackFilter registers a typed callback\-query handler gated by filter f. Filter routes are checked after pattern\-based OnCallback routes; first match wins.
|
OnCallbackFilter registers a typed callback\-query handler gated by filter f. Filter routes are checked after pattern\-based OnCallback routes; first match wins.
|
||||||
|
|
||||||
<a name="Router.OnChannelPost"></a>
|
<a name="Router.OnChannelPost"></a>
|
||||||
### func \(\*Router\) OnChannelPost
|
### func \(\*Router\) [OnChannelPost](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L177>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnChannelPost(h Handler[*api.Message])
|
func (r *Router) OnChannelPost(h Handler[*api.Message])
|
||||||
@@ -368,7 +368,7 @@ func (r *Router) OnChannelPost(h Handler[*api.Message])
|
|||||||
OnChannelPost registers a handler for channel post updates.
|
OnChannelPost registers a handler for channel post updates.
|
||||||
|
|
||||||
<a name="Router.OnChatBoost"></a>
|
<a name="Router.OnChatBoost"></a>
|
||||||
### func \(\*Router\) OnChatBoost
|
### func \(\*Router\) [OnChatBoost](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L275>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnChatBoost(h Handler[*api.ChatBoostUpdated])
|
func (r *Router) OnChatBoost(h Handler[*api.ChatBoostUpdated])
|
||||||
@@ -377,7 +377,7 @@ func (r *Router) OnChatBoost(h Handler[*api.ChatBoostUpdated])
|
|||||||
OnChatBoost registers a handler for chat boost updates.
|
OnChatBoost registers a handler for chat boost updates.
|
||||||
|
|
||||||
<a name="Router.OnChatJoinRequest"></a>
|
<a name="Router.OnChatJoinRequest"></a>
|
||||||
### func \(\*Router\) OnChatJoinRequest
|
### func \(\*Router\) [OnChatJoinRequest](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L225>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnChatJoinRequest(h Handler[*api.ChatJoinRequest])
|
func (r *Router) OnChatJoinRequest(h Handler[*api.ChatJoinRequest])
|
||||||
@@ -386,7 +386,7 @@ func (r *Router) OnChatJoinRequest(h Handler[*api.ChatJoinRequest])
|
|||||||
OnChatJoinRequest registers a handler for chat join requests.
|
OnChatJoinRequest registers a handler for chat join requests.
|
||||||
|
|
||||||
<a name="Router.OnChatJoinRequestFilter"></a>
|
<a name="Router.OnChatJoinRequestFilter"></a>
|
||||||
### func \(\*Router\) OnChatJoinRequestFilter
|
### func \(\*Router\) [OnChatJoinRequestFilter](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L230>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnChatJoinRequestFilter(f Filter[*api.ChatJoinRequest], h Handler[*api.ChatJoinRequest])
|
func (r *Router) OnChatJoinRequestFilter(f Filter[*api.ChatJoinRequest], h Handler[*api.ChatJoinRequest])
|
||||||
@@ -395,7 +395,7 @@ func (r *Router) OnChatJoinRequestFilter(f Filter[*api.ChatJoinRequest], h Handl
|
|||||||
OnChatJoinRequestFilter registers a filtered handler for chat join requests.
|
OnChatJoinRequestFilter registers a filtered handler for chat join requests.
|
||||||
|
|
||||||
<a name="Router.OnChatMember"></a>
|
<a name="Router.OnChatMember"></a>
|
||||||
### func \(\*Router\) OnChatMember
|
### func \(\*Router\) [OnChatMember](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L215>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnChatMember(h Handler[*api.ChatMemberUpdated])
|
func (r *Router) OnChatMember(h Handler[*api.ChatMemberUpdated])
|
||||||
@@ -404,7 +404,7 @@ func (r *Router) OnChatMember(h Handler[*api.ChatMemberUpdated])
|
|||||||
OnChatMember registers a handler for chat member status changes.
|
OnChatMember registers a handler for chat member status changes.
|
||||||
|
|
||||||
<a name="Router.OnChatMemberFilter"></a>
|
<a name="Router.OnChatMemberFilter"></a>
|
||||||
### func \(\*Router\) OnChatMemberFilter
|
### func \(\*Router\) [OnChatMemberFilter](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L220>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnChatMemberFilter(f Filter[*api.ChatMemberUpdated], h Handler[*api.ChatMemberUpdated])
|
func (r *Router) OnChatMemberFilter(f Filter[*api.ChatMemberUpdated], h Handler[*api.ChatMemberUpdated])
|
||||||
@@ -413,7 +413,7 @@ func (r *Router) OnChatMemberFilter(f Filter[*api.ChatMemberUpdated], h Handler[
|
|||||||
OnChatMemberFilter registers a filtered handler for chat member status changes.
|
OnChatMemberFilter registers a filtered handler for chat member status changes.
|
||||||
|
|
||||||
<a name="Router.OnChosenInlineResult"></a>
|
<a name="Router.OnChosenInlineResult"></a>
|
||||||
### func \(\*Router\) OnChosenInlineResult
|
### func \(\*Router\) [OnChosenInlineResult](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L260>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnChosenInlineResult(h Handler[*api.ChosenInlineResult])
|
func (r *Router) OnChosenInlineResult(h Handler[*api.ChosenInlineResult])
|
||||||
@@ -422,7 +422,7 @@ func (r *Router) OnChosenInlineResult(h Handler[*api.ChosenInlineResult])
|
|||||||
OnChosenInlineResult registers a handler for chosen inline results.
|
OnChosenInlineResult registers a handler for chosen inline results.
|
||||||
|
|
||||||
<a name="Router.OnCommand"></a>
|
<a name="Router.OnCommand"></a>
|
||||||
### func \(\*Router\) OnCommand
|
### func \(\*Router\) [OnCommand](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L146>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnCommand(cmd string, h Handler[*api.Message])
|
func (r *Router) OnCommand(cmd string, h Handler[*api.Message])
|
||||||
@@ -431,7 +431,7 @@ func (r *Router) OnCommand(cmd string, h Handler[*api.Message])
|
|||||||
OnCommand registers a handler for a slash command. The command string includes the leading slash \(e.g. "/start"\). Matching strips an optional "@BotName" suffix.
|
OnCommand registers a handler for a slash command. The command string includes the leading slash \(e.g. "/start"\). Matching strips an optional "@BotName" suffix.
|
||||||
|
|
||||||
<a name="Router.OnEditedChannelPost"></a>
|
<a name="Router.OnEditedChannelPost"></a>
|
||||||
### func \(\*Router\) OnEditedChannelPost
|
### func \(\*Router\) [OnEditedChannelPost](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L182>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnEditedChannelPost(h Handler[*api.Message])
|
func (r *Router) OnEditedChannelPost(h Handler[*api.Message])
|
||||||
@@ -440,7 +440,7 @@ func (r *Router) OnEditedChannelPost(h Handler[*api.Message])
|
|||||||
OnEditedChannelPost registers a handler for edited channel post updates.
|
OnEditedChannelPost registers a handler for edited channel post updates.
|
||||||
|
|
||||||
<a name="Router.OnEditedMessage"></a>
|
<a name="Router.OnEditedMessage"></a>
|
||||||
### func \(\*Router\) OnEditedMessage
|
### func \(\*Router\) [OnEditedMessage](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L172>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnEditedMessage(h Handler[*api.Message])
|
func (r *Router) OnEditedMessage(h Handler[*api.Message])
|
||||||
@@ -449,7 +449,7 @@ func (r *Router) OnEditedMessage(h Handler[*api.Message])
|
|||||||
OnEditedMessage registers a handler for edited message updates.
|
OnEditedMessage registers a handler for edited message updates.
|
||||||
|
|
||||||
<a name="Router.OnInlineQuery"></a>
|
<a name="Router.OnInlineQuery"></a>
|
||||||
### func \(\*Router\) OnInlineQuery
|
### func \(\*Router\) [OnInlineQuery](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L167>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnInlineQuery(h Handler[*api.InlineQuery])
|
func (r *Router) OnInlineQuery(h Handler[*api.InlineQuery])
|
||||||
@@ -458,7 +458,7 @@ func (r *Router) OnInlineQuery(h Handler[*api.InlineQuery])
|
|||||||
OnInlineQuery registers a handler for inline queries \(one matcher only; inline queries are not partitioned by content here\).
|
OnInlineQuery registers a handler for inline queries \(one matcher only; inline queries are not partitioned by content here\).
|
||||||
|
|
||||||
<a name="Router.OnInlineQueryFilter"></a>
|
<a name="Router.OnInlineQueryFilter"></a>
|
||||||
### func \(\*Router\) OnInlineQueryFilter
|
### func \(\*Router\) [OnInlineQueryFilter](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L200>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnInlineQueryFilter(f Filter[*api.InlineQuery], h Handler[*api.InlineQuery])
|
func (r *Router) OnInlineQueryFilter(f Filter[*api.InlineQuery], h Handler[*api.InlineQuery])
|
||||||
@@ -467,7 +467,7 @@ func (r *Router) OnInlineQueryFilter(f Filter[*api.InlineQuery], h Handler[*api.
|
|||||||
OnInlineQueryFilter registers an inline\-query handler gated by filter f. Filter routes are checked after bare OnInlineQuery handlers; first match wins.
|
OnInlineQueryFilter registers an inline\-query handler gated by filter f. Filter routes are checked after bare OnInlineQuery handlers; first match wins.
|
||||||
|
|
||||||
<a name="Router.OnMessageFilter"></a>
|
<a name="Router.OnMessageFilter"></a>
|
||||||
### func \(\*Router\) OnMessageFilter
|
### func \(\*Router\) [OnMessageFilter](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L188>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnMessageFilter(f Filter[*api.Message], h Handler[*api.Message])
|
func (r *Router) OnMessageFilter(f Filter[*api.Message], h Handler[*api.Message])
|
||||||
@@ -476,7 +476,7 @@ func (r *Router) OnMessageFilter(f Filter[*api.Message], h Handler[*api.Message]
|
|||||||
OnMessageFilter registers a typed message handler gated by filter f. Filter routes are checked after command and text routes; first match wins.
|
OnMessageFilter registers a typed message handler gated by filter f. Filter routes are checked after command and text routes; first match wins.
|
||||||
|
|
||||||
<a name="Router.OnMessageReaction"></a>
|
<a name="Router.OnMessageReaction"></a>
|
||||||
### func \(\*Router\) OnMessageReaction
|
### func \(\*Router\) [OnMessageReaction](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L265>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnMessageReaction(h Handler[*api.MessageReactionUpdated])
|
func (r *Router) OnMessageReaction(h Handler[*api.MessageReactionUpdated])
|
||||||
@@ -485,7 +485,7 @@ func (r *Router) OnMessageReaction(h Handler[*api.MessageReactionUpdated])
|
|||||||
OnMessageReaction registers a handler for message reaction updates.
|
OnMessageReaction registers a handler for message reaction updates.
|
||||||
|
|
||||||
<a name="Router.OnMessageReactionCount"></a>
|
<a name="Router.OnMessageReactionCount"></a>
|
||||||
### func \(\*Router\) OnMessageReactionCount
|
### func \(\*Router\) [OnMessageReactionCount](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L270>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnMessageReactionCount(h Handler[*api.MessageReactionCountUpdated])
|
func (r *Router) OnMessageReactionCount(h Handler[*api.MessageReactionCountUpdated])
|
||||||
@@ -494,7 +494,7 @@ func (r *Router) OnMessageReactionCount(h Handler[*api.MessageReactionCountUpdat
|
|||||||
OnMessageReactionCount registers a handler for anonymous message reaction count updates.
|
OnMessageReactionCount registers a handler for anonymous message reaction count updates.
|
||||||
|
|
||||||
<a name="Router.OnMyChatMember"></a>
|
<a name="Router.OnMyChatMember"></a>
|
||||||
### func \(\*Router\) OnMyChatMember
|
### func \(\*Router\) [OnMyChatMember](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L205>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnMyChatMember(h Handler[*api.ChatMemberUpdated])
|
func (r *Router) OnMyChatMember(h Handler[*api.ChatMemberUpdated])
|
||||||
@@ -503,7 +503,7 @@ func (r *Router) OnMyChatMember(h Handler[*api.ChatMemberUpdated])
|
|||||||
OnMyChatMember registers a handler for bot's own chat member status changes.
|
OnMyChatMember registers a handler for bot's own chat member status changes.
|
||||||
|
|
||||||
<a name="Router.OnMyChatMemberFilter"></a>
|
<a name="Router.OnMyChatMemberFilter"></a>
|
||||||
### func \(\*Router\) OnMyChatMemberFilter
|
### func \(\*Router\) [OnMyChatMemberFilter](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L210>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnMyChatMemberFilter(f Filter[*api.ChatMemberUpdated], h Handler[*api.ChatMemberUpdated])
|
func (r *Router) OnMyChatMemberFilter(f Filter[*api.ChatMemberUpdated], h Handler[*api.ChatMemberUpdated])
|
||||||
@@ -512,7 +512,7 @@ func (r *Router) OnMyChatMemberFilter(f Filter[*api.ChatMemberUpdated], h Handle
|
|||||||
OnMyChatMemberFilter registers a filtered handler for bot's own chat member status changes.
|
OnMyChatMemberFilter registers a filtered handler for bot's own chat member status changes.
|
||||||
|
|
||||||
<a name="Router.OnPoll"></a>
|
<a name="Router.OnPoll"></a>
|
||||||
### func \(\*Router\) OnPoll
|
### func \(\*Router\) [OnPoll](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L250>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnPoll(h Handler[*api.Poll])
|
func (r *Router) OnPoll(h Handler[*api.Poll])
|
||||||
@@ -521,7 +521,7 @@ func (r *Router) OnPoll(h Handler[*api.Poll])
|
|||||||
OnPoll registers a handler for poll state updates.
|
OnPoll registers a handler for poll state updates.
|
||||||
|
|
||||||
<a name="Router.OnPollAnswer"></a>
|
<a name="Router.OnPollAnswer"></a>
|
||||||
### func \(\*Router\) OnPollAnswer
|
### func \(\*Router\) [OnPollAnswer](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L255>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnPollAnswer(h Handler[*api.PollAnswer])
|
func (r *Router) OnPollAnswer(h Handler[*api.PollAnswer])
|
||||||
@@ -530,7 +530,7 @@ func (r *Router) OnPollAnswer(h Handler[*api.PollAnswer])
|
|||||||
OnPollAnswer registers a handler for poll answer updates.
|
OnPollAnswer registers a handler for poll answer updates.
|
||||||
|
|
||||||
<a name="Router.OnPreCheckoutQuery"></a>
|
<a name="Router.OnPreCheckoutQuery"></a>
|
||||||
### func \(\*Router\) OnPreCheckoutQuery
|
### func \(\*Router\) [OnPreCheckoutQuery](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L235>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnPreCheckoutQuery(h Handler[*api.PreCheckoutQuery])
|
func (r *Router) OnPreCheckoutQuery(h Handler[*api.PreCheckoutQuery])
|
||||||
@@ -539,7 +539,7 @@ func (r *Router) OnPreCheckoutQuery(h Handler[*api.PreCheckoutQuery])
|
|||||||
OnPreCheckoutQuery registers a handler for pre\-checkout queries.
|
OnPreCheckoutQuery registers a handler for pre\-checkout queries.
|
||||||
|
|
||||||
<a name="Router.OnPreCheckoutQueryFilter"></a>
|
<a name="Router.OnPreCheckoutQueryFilter"></a>
|
||||||
### func \(\*Router\) OnPreCheckoutQueryFilter
|
### func \(\*Router\) [OnPreCheckoutQueryFilter](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L240>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnPreCheckoutQueryFilter(f Filter[*api.PreCheckoutQuery], h Handler[*api.PreCheckoutQuery])
|
func (r *Router) OnPreCheckoutQueryFilter(f Filter[*api.PreCheckoutQuery], h Handler[*api.PreCheckoutQuery])
|
||||||
@@ -548,7 +548,7 @@ func (r *Router) OnPreCheckoutQueryFilter(f Filter[*api.PreCheckoutQuery], h Han
|
|||||||
OnPreCheckoutQueryFilter registers a filtered handler for pre\-checkout queries.
|
OnPreCheckoutQueryFilter registers a filtered handler for pre\-checkout queries.
|
||||||
|
|
||||||
<a name="Router.OnPurchasedPaidMedia"></a>
|
<a name="Router.OnPurchasedPaidMedia"></a>
|
||||||
### func \(\*Router\) OnPurchasedPaidMedia
|
### func \(\*Router\) [OnPurchasedPaidMedia](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L290>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnPurchasedPaidMedia(h Handler[*api.PaidMediaPurchased])
|
func (r *Router) OnPurchasedPaidMedia(h Handler[*api.PaidMediaPurchased])
|
||||||
@@ -557,7 +557,7 @@ func (r *Router) OnPurchasedPaidMedia(h Handler[*api.PaidMediaPurchased])
|
|||||||
OnPurchasedPaidMedia registers a handler for purchased paid media updates.
|
OnPurchasedPaidMedia registers a handler for purchased paid media updates.
|
||||||
|
|
||||||
<a name="Router.OnRemovedChatBoost"></a>
|
<a name="Router.OnRemovedChatBoost"></a>
|
||||||
### func \(\*Router\) OnRemovedChatBoost
|
### func \(\*Router\) [OnRemovedChatBoost](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L280>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnRemovedChatBoost(h Handler[*api.ChatBoostRemoved])
|
func (r *Router) OnRemovedChatBoost(h Handler[*api.ChatBoostRemoved])
|
||||||
@@ -566,7 +566,7 @@ func (r *Router) OnRemovedChatBoost(h Handler[*api.ChatBoostRemoved])
|
|||||||
OnRemovedChatBoost registers a handler for removed chat boost updates.
|
OnRemovedChatBoost registers a handler for removed chat boost updates.
|
||||||
|
|
||||||
<a name="Router.OnShippingQuery"></a>
|
<a name="Router.OnShippingQuery"></a>
|
||||||
### func \(\*Router\) OnShippingQuery
|
### func \(\*Router\) [OnShippingQuery](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L245>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnShippingQuery(h Handler[*api.ShippingQuery])
|
func (r *Router) OnShippingQuery(h Handler[*api.ShippingQuery])
|
||||||
@@ -575,7 +575,7 @@ func (r *Router) OnShippingQuery(h Handler[*api.ShippingQuery])
|
|||||||
OnShippingQuery registers a handler for shipping queries.
|
OnShippingQuery registers a handler for shipping queries.
|
||||||
|
|
||||||
<a name="Router.OnText"></a>
|
<a name="Router.OnText"></a>
|
||||||
### func \(\*Router\) OnText
|
### func \(\*Router\) [OnText](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L153>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) OnText(pattern string, h Handler[*api.Message])
|
func (r *Router) OnText(pattern string, h Handler[*api.Message])
|
||||||
@@ -586,7 +586,7 @@ OnText registers a handler for messages whose Text matches the regex.
|
|||||||
Panics at registration time if pattern is not a valid regular expression.
|
Panics at registration time if pattern is not a valid regular expression.
|
||||||
|
|
||||||
<a name="Router.Run"></a>
|
<a name="Router.Run"></a>
|
||||||
### func \(\*Router\) Run
|
### func \(\*Router\) [Run](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L303>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) Run(ctx context.Context, u transport.Updater) error
|
func (r *Router) Run(ctx context.Context, u transport.Updater) error
|
||||||
@@ -599,7 +599,7 @@ By default updates are processed concurrently \(up to WithMaxConcurrency\(50\) g
|
|||||||
Run waits for all in\-flight handlers to finish before returning.
|
Run waits for all in\-flight handlers to finish before returning.
|
||||||
|
|
||||||
<a name="Router.Use"></a>
|
<a name="Router.Use"></a>
|
||||||
### func \(\*Router\) Use
|
### func \(\*Router\) [Use](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L141>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (r *Router) Use(mw Middleware[*api.Update])
|
func (r *Router) Use(mw Middleware[*api.Update])
|
||||||
@@ -608,7 +608,7 @@ func (r *Router) Use(mw Middleware[*api.Update])
|
|||||||
Use registers a global middleware applied to every Update dispatch.
|
Use registers a global middleware applied to every Update dispatch.
|
||||||
|
|
||||||
<a name="RouterOption"></a>
|
<a name="RouterOption"></a>
|
||||||
## type RouterOption
|
## type [RouterOption](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L97>)
|
||||||
|
|
||||||
RouterOption configures a Router at construction time.
|
RouterOption configures a Router at construction time.
|
||||||
|
|
||||||
@@ -617,7 +617,7 @@ type RouterOption func(*Router)
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="WithMaxConcurrency"></a>
|
<a name="WithMaxConcurrency"></a>
|
||||||
### func WithMaxConcurrency
|
### func [WithMaxConcurrency](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/router.go#L106>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithMaxConcurrency(n int) RouterOption
|
func WithMaxConcurrency(n int) RouterOption
|
||||||
@@ -628,7 +628,7 @@ WithMaxConcurrency sets the maximum number of updates processed in parallel. Def
|
|||||||
Note: concurrent dispatch means handlers for different updates may run simultaneously. Handlers that mutate shared state must be safe for concurrent access.
|
Note: concurrent dispatch means handlers for different updates may run simultaneously. Handlers that mutate shared state must be safe for concurrent access.
|
||||||
|
|
||||||
<a name="RouterScope"></a>
|
<a name="RouterScope"></a>
|
||||||
## type RouterScope
|
## type [RouterScope](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/groups.go#L31-L34>)
|
||||||
|
|
||||||
RouterScope registers handlers into a specific priority group on its parent Router. Group 0 runs first, then group 1, etc. Within a group, handlers run in registration order; the first non\-skipped match terminates dispatch unless the handler returns ErrContinueGroups.
|
RouterScope registers handlers into a specific priority group on its parent Router. Group 0 runs first, then group 1, etc. Within a group, handlers run in registration order; the first non\-skipped match terminates dispatch unless the handler returns ErrContinueGroups.
|
||||||
|
|
||||||
@@ -639,7 +639,7 @@ type RouterScope struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="RouterScope.OnCommand"></a>
|
<a name="RouterScope.OnCommand"></a>
|
||||||
### func \(\*RouterScope\) OnCommand
|
### func \(\*RouterScope\) [OnCommand](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/groups.go#L45>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (s *RouterScope) OnCommand(cmd string, h Handler[*api.Message])
|
func (s *RouterScope) OnCommand(cmd string, h Handler[*api.Message])
|
||||||
@@ -648,7 +648,7 @@ func (s *RouterScope) OnCommand(cmd string, h Handler[*api.Message])
|
|||||||
OnCommand registers a command handler in this group.
|
OnCommand registers a command handler in this group.
|
||||||
|
|
||||||
<a name="RouterScope.OnMessageFilter"></a>
|
<a name="RouterScope.OnMessageFilter"></a>
|
||||||
### func \(\*RouterScope\) OnMessageFilter
|
### func \(\*RouterScope\) [OnMessageFilter](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/groups.go#L60>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (s *RouterScope) OnMessageFilter(f Filter[*api.Message], h Handler[*api.Message])
|
func (s *RouterScope) OnMessageFilter(f Filter[*api.Message], h Handler[*api.Message])
|
||||||
@@ -657,7 +657,7 @@ func (s *RouterScope) OnMessageFilter(f Filter[*api.Message], h Handler[*api.Mes
|
|||||||
OnMessageFilter registers a filter\-based message handler in this group.
|
OnMessageFilter registers a filter\-based message handler in this group.
|
||||||
|
|
||||||
<a name="RouterScope.OnText"></a>
|
<a name="RouterScope.OnText"></a>
|
||||||
### func \(\*RouterScope\) OnText
|
### func \(\*RouterScope\) [OnText](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/groups.go#L53>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (s *RouterScope) OnText(pattern string, h Handler[*api.Message])
|
func (s *RouterScope) OnText(pattern string, h Handler[*api.Message])
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ var ErrKeyNotFound = errors.New("conversation: key not found")
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="End"></a>
|
<a name="End"></a>
|
||||||
## func End
|
## func [End](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/handler.go#L34>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func End() error
|
func End() error
|
||||||
@@ -45,7 +45,7 @@ func End() error
|
|||||||
End signals the conversation has finished and state should be cleared. Conversation handlers return End\(\) to terminate.
|
End signals the conversation has finished and state should be cleared. Conversation handlers return End\(\) to terminate.
|
||||||
|
|
||||||
<a name="Next"></a>
|
<a name="Next"></a>
|
||||||
## func Next
|
## func [Next](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/handler.go#L28>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Next(s State) error
|
func Next(s State) error
|
||||||
@@ -54,7 +54,7 @@ func Next(s State) error
|
|||||||
Next signals the conversation should advance to the given state. Conversation handlers return Next\("state\_name"\) to transition.
|
Next signals the conversation should advance to the given state. Conversation handlers return Next\("state\_name"\) to transition.
|
||||||
|
|
||||||
<a name="Conversation"></a>
|
<a name="Conversation"></a>
|
||||||
## type Conversation
|
## type [Conversation](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/handler.go#L55-L79>)
|
||||||
|
|
||||||
Conversation is a stateful handler with entry, per\-state, exit and fallback steps. A conversation is keyed by KeyStrategy \(default KeyByUserAndChat\) and persisted by Storage \(default in\-memory\).
|
Conversation is a stateful handler with entry, per\-state, exit and fallback steps. A conversation is keyed by KeyStrategy \(default KeyByUserAndChat\) and persisted by Storage \(default in\-memory\).
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ type Conversation struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="Conversation.Dispatch"></a>
|
<a name="Conversation.Dispatch"></a>
|
||||||
### func \(\*Conversation\) Dispatch
|
### func \(\*Conversation\) [Dispatch](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/handler.go#L87>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (c *Conversation) Dispatch(next dispatch.Handler[*api.Update]) dispatch.Handler[*api.Update]
|
func (c *Conversation) Dispatch(next dispatch.Handler[*api.Update]) dispatch.Handler[*api.Update]
|
||||||
@@ -98,7 +98,7 @@ Dispatch is a global middleware\-shaped Handler that consumes updates and routes
|
|||||||
If the conversation claims an update, downstream handlers are skipped. If the conversation does not claim it, downstream handlers run as normal.
|
If the conversation claims an update, downstream handlers are skipped. If the conversation does not claim it, downstream handlers run as normal.
|
||||||
|
|
||||||
<a name="Handler"></a>
|
<a name="Handler"></a>
|
||||||
## type Handler
|
## type [Handler](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/handler.go#L44>)
|
||||||
|
|
||||||
Handler defines a step in the conversation. Receives the dispatch context and the raw update. Returns:
|
Handler defines a step in the conversation. Receives the dispatch context and the raw update. Returns:
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ type Handler func(ctx *dispatch.Context, u *api.Update) error
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="KeyStrategy"></a>
|
<a name="KeyStrategy"></a>
|
||||||
## type KeyStrategy
|
## type [KeyStrategy](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/key.go#L16>)
|
||||||
|
|
||||||
KeyStrategy derives a persistence key from an update. Strategies determine how conversation scope works — per\-user, per\-chat, or per\-user\-and\-chat. Implementations must return a stable string for the same logical scope across updates.
|
KeyStrategy derives a persistence key from an update. Strategies determine how conversation scope works — per\-user, per\-chat, or per\-user\-and\-chat. Implementations must return a stable string for the same logical scope across updates.
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ var KeyByUserAndChat KeyStrategy = func(u *api.Update) string {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="MemoryStorage"></a>
|
<a name="MemoryStorage"></a>
|
||||||
## type MemoryStorage
|
## type [MemoryStorage](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/in_memory.go#L11-L14>)
|
||||||
|
|
||||||
MemoryStorage is the default in\-process Storage. It is safe for concurrent use. Conversation state is lost on process restart; use a custom Storage backed by a database for persistent flows.
|
MemoryStorage is the default in\-process Storage. It is safe for concurrent use. Conversation state is lost on process restart; use a custom Storage backed by a database for persistent flows.
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ type MemoryStorage struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="NewMemoryStorage"></a>
|
<a name="NewMemoryStorage"></a>
|
||||||
### func NewMemoryStorage
|
### func [NewMemoryStorage](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/in_memory.go#L17>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func NewMemoryStorage() *MemoryStorage
|
func NewMemoryStorage() *MemoryStorage
|
||||||
@@ -178,7 +178,7 @@ func NewMemoryStorage() *MemoryStorage
|
|||||||
NewMemoryStorage constructs an empty in\-memory storage.
|
NewMemoryStorage constructs an empty in\-memory storage.
|
||||||
|
|
||||||
<a name="MemoryStorage.Delete"></a>
|
<a name="MemoryStorage.Delete"></a>
|
||||||
### func \(\*MemoryStorage\) Delete
|
### func \(\*MemoryStorage\) [Delete](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/in_memory.go#L38>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (s *MemoryStorage) Delete(_ context.Context, key string) error
|
func (s *MemoryStorage) Delete(_ context.Context, key string) error
|
||||||
@@ -187,7 +187,7 @@ func (s *MemoryStorage) Delete(_ context.Context, key string) error
|
|||||||
|
|
||||||
|
|
||||||
<a name="MemoryStorage.Get"></a>
|
<a name="MemoryStorage.Get"></a>
|
||||||
### func \(\*MemoryStorage\) Get
|
### func \(\*MemoryStorage\) [Get](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/in_memory.go#L21>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (s *MemoryStorage) Get(_ context.Context, key string) (State, error)
|
func (s *MemoryStorage) Get(_ context.Context, key string) (State, error)
|
||||||
@@ -196,7 +196,7 @@ func (s *MemoryStorage) Get(_ context.Context, key string) (State, error)
|
|||||||
|
|
||||||
|
|
||||||
<a name="MemoryStorage.Set"></a>
|
<a name="MemoryStorage.Set"></a>
|
||||||
### func \(\*MemoryStorage\) Set
|
### func \(\*MemoryStorage\) [Set](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/in_memory.go#L31>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (s *MemoryStorage) Set(_ context.Context, key string, state State) error
|
func (s *MemoryStorage) Set(_ context.Context, key string, state State) error
|
||||||
@@ -205,7 +205,7 @@ func (s *MemoryStorage) Set(_ context.Context, key string, state State) error
|
|||||||
|
|
||||||
|
|
||||||
<a name="State"></a>
|
<a name="State"></a>
|
||||||
## type State
|
## type [State](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/state.go#L9>)
|
||||||
|
|
||||||
State is a label identifying a node in the conversation graph. The empty string is the implicit "no active conversation" state.
|
State is a label identifying a node in the conversation graph. The empty string is the implicit "no active conversation" state.
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ type State string
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="Step"></a>
|
<a name="Step"></a>
|
||||||
## type Step
|
## type [Step](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/handler.go#L47-L50>)
|
||||||
|
|
||||||
Step pairs a filter with a handler for one conversation step.
|
Step pairs a filter with a handler for one conversation step.
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ type Step struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="Storage"></a>
|
<a name="Storage"></a>
|
||||||
## type Storage
|
## type [Storage](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/conversation/storage.go#L16-L20>)
|
||||||
|
|
||||||
Storage persists per\-user \(or per\-chat, per\-message — depending on the KeyStrategy in use\) conversation state across update deliveries.
|
Storage persists per\-user \(or per\-chat, per\-message — depending on the KeyStrategy in use\) conversation state across update deliveries.
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ Package callback provides Filter helpers for \*api.CallbackQuery payloads.
|
|||||||
|
|
||||||
|
|
||||||
<a name="Data"></a>
|
<a name="Data"></a>
|
||||||
## func Data
|
## func [Data](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/callback/callback.go#L14>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Data(pattern string) dispatch.Filter[*api.CallbackQuery]
|
func Data(pattern string) dispatch.Filter[*api.CallbackQuery]
|
||||||
@@ -26,7 +26,7 @@ func Data(pattern string) dispatch.Filter[*api.CallbackQuery]
|
|||||||
Data returns a Filter that matches callback queries whose Data matches pattern \(regex\). Panics at registration time on an invalid pattern.
|
Data returns a Filter that matches callback queries whose Data matches pattern \(regex\). Panics at registration time on an invalid pattern.
|
||||||
|
|
||||||
<a name="DataEquals"></a>
|
<a name="DataEquals"></a>
|
||||||
## func DataEquals
|
## func [DataEquals](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/callback/callback.go#L23>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func DataEquals(s string) dispatch.Filter[*api.CallbackQuery]
|
func DataEquals(s string) dispatch.Filter[*api.CallbackQuery]
|
||||||
@@ -35,7 +35,7 @@ func DataEquals(s string) dispatch.Filter[*api.CallbackQuery]
|
|||||||
DataEquals returns a Filter that matches callback queries whose Data equals s exactly.
|
DataEquals returns a Filter that matches callback queries whose Data equals s exactly.
|
||||||
|
|
||||||
<a name="DataPrefix"></a>
|
<a name="DataPrefix"></a>
|
||||||
## func DataPrefix
|
## func [DataPrefix](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/callback/callback.go#L31>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func DataPrefix(prefix string) dispatch.Filter[*api.CallbackQuery]
|
func DataPrefix(prefix string) dispatch.Filter[*api.CallbackQuery]
|
||||||
@@ -44,7 +44,7 @@ func DataPrefix(prefix string) dispatch.Filter[*api.CallbackQuery]
|
|||||||
DataPrefix returns a Filter that matches callback queries whose Data starts with prefix.
|
DataPrefix returns a Filter that matches callback queries whose Data starts with prefix.
|
||||||
|
|
||||||
<a name="FromUser"></a>
|
<a name="FromUser"></a>
|
||||||
## func FromUser
|
## func [FromUser](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/callback/callback.go#L39>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func FromUser(userID int64) dispatch.Filter[*api.CallbackQuery]
|
func FromUser(userID int64) dispatch.Filter[*api.CallbackQuery]
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Package chatjoinrequest provides Filter helpers for \*api.ChatJoinRequest payloa
|
|||||||
|
|
||||||
|
|
||||||
<a name="FromUser"></a>
|
<a name="FromUser"></a>
|
||||||
## func FromUser
|
## func [FromUser](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/chatjoinrequest/chatjoinrequest.go#L11>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func FromUser(uid int64) dispatch.Filter[*api.ChatJoinRequest]
|
func FromUser(uid int64) dispatch.Filter[*api.ChatJoinRequest]
|
||||||
@@ -24,7 +24,7 @@ func FromUser(uid int64) dispatch.Filter[*api.ChatJoinRequest]
|
|||||||
FromUser returns a Filter that matches join requests where the requesting user's ID equals uid.
|
FromUser returns a Filter that matches join requests where the requesting user's ID equals uid.
|
||||||
|
|
||||||
<a name="InChat"></a>
|
<a name="InChat"></a>
|
||||||
## func InChat
|
## func [InChat](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/chatjoinrequest/chatjoinrequest.go#L19>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func InChat(cid int64) dispatch.Filter[*api.ChatJoinRequest]
|
func InChat(cid int64) dispatch.Filter[*api.ChatJoinRequest]
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Package chatmember provides Filter helpers for \*api.ChatMemberUpdated payloads.
|
|||||||
|
|
||||||
|
|
||||||
<a name="FromUser"></a>
|
<a name="FromUser"></a>
|
||||||
## func FromUser
|
## func [FromUser](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/chatmember/chatmember.go#L37>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func FromUser(uid int64) dispatch.Filter[*api.ChatMemberUpdated]
|
func FromUser(uid int64) dispatch.Filter[*api.ChatMemberUpdated]
|
||||||
@@ -24,7 +24,7 @@ func FromUser(uid int64) dispatch.Filter[*api.ChatMemberUpdated]
|
|||||||
FromUser returns a Filter that matches updates where the acting user \(From.ID\) equals uid.
|
FromUser returns a Filter that matches updates where the acting user \(From.ID\) equals uid.
|
||||||
|
|
||||||
<a name="NewStatus"></a>
|
<a name="NewStatus"></a>
|
||||||
## func NewStatus
|
## func [NewStatus](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/chatmember/chatmember.go#L11>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func NewStatus(s string) dispatch.Filter[*api.ChatMemberUpdated]
|
func NewStatus(s string) dispatch.Filter[*api.ChatMemberUpdated]
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Package inline provides Filter helpers for \*api.InlineQuery payloads.
|
|||||||
|
|
||||||
|
|
||||||
<a name="Query"></a>
|
<a name="Query"></a>
|
||||||
## func Query
|
## func [Query](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/inline/inline.go#L14>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Query(pattern string) dispatch.Filter[*api.InlineQuery]
|
func Query(pattern string) dispatch.Filter[*api.InlineQuery]
|
||||||
@@ -25,7 +25,7 @@ func Query(pattern string) dispatch.Filter[*api.InlineQuery]
|
|||||||
Query returns a Filter that matches inline queries whose Query field matches pattern \(regex\). Panics at registration time on an invalid pattern.
|
Query returns a Filter that matches inline queries whose Query field matches pattern \(regex\). Panics at registration time on an invalid pattern.
|
||||||
|
|
||||||
<a name="QueryEquals"></a>
|
<a name="QueryEquals"></a>
|
||||||
## func QueryEquals
|
## func [QueryEquals](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/inline/inline.go#L23>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func QueryEquals(s string) dispatch.Filter[*api.InlineQuery]
|
func QueryEquals(s string) dispatch.Filter[*api.InlineQuery]
|
||||||
@@ -34,7 +34,7 @@ func QueryEquals(s string) dispatch.Filter[*api.InlineQuery]
|
|||||||
QueryEquals returns a Filter that matches inline queries whose Query equals s exactly.
|
QueryEquals returns a Filter that matches inline queries whose Query equals s exactly.
|
||||||
|
|
||||||
<a name="QueryPrefix"></a>
|
<a name="QueryPrefix"></a>
|
||||||
## func QueryPrefix
|
## func [QueryPrefix](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/inline/inline.go#L31>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func QueryPrefix(prefix string) dispatch.Filter[*api.InlineQuery]
|
func QueryPrefix(prefix string) dispatch.Filter[*api.InlineQuery]
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ Package message provides Filter helpers for \*api.Message payloads.
|
|||||||
|
|
||||||
|
|
||||||
<a name="AnyCommand"></a>
|
<a name="AnyCommand"></a>
|
||||||
## func AnyCommand
|
## func [AnyCommand](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L69>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func AnyCommand() dispatch.Filter[*api.Message]
|
func AnyCommand() dispatch.Filter[*api.Message]
|
||||||
@@ -36,7 +36,7 @@ func AnyCommand() dispatch.Filter[*api.Message]
|
|||||||
AnyCommand returns a Filter that matches any message starting with a bot\_command entity at offset 0.
|
AnyCommand returns a Filter that matches any message starting with a bot\_command entity at offset 0.
|
||||||
|
|
||||||
<a name="ChatType"></a>
|
<a name="ChatType"></a>
|
||||||
## func ChatType
|
## func [ChatType](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L124>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func ChatType(t api.ChatType) dispatch.Filter[*api.Message]
|
func ChatType(t api.ChatType) dispatch.Filter[*api.Message]
|
||||||
@@ -45,7 +45,7 @@ func ChatType(t api.ChatType) dispatch.Filter[*api.Message]
|
|||||||
ChatType returns a Filter that matches messages whose Chat.Type equals t.
|
ChatType returns a Filter that matches messages whose Chat.Type equals t.
|
||||||
|
|
||||||
<a name="Command"></a>
|
<a name="Command"></a>
|
||||||
## func Command
|
## func [Command](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L44>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Command(name string) dispatch.Filter[*api.Message]
|
func Command(name string) dispatch.Filter[*api.Message]
|
||||||
@@ -54,7 +54,7 @@ func Command(name string) dispatch.Filter[*api.Message]
|
|||||||
Command returns a Filter that matches messages whose first entity is a bot\_command equal to "/\<name\>" \(with or without "@BotName" suffix\).
|
Command returns a Filter that matches messages whose first entity is a bot\_command equal to "/\<name\>" \(with or without "@BotName" suffix\).
|
||||||
|
|
||||||
<a name="FromUser"></a>
|
<a name="FromUser"></a>
|
||||||
## func FromUser
|
## func [FromUser](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L131>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func FromUser(userID int64) dispatch.Filter[*api.Message]
|
func FromUser(userID int64) dispatch.Filter[*api.Message]
|
||||||
@@ -63,7 +63,7 @@ func FromUser(userID int64) dispatch.Filter[*api.Message]
|
|||||||
FromUser returns a Filter that matches messages whose From.ID equals userID.
|
FromUser returns a Filter that matches messages whose From.ID equals userID.
|
||||||
|
|
||||||
<a name="HasDocument"></a>
|
<a name="HasDocument"></a>
|
||||||
## func HasDocument
|
## func [HasDocument](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L101>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func HasDocument() dispatch.Filter[*api.Message]
|
func HasDocument() dispatch.Filter[*api.Message]
|
||||||
@@ -72,7 +72,7 @@ func HasDocument() dispatch.Filter[*api.Message]
|
|||||||
HasDocument returns a Filter that matches messages with a Document attachment.
|
HasDocument returns a Filter that matches messages with a Document attachment.
|
||||||
|
|
||||||
<a name="HasEntity"></a>
|
<a name="HasEntity"></a>
|
||||||
## func HasEntity
|
## func [HasEntity](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L109>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func HasEntity(t api.MessageEntityType) dispatch.Filter[*api.Message]
|
func HasEntity(t api.MessageEntityType) dispatch.Filter[*api.Message]
|
||||||
@@ -81,7 +81,7 @@ func HasEntity(t api.MessageEntityType) dispatch.Filter[*api.Message]
|
|||||||
HasEntity returns a Filter that matches messages whose Entities contain at least one entity of type t \(e.g. api.MessageEntityTypeBotCommand\).
|
HasEntity returns a Filter that matches messages whose Entities contain at least one entity of type t \(e.g. api.MessageEntityTypeBotCommand\).
|
||||||
|
|
||||||
<a name="HasPhoto"></a>
|
<a name="HasPhoto"></a>
|
||||||
## func HasPhoto
|
## func [HasPhoto](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L94>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func HasPhoto() dispatch.Filter[*api.Message]
|
func HasPhoto() dispatch.Filter[*api.Message]
|
||||||
@@ -90,7 +90,7 @@ func HasPhoto() dispatch.Filter[*api.Message]
|
|||||||
HasPhoto returns a Filter that matches messages with a Photo attachment.
|
HasPhoto returns a Filter that matches messages with a Photo attachment.
|
||||||
|
|
||||||
<a name="InChat"></a>
|
<a name="InChat"></a>
|
||||||
## func InChat
|
## func [InChat](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L138>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func InChat(chatID int64) dispatch.Filter[*api.Message]
|
func InChat(chatID int64) dispatch.Filter[*api.Message]
|
||||||
@@ -99,7 +99,7 @@ func InChat(chatID int64) dispatch.Filter[*api.Message]
|
|||||||
InChat returns a Filter that matches messages whose Chat.ID equals chatID.
|
InChat returns a Filter that matches messages whose Chat.ID equals chatID.
|
||||||
|
|
||||||
<a name="IsForward"></a>
|
<a name="IsForward"></a>
|
||||||
## func IsForward
|
## func [IsForward](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L87>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func IsForward() dispatch.Filter[*api.Message]
|
func IsForward() dispatch.Filter[*api.Message]
|
||||||
@@ -108,7 +108,7 @@ func IsForward() dispatch.Filter[*api.Message]
|
|||||||
IsForward returns a Filter that matches messages that have ForwardOrigin set.
|
IsForward returns a Filter that matches messages that have ForwardOrigin set.
|
||||||
|
|
||||||
<a name="IsReply"></a>
|
<a name="IsReply"></a>
|
||||||
## func IsReply
|
## func [IsReply](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L80>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func IsReply() dispatch.Filter[*api.Message]
|
func IsReply() dispatch.Filter[*api.Message]
|
||||||
@@ -117,7 +117,7 @@ func IsReply() dispatch.Filter[*api.Message]
|
|||||||
IsReply returns a Filter that matches messages that have ReplyToMessage set.
|
IsReply returns a Filter that matches messages that have ReplyToMessage set.
|
||||||
|
|
||||||
<a name="Text"></a>
|
<a name="Text"></a>
|
||||||
## func Text
|
## func [Text](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L14>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Text(pattern string) dispatch.Filter[*api.Message]
|
func Text(pattern string) dispatch.Filter[*api.Message]
|
||||||
@@ -126,7 +126,7 @@ func Text(pattern string) dispatch.Filter[*api.Message]
|
|||||||
Text returns a Filter that matches messages whose Text matches pattern \(regex\). Panics at registration time on an invalid pattern.
|
Text returns a Filter that matches messages whose Text matches pattern \(regex\). Panics at registration time on an invalid pattern.
|
||||||
|
|
||||||
<a name="TextContains"></a>
|
<a name="TextContains"></a>
|
||||||
## func TextContains
|
## func [TextContains](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L36>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func TextContains(sub string) dispatch.Filter[*api.Message]
|
func TextContains(sub string) dispatch.Filter[*api.Message]
|
||||||
@@ -135,7 +135,7 @@ func TextContains(sub string) dispatch.Filter[*api.Message]
|
|||||||
TextContains returns a Filter that matches messages whose Text contains sub.
|
TextContains returns a Filter that matches messages whose Text contains sub.
|
||||||
|
|
||||||
<a name="TextEquals"></a>
|
<a name="TextEquals"></a>
|
||||||
## func TextEquals
|
## func [TextEquals](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L22>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func TextEquals(s string) dispatch.Filter[*api.Message]
|
func TextEquals(s string) dispatch.Filter[*api.Message]
|
||||||
@@ -144,7 +144,7 @@ func TextEquals(s string) dispatch.Filter[*api.Message]
|
|||||||
TextEquals returns a Filter that matches messages whose Text equals s exactly.
|
TextEquals returns a Filter that matches messages whose Text equals s exactly.
|
||||||
|
|
||||||
<a name="TextPrefix"></a>
|
<a name="TextPrefix"></a>
|
||||||
## func TextPrefix
|
## func [TextPrefix](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/message/message.go#L29>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func TextPrefix(prefix string) dispatch.Filter[*api.Message]
|
func TextPrefix(prefix string) dispatch.Filter[*api.Message]
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Package precheckoutquery provides Filter helpers for \*api.PreCheckoutQuery payl
|
|||||||
|
|
||||||
|
|
||||||
<a name="Currency"></a>
|
<a name="Currency"></a>
|
||||||
## func Currency
|
## func [Currency](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/precheckoutquery/precheckoutquery.go#L11>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Currency(c string) dispatch.Filter[*api.PreCheckoutQuery]
|
func Currency(c string) dispatch.Filter[*api.PreCheckoutQuery]
|
||||||
@@ -24,7 +24,7 @@ func Currency(c string) dispatch.Filter[*api.PreCheckoutQuery]
|
|||||||
Currency returns a Filter that matches pre\-checkout queries with the given ISO 4217 currency code \(e.g. "USD", "EUR", "XTR"\).
|
Currency returns a Filter that matches pre\-checkout queries with the given ISO 4217 currency code \(e.g. "USD", "EUR", "XTR"\).
|
||||||
|
|
||||||
<a name="FromUser"></a>
|
<a name="FromUser"></a>
|
||||||
## func FromUser
|
## func [FromUser](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filters/precheckoutquery/precheckoutquery.go#L19>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func FromUser(uid int64) dispatch.Filter[*api.PreCheckoutQuery]
|
func FromUser(uid int64) dispatch.Filter[*api.PreCheckoutQuery]
|
||||||
|
|||||||
+19
-19
@@ -34,7 +34,7 @@ All implementations satisfy the Updater interface so user code can swap one for
|
|||||||
|
|
||||||
|
|
||||||
<a name="BackoffStrategy"></a>
|
<a name="BackoffStrategy"></a>
|
||||||
## type BackoffStrategy
|
## type [BackoffStrategy](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/backoff.go#L12-L14>)
|
||||||
|
|
||||||
BackoffStrategy returns the duration to wait before the next attempt after \`attempt\` consecutive failures \(1\-based\). Implementations must be safe to call from a single goroutine.
|
BackoffStrategy returns the duration to wait before the next attempt after \`attempt\` consecutive failures \(1\-based\). Implementations must be safe to call from a single goroutine.
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ type BackoffStrategy interface {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="ExponentialBackoff"></a>
|
<a name="ExponentialBackoff"></a>
|
||||||
## type ExponentialBackoff
|
## type [ExponentialBackoff](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/backoff.go#L18-L23>)
|
||||||
|
|
||||||
ExponentialBackoff implements capped exponential back\-off with jitter. Defaults: Base=500ms, Max=30s, Factor=2.0, Jitter=0.2.
|
ExponentialBackoff implements capped exponential back\-off with jitter. Defaults: Base=500ms, Max=30s, Factor=2.0, Jitter=0.2.
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ type ExponentialBackoff struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="DefaultBackoff"></a>
|
<a name="DefaultBackoff"></a>
|
||||||
### func DefaultBackoff
|
### func [DefaultBackoff](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/backoff.go#L26>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func DefaultBackoff() *ExponentialBackoff
|
func DefaultBackoff() *ExponentialBackoff
|
||||||
@@ -68,7 +68,7 @@ func DefaultBackoff() *ExponentialBackoff
|
|||||||
DefaultBackoff returns an ExponentialBackoff with library defaults.
|
DefaultBackoff returns an ExponentialBackoff with library defaults.
|
||||||
|
|
||||||
<a name="ExponentialBackoff.NextDelay"></a>
|
<a name="ExponentialBackoff.NextDelay"></a>
|
||||||
### func \(\*ExponentialBackoff\) NextDelay
|
### func \(\*ExponentialBackoff\) [NextDelay](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/backoff.go#L36>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (b *ExponentialBackoff) NextDelay(attempt int) time.Duration
|
func (b *ExponentialBackoff) NextDelay(attempt int) time.Duration
|
||||||
@@ -77,7 +77,7 @@ func (b *ExponentialBackoff) NextDelay(attempt int) time.Duration
|
|||||||
NextDelay implements BackoffStrategy.
|
NextDelay implements BackoffStrategy.
|
||||||
|
|
||||||
<a name="LongPoller"></a>
|
<a name="LongPoller"></a>
|
||||||
## type LongPoller
|
## type [LongPoller](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/longpoll.go#L21-L31>)
|
||||||
|
|
||||||
LongPoller pulls updates via Bot.GetUpdates in a loop, advancing the offset cursor after each batch. It applies BackoffStrategy on transient errors \(network failures, 5xx, 429\).
|
LongPoller pulls updates via Bot.GetUpdates in a loop, advancing the offset cursor after each batch. It applies BackoffStrategy on transient errors \(network failures, 5xx, 429\).
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ type LongPoller struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="NewLongPoller"></a>
|
<a name="NewLongPoller"></a>
|
||||||
### func NewLongPoller
|
### func [NewLongPoller](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/longpoll.go#L34>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func NewLongPoller(b *client.Bot) *LongPoller
|
func NewLongPoller(b *client.Bot) *LongPoller
|
||||||
@@ -104,7 +104,7 @@ func NewLongPoller(b *client.Bot) *LongPoller
|
|||||||
NewLongPoller constructs a LongPoller with sensible defaults.
|
NewLongPoller constructs a LongPoller with sensible defaults.
|
||||||
|
|
||||||
<a name="LongPoller.Run"></a>
|
<a name="LongPoller.Run"></a>
|
||||||
### func \(\*LongPoller\) Run
|
### func \(\*LongPoller\) [Run](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/longpoll.go#L51>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (p *LongPoller) Run(ctx context.Context) error
|
func (p *LongPoller) Run(ctx context.Context) error
|
||||||
@@ -113,7 +113,7 @@ func (p *LongPoller) Run(ctx context.Context) error
|
|||||||
Run implements Updater. It blocks until ctx is cancelled, Stop is called, or a fatal error occurs \(e.g. unauthorized\). See LongPoller for at\-least\-once delivery semantics on shutdown.
|
Run implements Updater. It blocks until ctx is cancelled, Stop is called, or a fatal error occurs \(e.g. unauthorized\). See LongPoller for at\-least\-once delivery semantics on shutdown.
|
||||||
|
|
||||||
<a name="LongPoller.Stop"></a>
|
<a name="LongPoller.Stop"></a>
|
||||||
### func \(\*LongPoller\) Stop
|
### func \(\*LongPoller\) [Stop](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/longpoll.go#L126>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (p *LongPoller) Stop(ctx context.Context) error
|
func (p *LongPoller) Stop(ctx context.Context) error
|
||||||
@@ -122,7 +122,7 @@ func (p *LongPoller) Stop(ctx context.Context) error
|
|||||||
Stop implements Updater.
|
Stop implements Updater.
|
||||||
|
|
||||||
<a name="LongPoller.Updates"></a>
|
<a name="LongPoller.Updates"></a>
|
||||||
### func \(\*LongPoller\) Updates
|
### func \(\*LongPoller\) [Updates](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/longpoll.go#L46>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (p *LongPoller) Updates() <-chan api.Update
|
func (p *LongPoller) Updates() <-chan api.Update
|
||||||
@@ -131,7 +131,7 @@ func (p *LongPoller) Updates() <-chan api.Update
|
|||||||
Updates implements Updater.
|
Updates implements Updater.
|
||||||
|
|
||||||
<a name="Updater"></a>
|
<a name="Updater"></a>
|
||||||
## type Updater
|
## type [Updater](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/updater.go#L13-L23>)
|
||||||
|
|
||||||
Updater is the abstraction over update sources. Implementations must:
|
Updater is the abstraction over update sources. Implementations must:
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ type Updater interface {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="WebhookOption"></a>
|
<a name="WebhookOption"></a>
|
||||||
## type WebhookOption
|
## type [WebhookOption](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L38>)
|
||||||
|
|
||||||
WebhookOption configures a WebhookServer at construction time.
|
WebhookOption configures a WebhookServer at construction time.
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ type WebhookOption func(*webhookOptions)
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="WithBufferSize"></a>
|
<a name="WithBufferSize"></a>
|
||||||
### func WithBufferSize
|
### func [WithBufferSize](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L46>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithBufferSize(n int) WebhookOption
|
func WithBufferSize(n int) WebhookOption
|
||||||
@@ -172,7 +172,7 @@ func WithBufferSize(n int) WebhookOption
|
|||||||
WithBufferSize sets the size of the updates channel buffer. Default is 64.
|
WithBufferSize sets the size of the updates channel buffer. Default is 64.
|
||||||
|
|
||||||
<a name="WebhookServer"></a>
|
<a name="WebhookServer"></a>
|
||||||
## type WebhookServer
|
## type [WebhookServer](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L24-L35>)
|
||||||
|
|
||||||
WebhookServer implements Updater by exposing an http.Handler that receives updates from Telegram. It can be mounted on the user's own HTTP server \(via ServeHTTP\) or run standalone \(via ListenAndServe\).
|
WebhookServer implements Updater by exposing an http.Handler that receives updates from Telegram. It can be mounted on the user's own HTTP server \(via ServeHTTP\) or run standalone \(via ListenAndServe\).
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ type WebhookServer struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="NewWebhookServer"></a>
|
<a name="NewWebhookServer"></a>
|
||||||
### func NewWebhookServer
|
### func [NewWebhookServer](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L52>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func NewWebhookServer(b *client.Bot, opts ...WebhookOption) *WebhookServer
|
func NewWebhookServer(b *client.Bot, opts ...WebhookOption) *WebhookServer
|
||||||
@@ -194,7 +194,7 @@ func NewWebhookServer(b *client.Bot, opts ...WebhookOption) *WebhookServer
|
|||||||
NewWebhookServer constructs a WebhookServer with default buffer size \(64\). Use WithBufferSize to override.
|
NewWebhookServer constructs a WebhookServer with default buffer size \(64\). Use WithBufferSize to override.
|
||||||
|
|
||||||
<a name="WebhookServer.ListenAndServe"></a>
|
<a name="WebhookServer.ListenAndServe"></a>
|
||||||
### func \(\*WebhookServer\) ListenAndServe
|
### func \(\*WebhookServer\) [ListenAndServe](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L150>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (w *WebhookServer) ListenAndServe(ctx context.Context, addr string) error
|
func (w *WebhookServer) ListenAndServe(ctx context.Context, addr string) error
|
||||||
@@ -203,7 +203,7 @@ func (w *WebhookServer) ListenAndServe(ctx context.Context, addr string) error
|
|||||||
ListenAndServe starts an HTTP server on addr and blocks until Stop is called \(which triggers Shutdown with the caller's context\) or the server returns an error other than http.ErrServerClosed. Callers must invoke Stop\(ctx\) to cleanly shut down the server; the ctx passed here is only used as the server's base context for incoming requests.
|
ListenAndServe starts an HTTP server on addr and blocks until Stop is called \(which triggers Shutdown with the caller's context\) or the server returns an error other than http.ErrServerClosed. Callers must invoke Stop\(ctx\) to cleanly shut down the server; the ctx passed here is only used as the server's base context for incoming requests.
|
||||||
|
|
||||||
<a name="WebhookServer.Run"></a>
|
<a name="WebhookServer.Run"></a>
|
||||||
### func \(\*WebhookServer\) Run
|
### func \(\*WebhookServer\) [Run](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L71>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (w *WebhookServer) Run(ctx context.Context) error
|
func (w *WebhookServer) Run(ctx context.Context) error
|
||||||
@@ -212,7 +212,7 @@ func (w *WebhookServer) Run(ctx context.Context) error
|
|||||||
Run implements Updater. It blocks until Stop is called or ctx is cancelled. If the server has not been started via ListenAndServe, Run only watches for shutdown — the user is expected to mount ServeHTTP on their own router.
|
Run implements Updater. It blocks until Stop is called or ctx is cancelled. If the server has not been started via ListenAndServe, Run only watches for shutdown — the user is expected to mount ServeHTTP on their own router.
|
||||||
|
|
||||||
<a name="WebhookServer.ServeHTTP"></a>
|
<a name="WebhookServer.ServeHTTP"></a>
|
||||||
### func \(\*WebhookServer\) ServeHTTP
|
### func \(\*WebhookServer\) [ServeHTTP](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L97>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (w *WebhookServer) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
func (w *WebhookServer) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
||||||
@@ -221,7 +221,7 @@ func (w *WebhookServer) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
ServeHTTP implements http.Handler. Telegram POSTs each update as JSON to this endpoint. Non\-POST requests get 405; bad bodies get 400; secret token mismatches get 401.
|
ServeHTTP implements http.Handler. Telegram POSTs each update as JSON to this endpoint. Non\-POST requests get 405; bad bodies get 400; secret token mismatches get 401.
|
||||||
|
|
||||||
<a name="WebhookServer.Stop"></a>
|
<a name="WebhookServer.Stop"></a>
|
||||||
### func \(\*WebhookServer\) Stop
|
### func \(\*WebhookServer\) [Stop](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L83>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (w *WebhookServer) Stop(ctx context.Context) error
|
func (w *WebhookServer) Stop(ctx context.Context) error
|
||||||
@@ -230,7 +230,7 @@ func (w *WebhookServer) Stop(ctx context.Context) error
|
|||||||
Stop implements Updater.
|
Stop implements Updater.
|
||||||
|
|
||||||
<a name="WebhookServer.Updates"></a>
|
<a name="WebhookServer.Updates"></a>
|
||||||
### func \(\*WebhookServer\) Updates
|
### func \(\*WebhookServer\) [Updates](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L65>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (w *WebhookServer) Updates() <-chan api.Update
|
func (w *WebhookServer) Updates() <-chan api.Update
|
||||||
|
|||||||
Reference in New Issue
Block a user