mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-06-10 23:09:04 +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 chatjoinrequest provides Filter helpers for *api.ChatJoinRequest payloads.
|
||||
package chatjoinrequest
|
||||
|
||||
import (
|
||||
"github.com/lukaszraczylo/go-telegram/api"
|
||||
"github.com/lukaszraczylo/go-telegram/dispatch"
|
||||
)
|
||||
|
||||
// FromUser returns a Filter that matches join requests where the requesting
|
||||
// user's ID equals uid.
|
||||
func FromUser(uid int64) dispatch.Filter[*api.ChatJoinRequest] {
|
||||
return func(r *api.ChatJoinRequest) bool {
|
||||
return r != nil && r.From.ID == uid
|
||||
}
|
||||
}
|
||||
|
||||
// InChat returns a Filter that matches join requests directed at the chat
|
||||
// with the given chat ID.
|
||||
func InChat(cid int64) dispatch.Filter[*api.ChatJoinRequest] {
|
||||
return func(r *api.ChatJoinRequest) bool {
|
||||
return r != nil && r.Chat.ID == cid
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package chatjoinrequest_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/lukaszraczylo/go-telegram/api"
|
||||
cjrfilter "github.com/lukaszraczylo/go-telegram/dispatch/filters/chatjoinrequest"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func joinRequest(fromID, chatID int64) *api.ChatJoinRequest {
|
||||
return &api.ChatJoinRequest{
|
||||
Chat: api.Chat{ID: chatID},
|
||||
From: api.User{ID: fromID},
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromUser_Matches(t *testing.T) {
|
||||
f := cjrfilter.FromUser(10)
|
||||
require.True(t, f(joinRequest(10, 100)))
|
||||
require.False(t, f(joinRequest(99, 100)))
|
||||
require.False(t, f(nil))
|
||||
}
|
||||
|
||||
func TestInChat_Matches(t *testing.T) {
|
||||
f := cjrfilter.InChat(100)
|
||||
require.True(t, f(joinRequest(10, 100)))
|
||||
require.False(t, f(joinRequest(10, 200)))
|
||||
require.False(t, f(nil))
|
||||
}
|
||||
|
||||
func TestComposedFilters(t *testing.T) {
|
||||
f := cjrfilter.FromUser(10).And(cjrfilter.InChat(100))
|
||||
require.True(t, f(joinRequest(10, 100)))
|
||||
require.False(t, f(joinRequest(10, 200)))
|
||||
require.False(t, f(joinRequest(99, 100)))
|
||||
}
|
||||
Reference in New Issue
Block a user