Documentation
¶
Overview ¶
Package waitnew finds incoming messages newer than a per-chat watermark. One Poll is one connection's worth of work; the caller loops, sleeps and releases the Telegram lock between polls.
Index ¶
- Constants
- func Init(ctx context.Context, t tgclient.Telegram, f Filter, since time.Time) (*State, *Result, error)
- func Poll(ctx context.Context, t tgclient.Telegram, st *State, f Filter) (*State, *Result, error)
- func Prepare(path string, st *State, now time.Time) (commit func() error, err error)
- func Save(path string, st *State, now time.Time) error
- type Filter
- type Result
- type State
Constants ¶
View Source
const (
// PerChat caps messages returned per chat per poll (the newest ones).
PerChat = 100
)
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(ctx context.Context, t tgclient.Telegram, f Filter, since time.Time) (*State, *Result, error)
Init builds the watermark from every dialog. With since set it also returns the wanted messages newer than since.
func Poll ¶
Poll returns the wanted incoming messages past the watermark and the advanced state. Only chats whose top message moved are fetched; st is not modified.
Types ¶
type Filter ¶
type Filter struct {
Chats map[int64]bool // empty: every chat
DMs bool // 1:1 chats (people and bots)
Groups bool // groups, supergroups, forums
Mentions bool // group messages only when they mention or reply to you
}
Filter selects chats and messages.
type Result ¶
type Result struct {
Messages []tgclient.Message
Truncated []int64 // chats with more than PerChat new messages
}
Result is one poll's (or the first run's) output.
type State ¶
type State struct {
Version int `json:"version"`
Chats map[int64]int `json:"chats"` // chat id → highest message id seen
// Newest is the newest top-message date seen (server clock); dialogs older
// than it (minus slack) cannot hold new messages, so the scan stops there.
Newest time.Time `json:"newest,omitzero"`
Updated time.Time `json:"updated,omitzero"`
}
State is the watermark file.
Click to show internal directories.
Click to hide internal directories.