store

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	AccountPairing      = "pairing"
	AccountConnected    = "connected"
	AccountDisconnected = "disconnected"
	AccountLoggedOut    = "logged_out"
)
View Source
const (
	ChatDirect = "direct"
	ChatGroup  = "group"
)
View Source
const (
	DeliveryOpen      = "open"
	DeliveryRetrying  = "retrying"
	DeliveryDelivered = "delivered"
	DeliveryFailed    = "failed"
)
View Source
const (
	EventMessageReceived = "message.received"
	EventAccountState    = "account.state"
)
View Source
const (
	GrantStatic = "static"
	GrantOAuth  = "oauth"
)
View Source
const (
	ApprovalElicitation = "elicitation"
	ApprovalApp         = "app"
)
View Source
const (
	MediaPending     = "pending"
	MediaDownloaded  = "downloaded"
	MediaFailed      = "failed"
	MediaUnavailable = "unavailable"
)
View Source
const (
	MessageImage    = "image"
	MessageVideo    = "video"
	MessageAudio    = "audio"
	MessageDocument = "document"
	MessageSticker  = "sticker"
	MessageLocation = "location"
	MessageContact  = "contact"
	MessagePoll     = "poll"
)
View Source
const (
	TokenStatic  = "static"
	TokenAccess  = "access"
	TokenRefresh = "refresh"
)
View Source
const MessageText = "text"
View Source
const RetentionBatch = 1000

Variables

View Source
var (
	ErrNotFound       = errors.New("not found")
	ErrNameInUse      = errors.New("name in use")
	ErrUnknownAccount = errors.New("unknown account")
)

Functions

func ValidApproval

func ValidApproval(mode string) bool

Types

type Account

type Account struct {
	ID              int64
	Name            string
	JID             string
	Phone           string
	ProfileName     string
	Description     string
	RetentionMonths int
	State           string
	CreatedAt       time.Time
}

type AttemptFailure added in v0.2.0

type AttemptFailure struct {
	Status int
	Error  string
}

func (AttemptFailure) Known added in v0.2.0

func (f AttemptFailure) Known() bool

type AttemptOutcome added in v0.2.0

type AttemptOutcome struct {
	State           string
	DueAt           time.Time
	Status          int
	Error           string
	SettledAt       time.Time
	DisablesWebhook bool
}

type AuthCode

type AuthCode struct {
	Hash          string
	ClientID      string
	GrantName     string
	AccountNames  []string
	CodeChallenge string
	RedirectURI   string
	ExpiresAt     time.Time
	CreatedAt     time.Time
}

type Bearer

type Bearer struct {
	Grant     Grant
	ExpiresAt time.Time
}

type Chat

type Chat struct {
	JID           string
	Kind          string
	Name          string
	LastMessageAt time.Time
	UnreadCount   int
}

type ChatCursor

type ChatCursor struct {
	LastMessageAt time.Time
	JID           string
}

type ChatQuery

type ChatQuery struct {
	UnreadOnly bool
	Match      func(Chat) bool
	After      *ChatCursor
	Limit      int
}

type ContactCard

type ContactCard struct {
	Name  string `json:"name"`
	VCard string `json:"vcard"`
}

type Delivery added in v0.2.0

type Delivery struct {
	ID               int64
	WebhookID        int64
	AccountID        int64
	ChatJID          string
	FirstSeq         int64
	LastSeq          int64
	EventCount       int
	State            string
	OpenedAt         time.Time
	DueAt            time.Time
	Attempts         int
	RecordedAttempts int
	LastStatus       int
	LastError        string
	SettledAt        time.Time
}

type DeliverySummary added in v0.2.0

type DeliverySummary struct {
	Pending     int
	Failed      int
	LastSuccess time.Time
	LastFailure AttemptFailure
}

type Details

type Details struct {
	Poll     *Poll         `json:"poll,omitempty"`
	Location *Location     `json:"location,omitempty"`
	Contacts []ContactCard `json:"contacts,omitempty"`
}

type Event added in v0.2.0

type Event struct {
	Seq       int64
	AccountID int64
	Kind      string
	ChatJID   string
	MessageID string
	State     string
	CreatedAt time.Time
}

type ExpiredBatch

type ExpiredBatch struct {
	Messages int
	Files    int
}

type Grant

type Grant struct {
	ID        int64
	ClientID  string
	Name      string
	Kind      string
	ReadOnly  bool
	Approval  string
	CreatedAt time.Time
	RevokedAt time.Time
}

func (Grant) Revoked

func (g Grant) Revoked() bool

func (Grant) TrustsApp

func (g Grant) TrustsApp() bool

type GrantChange

type GrantChange struct {
	Name                string
	ChangeAccounts      bool
	AllExistingAccounts bool
	AccountNames        []string
	Approval            string
}

type Location

type Location struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
	Name      string  `json:"name,omitempty"`
	Address   string  `json:"address,omitempty"`
	URL       string  `json:"url,omitempty"`
	Live      bool    `json:"live,omitempty"`
}

type Media

type Media struct {
	Mime          string
	FileName      string
	Size          int64
	Seconds       int
	VoiceNote     bool
	MediaKey      []byte
	DirectPath    string
	FileSHA256    []byte
	FileEncSHA256 []byte
	State         string
	Path          string
}

type MediaFailure

type MediaFailure struct {
	State    string
	Attempts int
	Error    string
	RetryAt  time.Time
}

type MediaFile

type MediaFile struct {
	MediaRef
	Kind     string
	Media    Media
	SentAt   time.Time
	Path     string
	Attempts int
	Error    string
	RetryAt  time.Time
}

type MediaRef

type MediaRef struct {
	AccountID int64
	ChatJID   string
	MessageID string
}

type Message

type Message struct {
	ChatJID    string
	ID         string
	SenderJID  string
	SenderName string
	FromMe     bool
	SentAt     time.Time
	Kind       string
	Text       string
	QuotedID   string
	EditedAt   time.Time
	RevokedAt  time.Time
	Media      *Media
	Details    *Details
	Reactions  []Reaction
}

type MessageBound

type MessageBound struct {
	SentAt time.Time
	ID     string
}

type MessageQuery

type MessageQuery struct {
	Before *MessageBound
	After  *MessageBound
	Limit  int
}

type NewAccount

type NewAccount struct {
	Name        string
	Phone       string
	Description string
	CreatedAt   time.Time
}

type NewGrant

type NewGrant struct {
	ClientID            string
	Name                string
	Kind                string
	ReadOnly            bool
	Approval            string
	AllExistingAccounts bool
	AccountNames        []string
	CreatedAt           time.Time
	Tokens              []Token
}

type NewWebhook added in v0.2.0

type NewWebhook struct {
	Name                string
	URL                 string
	Format              string
	Content             string
	Events              []string
	Chats               string
	Quiet               time.Duration
	MaxWait             time.Duration
	Secret              string
	Headers             map[string]string
	AllExistingAccounts bool
	AccountNames        []string
	ListedChats         func(accountID int64) []string
	CreatedAt           time.Time
}

type OAuthClient

type OAuthClient struct {
	ID           string
	Name         string
	RedirectURIs []string
	AuthMethod   string
	SecretHash   string
	CreatedAt    time.Time
}

type PhoneInUseError

type PhoneInUseError struct {
	Phone   string
	Account string
}

func (*PhoneInUseError) Error

func (e *PhoneInUseError) Error() string

type Placement added in v0.2.0

type Placement struct {
	Join  bool
	DueAt time.Time
}

type Poll

type Poll struct {
	Options    []string `json:"options"`
	MaxChoices int      `json:"max_choices"`
}

type Queue added in v0.2.0

type Queue struct {
	WebhookID int64
	Cursor    int64
	Events    []Event
	Place     func(e Event, previous *Delivery) Placement
}

type Reaction

type Reaction struct {
	ChatJID    string
	MessageID  string
	SenderJID  string
	SenderName string
	FromMe     bool
	Emoji      string
	ReactedAt  time.Time
}

type ReusedError

type ReusedError struct {
	Grant Grant
}

func (*ReusedError) Error

func (e *ReusedError) Error() string

type SearchPosition

type SearchPosition struct {
	SentAt  time.Time
	ChatJID string
	ID      string
}

type SearchQuery

type SearchQuery struct {
	Match   string
	ChatJID string
	Since   time.Time
	Until   time.Time
	Before  *SearchPosition
	Limit   int
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

func Open

func Open(ctx context.Context, path string) (*Store, error)

func (*Store) Account

func (s *Store) Account(ctx context.Context, id int64) (Account, error)

func (*Store) AccountByName

func (s *Store) AccountByName(ctx context.Context, name string) (Account, error)

func (*Store) ActiveGrant

func (s *Store) ActiveGrant(ctx context.Context, id int64) (Grant, error)

func (*Store) ChangeGrant

func (s *Store) ChangeGrant(ctx context.Context, c GrantChange) (Grant, error)

func (*Store) ChangeWebhook added in v0.2.0

func (s *Store) ChangeWebhook(ctx context.Context, c WebhookChange) (Webhook, error)

func (*Store) Chat

func (s *Store) Chat(ctx context.Context, accountID int64, jid string) (Chat, error)

func (*Store) ClaimDelivery added in v0.2.0

func (s *Store) ClaimDelivery(ctx context.Context, id int64, leaseUntil time.Time) (Delivery, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) CountMessages

func (s *Store) CountMessages(ctx context.Context, accountID int64) (int64, error)

func (*Store) CreateAccount

func (s *Store) CreateAccount(ctx context.Context, n NewAccount) (Account, error)

func (*Store) CreateAuthCode

func (s *Store) CreateAuthCode(ctx context.Context, c AuthCode) error

func (*Store) CreateGrant

func (s *Store) CreateGrant(ctx context.Context, n NewGrant) (Grant, error)

func (*Store) CreateOAuthClient

func (s *Store) CreateOAuthClient(ctx context.Context, c OAuthClient) error

func (*Store) CreateWebhook added in v0.2.0

func (s *Store) CreateWebhook(ctx context.Context, n NewWebhook) (Webhook, error)

func (*Store) DeleteAccount

func (s *Store) DeleteAccount(ctx context.Context, id int64) error

func (*Store) DeleteDeliveriesSettledBefore added in v0.2.0

func (s *Store) DeleteDeliveriesSettledBefore(ctx context.Context, before time.Time) (int, error)

func (*Store) DeleteEventsBefore added in v0.2.0

func (s *Store) DeleteEventsBefore(ctx context.Context, before time.Time) (int, error)

func (*Store) DeleteMessagesBefore

func (s *Store) DeleteMessagesBefore(ctx context.Context, accountID int64, before time.Time, removeFiles func(paths []string) error) (ExpiredBatch, error)

func (*Store) DeleteUnfinishedPairings

func (s *Store) DeleteUnfinishedPairings(ctx context.Context) error

func (*Store) DeleteWebhook added in v0.2.0

func (s *Store) DeleteWebhook(ctx context.Context, name string) (Webhook, error)

func (*Store) DeliveryEvents added in v0.2.0

func (s *Store) DeliveryEvents(ctx context.Context, d Delivery) ([]Event, error)

func (*Store) DueDeliveries added in v0.2.0

func (s *Store) DueDeliveries(ctx context.Context, now time.Time, limit int) ([]Delivery, error)

func (*Store) DueMedia

func (s *Store) DueMedia(ctx context.Context, now time.Time, limit int) ([]MediaFile, error)

func (*Store) EditMessage

func (s *Store) EditMessage(ctx context.Context, accountID int64, chatJID, id, senderJID, text string, editedAt time.Time) error

func (*Store) EnableWebhook added in v0.2.0

func (s *Store) EnableWebhook(ctx context.Context, name string) (Webhook, error)

func (*Store) EventsAfter added in v0.2.0

func (s *Store) EventsAfter(ctx context.Context, seq int64, limit int) ([]Event, error)

func (*Store) ForgetUnusedOAuthClients

func (s *Store) ForgetUnusedOAuthClients(ctx context.Context, registeredBefore, now time.Time) error

func (*Store) Grant

func (s *Store) Grant(ctx context.Context, id int64) (Grant, error)

func (*Store) GrantAccounts

func (s *Store) GrantAccounts(ctx context.Context, g Grant) ([]Account, error)

func (*Store) GrantByName

func (s *Store) GrantByName(ctx context.Context, name string) (Grant, error)

func (*Store) GrantForBearer

func (s *Store) GrantForBearer(ctx context.Context, hash string, now time.Time) (Bearer, error)

func (*Store) HasMessages

func (s *Store) HasMessages(ctx context.Context, accountID int64, chatJID string, q MessageQuery) (bool, error)

func (*Store) InsertToken

func (s *Store) InsertToken(ctx context.Context, t Token) error

func (*Store) ListAccounts

func (s *Store) ListAccounts(ctx context.Context) ([]Account, error)

func (*Store) ListChats

func (s *Store) ListChats(ctx context.Context, accountID int64, q ChatQuery) ([]Chat, error)

func (*Store) ListGrants

func (s *Store) ListGrants(ctx context.Context) ([]Grant, error)

func (*Store) ListWebhooks added in v0.2.0

func (s *Store) ListWebhooks(ctx context.Context) ([]Webhook, error)

func (*Store) MarkChatReadUntil

func (s *Store) MarkChatReadUntil(ctx context.Context, accountID int64, jid string, readAt time.Time) error

func (*Store) MediaFile

func (s *Store) MediaFile(ctx context.Context, ref MediaRef) (MediaFile, error)

func (*Store) MediaFileByPath

func (s *Store) MediaFileByPath(ctx context.Context, path string) (MediaFile, error)

func (*Store) MergeIdentity

func (s *Store) MergeIdentity(ctx context.Context, accountID int64, lid, phone string) error

func (*Store) Message

func (s *Store) Message(ctx context.Context, accountID int64, chatJID, id string) (Message, error)

func (*Store) Messages

func (s *Store) Messages(ctx context.Context, accountID int64, chatJID string, q MessageQuery) ([]Message, error)

func (*Store) NextDeliveryDue added in v0.2.0

func (s *Store) NextDeliveryDue(ctx context.Context) (time.Time, bool, error)

func (*Store) OAuthClient

func (s *Store) OAuthClient(ctx context.Context, id string) (OAuthClient, error)

func (*Store) OldestMessage

func (s *Store) OldestMessage(ctx context.Context, accountID int64, chatJID string) (Message, error)

func (*Store) QueueEvents added in v0.2.0

func (s *Store) QueueEvents(ctx context.Context, q Queue) error

func (*Store) React

func (s *Store) React(ctx context.Context, accountID int64, r Reaction) error

func (*Store) RecordAttempt added in v0.2.0

func (s *Store) RecordAttempt(ctx context.Context, id int64, a AttemptOutcome) error

func (*Store) RedeemAuthCode

func (s *Store) RedeemAuthCode(ctx context.Context, hash string, now time.Time, issue func(AuthCode) (NewGrant, error)) (Grant, error)

func (*Store) RedeliverFailed added in v0.2.0

func (s *Store) RedeliverFailed(ctx context.Context, webhookID int64, failedSince, dueAt time.Time) (int, error)

func (*Store) RetryFailedMediaNow

func (s *Store) RetryFailedMediaNow(ctx context.Context, accountID int64, now time.Time) error

func (*Store) RevokeGrant

func (s *Store) RevokeGrant(ctx context.Context, name string, at time.Time) (Grant, error)

func (*Store) RevokeGrantOfToken

func (s *Store) RevokeGrantOfToken(ctx context.Context, hash string, at time.Time, allowed func(Grant) bool) (Grant, error)

func (*Store) RevokeMessage

func (s *Store) RevokeMessage(ctx context.Context, accountID int64, chatJID, id, senderJID string, byAdmin bool, revokedAt time.Time) error

func (*Store) RotateRefreshToken

func (s *Store) RotateRefreshToken(ctx context.Context, hash string, now time.Time, issue func(Grant) ([]Token, error)) (Grant, error)

func (*Store) RotateWebhookSecret added in v0.2.0

func (s *Store) RotateWebhookSecret(ctx context.Context, name, secret string, previousSecretUntil time.Time) (Webhook, error)

func (*Store) SaveChat

func (s *Store) SaveChat(ctx context.Context, accountID int64, chat Chat) error

func (*Store) SaveHistoryMessage

func (s *Store) SaveHistoryMessage(ctx context.Context, accountID int64, chat Chat, msg Message) error

func (*Store) SaveMessage

func (s *Store) SaveMessage(ctx context.Context, accountID int64, chat Chat, msg Message, savedAt time.Time) error

func (*Store) SearchMessages

func (s *Store) SearchMessages(ctx context.Context, accountID int64, q SearchQuery) ([]Message, error)

func (*Store) SetAccountDescription

func (s *Store) SetAccountDescription(ctx context.Context, name, description string) (Account, error)

func (*Store) SetAccountLoggedOut

func (s *Store) SetAccountLoggedOut(ctx context.Context, id int64, at time.Time) error

func (*Store) SetAccountPaired

func (s *Store) SetAccountPaired(ctx context.Context, id int64, jid, phone string) error

func (*Store) SetAccountProfileName

func (s *Store) SetAccountProfileName(ctx context.Context, id int64, name string) error

func (*Store) SetAccountRetention

func (s *Store) SetAccountRetention(ctx context.Context, name string, months int) (Account, error)

func (*Store) SetAccountState

func (s *Store) SetAccountState(ctx context.Context, id int64, state string, at time.Time) error

func (*Store) SetChatName

func (s *Store) SetChatName(ctx context.Context, accountID int64, jid, name string) error

func (*Store) SetMediaDownloaded

func (s *Store) SetMediaDownloaded(ctx context.Context, ref MediaRef, path string) (bool, error)

func (*Store) SetMediaFailed

func (s *Store) SetMediaFailed(ctx context.Context, ref MediaRef, failure MediaFailure) error

func (*Store) SetUnreadCount

func (s *Store) SetUnreadCount(ctx context.Context, accountID int64, jid string, count int) error

func (*Store) SpendApproval

func (s *Store) SpendApproval(ctx context.Context, nonce string, expires, now time.Time) (bool, error)

func (*Store) SummarizeDeliveries added in v0.2.0

func (s *Store) SummarizeDeliveries(ctx context.Context, webhookID int64) (DeliverySummary, error)

func (*Store) Webhook added in v0.2.0

func (s *Store) Webhook(ctx context.Context, id int64) (Webhook, error)

func (*Store) WebhookAccounts added in v0.2.0

func (s *Store) WebhookAccounts(ctx context.Context, w Webhook) ([]Account, error)

func (*Store) WebhookByName added in v0.2.0

func (s *Store) WebhookByName(ctx context.Context, name string) (Webhook, error)

func (*Store) WebhookChats added in v0.2.0

func (s *Store) WebhookChats(ctx context.Context, w Webhook) ([]WebhookChat, error)

type Token

type Token struct {
	Hash      string
	GrantID   int64
	Kind      string
	ExpiresAt time.Time
	CreatedAt time.Time
}

type UnknownAccountError

type UnknownAccountError struct {
	Name string
}

func (*UnknownAccountError) Error

func (e *UnknownAccountError) Error() string

func (*UnknownAccountError) Is

func (e *UnknownAccountError) Is(target error) bool

type Webhook added in v0.2.0

type Webhook struct {
	ID                  int64
	Name                string
	URL                 string
	Format              string
	Content             string
	Events              []string
	Chats               string
	Quiet               time.Duration
	MaxWait             time.Duration
	Secret              string
	PreviousSecret      string
	PreviousSecretUntil time.Time
	Headers             map[string]string
	Cursor              int64
	CreatedAt           time.Time
	DisabledAt          time.Time
}

func (Webhook) Disabled added in v0.2.0

func (w Webhook) Disabled() bool

type WebhookChange added in v0.2.0

type WebhookChange struct {
	Webhook             Webhook
	ChangeAccounts      bool
	AllExistingAccounts bool
	AccountNames        []string
	ListedChats         func(accountID int64) []string
}

type WebhookChat added in v0.2.0

type WebhookChat struct {
	AccountID int64
	ChatJID   string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL