mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-06-14 03:02:13 +00:00
Initial release of go-telegram
A fully-generated, strongly-typed Go client for the Telegram Bot API. * 176 methods + 301 types generated from Bot API v10.0 * 1408 auto-generated tests (8 scenarios per method) * Typed unions throughout — no 'any' in the public surface * Pluggable HTTP transport and JSON codec (default goccy/go-json) * Built-in retry middleware honouring Telegram's retry_after * Generic dispatcher with filters and conversation handlers * Self-verifying codegen pipeline (regen → audit → emit → run tests) * 14 example bots covering common patterns
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// Package precheckoutquery provides Filter helpers for *api.PreCheckoutQuery payloads.
|
||||
package precheckoutquery
|
||||
|
||||
import (
|
||||
"github.com/lukaszraczylo/go-telegram/api"
|
||||
"github.com/lukaszraczylo/go-telegram/dispatch"
|
||||
)
|
||||
|
||||
// Currency returns a Filter that matches pre-checkout queries with the given
|
||||
// ISO 4217 currency code (e.g. "USD", "EUR", "XTR").
|
||||
func Currency(c string) dispatch.Filter[*api.PreCheckoutQuery] {
|
||||
return func(q *api.PreCheckoutQuery) bool {
|
||||
return q != nil && q.Currency == c
|
||||
}
|
||||
}
|
||||
|
||||
// FromUser returns a Filter that matches pre-checkout queries sent by the
|
||||
// user with the given ID.
|
||||
func FromUser(uid int64) dispatch.Filter[*api.PreCheckoutQuery] {
|
||||
return func(q *api.PreCheckoutQuery) bool {
|
||||
return q != nil && q.From.ID == uid
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package precheckoutquery_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/lukaszraczylo/go-telegram/api"
|
||||
pcqfilter "github.com/lukaszraczylo/go-telegram/dispatch/filters/precheckoutquery"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func pcq(currency string, fromID int64) *api.PreCheckoutQuery {
|
||||
return &api.PreCheckoutQuery{
|
||||
ID: "q",
|
||||
Currency: currency,
|
||||
From: api.User{ID: fromID},
|
||||
}
|
||||
}
|
||||
|
||||
func TestCurrency_Matches(t *testing.T) {
|
||||
f := pcqfilter.Currency("USD")
|
||||
require.True(t, f(pcq("USD", 1)))
|
||||
require.False(t, f(pcq("EUR", 1)))
|
||||
require.False(t, f(nil))
|
||||
}
|
||||
|
||||
func TestFromUser_Matches(t *testing.T) {
|
||||
f := pcqfilter.FromUser(5)
|
||||
require.True(t, f(pcq("USD", 5)))
|
||||
require.False(t, f(pcq("USD", 9)))
|
||||
require.False(t, f(nil))
|
||||
}
|
||||
|
||||
func TestComposedFilters(t *testing.T) {
|
||||
f := pcqfilter.Currency("XTR").And(pcqfilter.FromUser(42))
|
||||
require.True(t, f(pcq("XTR", 42)))
|
||||
require.False(t, f(pcq("XTR", 99)))
|
||||
require.False(t, f(pcq("USD", 42)))
|
||||
}
|
||||
Reference in New Issue
Block a user