Documentation
¶
Overview ¶
Package pairing implements OpenClaw-style DM pairing for channel access control
Index ¶
- func BuildPairingReply(channel, idLine, code string) string
- type AllowStore
- type Config
- type DMPolicy
- type PairingRequest
- type PairingStore
- func (ps *PairingStore) AddToAllowlist(senderID, name string) error
- func (ps *PairingStore) Approve(code string) (string, string, error)
- func (ps *PairingStore) GetAllowlist() map[string]string
- func (ps *PairingStore) IsAllowed(senderID string) bool
- func (ps *PairingStore) ListPending() []*PairingRequest
- func (ps *PairingStore) Reject(code string) error
- func (ps *PairingStore) RemoveFromAllowlist(senderID string) error
- func (ps *PairingStore) UpsertRequest(senderID, senderName string) (string, bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildPairingReply ¶
BuildPairingReply builds the pairing reply message sent to the user
Types ¶
type AllowStore ¶
type AllowStore struct {
// contains filtered or unexported fields
}
AllowStore manages the allowlist (approved senders)
func (*AllowStore) Save ¶
func (as *AllowStore) Save() error
Save saves the allowlist to disk Note: caller must hold the write lock (mu.Lock)
type Config ¶
type Config struct {
Channel string
AccountID string // empty for default account
DataDir string
CodeLength int // default 8
CodeExpiry time.Duration // default 1 hour
MaxPending int // max pending requests, default 3
}
Config options for PairingStore
type DMPolicy ¶
type DMPolicy string
DMPolicy defines the direct message access policy
const ( // DMPolicyOpen allows all senders DMPolicyOpen DMPolicy = "open" // DMPolicyPairing requires pairing approval for unknown senders DMPolicyPairing DMPolicy = "pairing" // DMPolicyAllowlist only allows senders in the allowlist DMPolicyAllowlist DMPolicy = "allowlist" // DMPolicyClosed blocks all DMs DMPolicyClosed DMPolicy = "closed" )
type PairingRequest ¶
type PairingRequest struct {
ID string `json:"id"` // sender ID (e.g., open_id, user_id)
Name string `json:"name"` // sender display name
Code string `json:"code"` // 8-char uppercase code
CreatedAt int64 `json:"created_at"` // Unix timestamp
ExpiresAt int64 `json:"expires_at"` // Unix timestamp
Metadata map[string]interface{} `json:"metadata"` // Additional metadata
}
PairingRequest represents a pending pairing request
func (*PairingRequest) IsExpired ¶
func (p *PairingRequest) IsExpired() bool
IsExpired checks if the pairing request has expired
type PairingStore ¶
type PairingStore struct {
// contains filtered or unexported fields
}
PairingStore manages pairing requests and allowlist
func NewPairingStore ¶
func NewPairingStore(cfg Config) (*PairingStore, error)
NewPairingStore creates a new pairing store
func (*PairingStore) AddToAllowlist ¶
func (ps *PairingStore) AddToAllowlist(senderID, name string) error
AddToAllowlist directly adds a sender to the allowlist (for admin use)
func (*PairingStore) Approve ¶
func (ps *PairingStore) Approve(code string) (string, string, error)
Approve approves a pairing request by code Returns (senderID, name, error)
func (*PairingStore) GetAllowlist ¶
func (ps *PairingStore) GetAllowlist() map[string]string
GetAllowlist returns all allowed senders
func (*PairingStore) IsAllowed ¶
func (ps *PairingStore) IsAllowed(senderID string) bool
IsAllowed checks if a sender is in the allowlist
func (*PairingStore) ListPending ¶
func (ps *PairingStore) ListPending() []*PairingRequest
ListPending returns all non-expired pending requests
func (*PairingStore) Reject ¶
func (ps *PairingStore) Reject(code string) error
Reject rejects a pairing request by code
func (*PairingStore) RemoveFromAllowlist ¶
func (ps *PairingStore) RemoveFromAllowlist(senderID string) error
RemoveFromAllowlist removes a sender from the allowlist
func (*PairingStore) UpsertRequest ¶
func (ps *PairingStore) UpsertRequest(senderID, senderName string) (string, bool, error)
UpsertRequest creates or updates a pairing request Returns (code, created, error) created is true if a new request was created, false if existing request was found