actions

package
v0.0.0-...-33b3299 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultConfirmTTL = 10 * time.Minute
View Source
const DefaultSendFileMaxBytes int64 = 25 * 1000 * 1000

Variables

This section is empty.

Functions

func DeriveToken

func DeriveToken(actor string, kind Kind, payload any) (string, error)

func PayloadSHA256

func PayloadSHA256(payload any) string

func ValidatePending

func ValidatePending(a PendingAction, actor string, kind Kind, payload any, confirmation string, now time.Time) error

Types

type Kind

type Kind string
const (
	Send          Kind = "send"
	SendFile      Kind = "send_file"
	Reply         Kind = "reply"
	MediaDownload Kind = "media_download"
	Forward       Kind = "forward"
	React         Kind = "react"
	MarkRead      Kind = "mark_read"
	Join          Kind = "join"
)

type MarkReadExecutor

type MarkReadExecutor interface {
	MarkRead(ctx context.Context, request MarkReadRequest) (MarkReadResult, error)
}

type MarkReadPayload

type MarkReadPayload struct {
	AccountID int64  `json:"account_id"`
	Peer      string `json:"peer"`
	PeerID    int64  `json:"peer_id"`
	PeerKind  string `json:"peer_kind"`
	MaxID     int64  `json:"max_id"`
}

func NewMarkReadPayload

func NewMarkReadPayload(request MarkReadRequest) MarkReadPayload

type MarkReadRequest

type MarkReadRequest struct {
	Actor      string `json:"actor"`
	AccountID  int64  `json:"account_id"`
	Peer       string `json:"peer"`
	PeerID     int64  `json:"peer_id"`
	PeerKind   string `json:"peer_kind"`
	AccessHash *int64 `json:"-"`
	MaxID      int64  `json:"max_id"`
}

type MarkReadResult

type MarkReadResult struct {
	MarkedReadAt time.Time `json:"marked_read_at"`
}

type MarkReadService

type MarkReadService struct {
	ACL      acl.ACL
	Executor MarkReadExecutor
	Now      func() time.Time
	TTL      time.Duration
}

func (MarkReadService) ConfirmAndMarkRead

func (s MarkReadService) ConfirmAndMarkRead(ctx context.Context, request MarkReadRequest) (MarkReadResult, error)

func (MarkReadService) Plan

func (s MarkReadService) Plan(request MarkReadRequest, dryRun bool) (ScopedPlan, error)

type MediaDownloadCounts

type MediaDownloadCounts struct {
	Candidates int   `json:"candidates"`
	Planned    int   `json:"planned"`
	Skipped    int   `json:"skipped"`
	Downloaded int   `json:"downloaded,omitempty"`
	Failed     int   `json:"failed,omitempty"`
	TotalBytes int64 `json:"total_bytes"`
}

type MediaDownloadItem

type MediaDownloadItem struct {
	AccountID     int64  `json:"account_id,omitempty"`
	PeerID        int64  `json:"peer_id,omitempty"`
	MessageID     int64  `json:"message_id"`
	Date          string `json:"date"`
	FileID        int64  `json:"-"`
	MediaKind     string `json:"media_kind"`
	MediaID       string `json:"-"`
	AccessHash    int64  `json:"-"`
	FileReference []byte `json:"-"`
	ThumbSize     string `json:"-"`
	DCID          int    `json:"-"`
	MimeType      string `json:"mime_type,omitempty"`
	SizeBytes     int64  `json:"size_bytes"`
	FileName      string `json:"-"`
	Ext           string `json:"-"`
	PlannedPath   string `json:"planned_path,omitempty"`
	Status        string `json:"status"`
	Error         string `json:"error,omitempty"`
	LocalPath     string `json:"local_path,omitempty"`
	SHA256        string `json:"sha256,omitempty"`
}

type MediaDownloadLimits

type MediaDownloadLimits struct {
	Limit        int      `json:"limit"`
	MaxFileBytes int64    `json:"max_file_bytes"`
	MaxBytes     int64    `json:"max_bytes"`
	Types        []string `json:"types"`
}

type MediaDownloadManifest

type MediaDownloadManifest struct {
	Peer         MediaDownloadPeer   `json:"peer"`
	Window       MediaDownloadWindow `json:"window"`
	Limits       MediaDownloadLimits `json:"limits"`
	Counts       MediaDownloadCounts `json:"counts"`
	Items        []MediaDownloadItem `json:"items"`
	ManifestPath string              `json:"manifest_path"`
	CreatedAt    string              `json:"created_at"`
}

type MediaDownloadPayload

type MediaDownloadPayload struct {
	AccountID    int64    `json:"account_id"`
	Peer         string   `json:"peer"`
	PeerID       int64    `json:"peer_id"`
	Since        string   `json:"since"`
	Until        string   `json:"until,omitempty"`
	OutDir       string   `json:"out_dir"`
	Limit        int      `json:"limit"`
	MaxFileBytes int64    `json:"max_file_bytes"`
	MaxBytes     int64    `json:"max_bytes"`
	Types        []string `json:"types"`
}

func NewMediaDownloadPayload

func NewMediaDownloadPayload(request MediaDownloadRequest) MediaDownloadPayload

func NewMediaDownloadPendingPayload

func NewMediaDownloadPendingPayload(request MediaDownloadRequest) (MediaDownloadPayload, error)

type MediaDownloadPeer

type MediaDownloadPeer struct {
	AccountID int64 `json:"account_id"`
	PeerID    int64 `json:"peer_id"`
}

type MediaDownloadPlan

type MediaDownloadPlan struct {
	Action                  Kind                `json:"action"`
	LiveRead                bool                `json:"live_read"`
	LocalArtifactWrite      bool                `json:"local_artifact_write"`
	Actor                   string              `json:"actor"`
	AccountID               int64               `json:"account_id"`
	Peer                    string              `json:"peer"`
	PeerID                  int64               `json:"peer_id"`
	Since                   string              `json:"since"`
	Until                   string              `json:"until,omitempty"`
	OutDir                  string              `json:"out_dir"`
	RequiredPermission      acl.Permission      `json:"required_permission"`
	PermissionGranted       bool                `json:"permission_granted"`
	DryRun                  bool                `json:"dry_run"`
	ConfirmationRequired    bool                `json:"confirmation_required"`
	ConfirmationToken       string              `json:"confirmation_token"`
	ConfirmationExpiresAt   time.Time           `json:"confirmation_expires_at"`
	ConfirmationInstruction string              `json:"confirmation_instruction"`
	Limits                  MediaDownloadLimits `json:"limits"`
	Counts                  MediaDownloadCounts `json:"counts"`
	Items                   []MediaDownloadItem `json:"items"`
	Safety                  MediaDownloadSafety `json:"safety"`
	Status                  MediaDownloadStatus `json:"status"`
}

type MediaDownloadRequest

type MediaDownloadRequest struct {
	Actor        string              `json:"actor"`
	AccountID    int64               `json:"account_id"`
	Peer         string              `json:"peer"`
	PeerID       int64               `json:"peer_id"`
	Since        string              `json:"since"`
	Until        string              `json:"until,omitempty"`
	OutDir       string              `json:"out_dir"`
	Limit        int                 `json:"limit"`
	MaxFileBytes int64               `json:"max_file_bytes"`
	MaxBytes     int64               `json:"max_bytes"`
	Types        []string            `json:"types"`
	Items        []MediaDownloadItem `json:"-"`
}

type MediaDownloadSafety

type MediaDownloadSafety struct {
	NoNetwork         bool   `json:"no_network"`
	NoFilesWritten    bool   `json:"no_files_written"`
	SecretsRedacted   bool   `json:"secrets_redacted"`
	TextRedacted      bool   `json:"text_redacted"`
	PartialThenRename bool   `json:"partial_then_rename"`
	Notes             string `json:"notes"`
}

type MediaDownloadService

type MediaDownloadService struct {
	ACL        acl.ACL
	Downloader MediaFileDownloader
	Now        func() time.Time
	TTL        time.Duration
}

func (MediaDownloadService) ConfirmAndDownload

func (s MediaDownloadService) ConfirmAndDownload(ctx context.Context, request MediaDownloadRequest, pending PendingAction, confirmation string) (MediaDownloadManifest, error)

func (MediaDownloadService) Plan

type MediaDownloadStatus

type MediaDownloadStatus struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Next    string `json:"next,omitempty"`
}

type MediaDownloadWindow

type MediaDownloadWindow struct {
	Since string `json:"since"`
	Until string `json:"until,omitempty"`
}

type MediaFileDownloader

type MediaFileDownloader interface {
	DownloadMedia(ctx context.Context, item MediaDownloadItem, w io.Writer) error
}

type PendingAction

type PendingAction struct {
	ID                 int64           `json:"id,omitempty"`
	AccountID          int64           `json:"account_id,omitempty"`
	PeerID             int64           `json:"peer_id,omitempty"`
	Token              string          `json:"token"`
	Actor              string          `json:"actor"`
	Kind               Kind            `json:"kind"`
	RequiredPermission string          `json:"required_permission,omitempty"`
	Payload            json.RawMessage `json:"payload"`
	PayloadSHA256      string          `json:"payload_sha256,omitempty"`
	Status             string          `json:"status,omitempty"`
	CreatedAt          time.Time       `json:"created_at"`
	ExpiresAt          time.Time       `json:"expires_at"`
	UpdatedAt          time.Time       `json:"updated_at,omitempty"`
}

func NewMediaDownloadPending

func NewMediaDownloadPending(request MediaDownloadRequest, createdAt time.Time, ttl time.Duration) (PendingAction, error)

func NewPending

func NewPending(actor string, kind Kind, payload any, createdAt time.Time, ttl time.Duration) (PendingAction, error)

func NewSendFilePending

func NewSendFilePending(request SendFileRequest, createdAt time.Time, ttl time.Duration) (PendingAction, error)

func NewSendPending

func NewSendPending(request SendRequest, createdAt time.Time, ttl time.Duration) (PendingAction, error)

func (PendingAction) Expired

func (a PendingAction) Expired(now time.Time) bool

type ReplyExecutor

type ReplyExecutor interface {
	Reply(ctx context.Context, request ReplyRequest) (ReplyResult, error)
}

type ReplyPayload

type ReplyPayload struct {
	AccountID        int64  `json:"account_id"`
	Peer             string `json:"peer"`
	PeerID           int64  `json:"peer_id"`
	PeerKind         string `json:"peer_kind"`
	ReplyToMessageID int64  `json:"reply_to_message_id"`
	TextSHA256       string `json:"text_sha256"`
	TextBytes        int    `json:"text_bytes"`
	TextRunes        int    `json:"text_runes"`
}

func NewReplyPayload

func NewReplyPayload(request ReplyRequest) ReplyPayload

type ReplyRequest

type ReplyRequest struct {
	Actor            string `json:"actor"`
	AccountID        int64  `json:"account_id"`
	Peer             string `json:"peer"`
	PeerID           int64  `json:"peer_id"`
	PeerKind         string `json:"peer_kind"`
	AccessHash       *int64 `json:"-"`
	ReplyToMessageID int64  `json:"reply_to_message_id"`
	Text             string `json:"text,omitempty"`
}

type ReplyResult

type ReplyResult struct {
	RemoteMessageID string    `json:"remote_message_id,omitempty"`
	SentAt          time.Time `json:"sent_at"`
}

type ReplyService

type ReplyService struct {
	ACL      acl.ACL
	Executor ReplyExecutor
	Now      func() time.Time
	TTL      time.Duration
}

func (ReplyService) ConfirmAndReply

func (s ReplyService) ConfirmAndReply(ctx context.Context, request ReplyRequest) (ReplyResult, error)

func (ReplyService) Plan

func (s ReplyService) Plan(request ReplyRequest, dryRun bool) (ScopedPlan, error)

type ScopedPlan

type ScopedPlan struct {
	Action                  Kind           `json:"action"`
	WriteCapable            bool           `json:"write_capable"`
	Actor                   string         `json:"actor"`
	AccountID               int64          `json:"account_id"`
	Peer                    string         `json:"peer"`
	PeerID                  int64          `json:"peer_id"`
	PeerKind                string         `json:"peer_kind"`
	ReplyToMessageID        int64          `json:"reply_to_message_id,omitempty"`
	MaxID                   int64          `json:"max_id,omitempty"`
	RequiredPermission      acl.Permission `json:"required_permission"`
	PermissionGranted       bool           `json:"permission_granted"`
	DryRun                  bool           `json:"dry_run"`
	ConfirmationRequired    bool           `json:"confirmation_required"`
	ConfirmationToken       string         `json:"confirmation_token"`
	ConfirmationExpiresAt   time.Time      `json:"confirmation_expires_at"`
	ConfirmationInstruction string         `json:"confirmation_instruction"`
	Payload                 any            `json:"payload"`
	Safety                  ScopedSafety   `json:"safety"`
	Status                  ScopedStatus   `json:"status"`
}

type ScopedSafety

type ScopedSafety struct {
	NoNetwork             bool   `json:"no_network"`
	LocalScopeOnly        bool   `json:"local_scope_only"`
	MessageTextRedacted   bool   `json:"message_text_redacted,omitempty"`
	AccessHashesRedacted  bool   `json:"access_hashes_redacted"`
	TelegramTextUntrusted bool   `json:"telegram_text_untrusted"`
	Notes                 string `json:"notes"`
}

type ScopedStatus

type ScopedStatus struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Next    string `json:"next,omitempty"`
}

type SendExecutor

type SendExecutor interface {
	Send(ctx context.Context, request SendRequest) (SendResult, error)
}

type SendFileExecutor

type SendFileExecutor interface {
	SendFile(ctx context.Context, request SendFileRequest) (SendFileResult, error)
}

type SendFilePayload

type SendFilePayload struct {
	Peer          string `json:"peer"`
	FilePath      string `json:"file_path"`
	FileBytes     int64  `json:"file_bytes"`
	FileSHA256    string `json:"file_sha256"`
	MIMEType      string `json:"mime_type"`
	Filename      string `json:"filename"`
	MaxFileBytes  int64  `json:"max_file_bytes"`
	CaptionSHA256 string `json:"caption_sha256,omitempty"`
	CaptionBytes  int    `json:"caption_bytes,omitempty"`
	CaptionRunes  int    `json:"caption_runes,omitempty"`
}

func NewSendFilePendingPayload

func NewSendFilePendingPayload(request SendFileRequest) (SendFilePayload, error)

type SendFilePlan

type SendFilePlan struct {
	Action                  Kind               `json:"action"`
	WriteCapable            bool               `json:"write_capable"`
	Actor                   string             `json:"actor"`
	Peer                    string             `json:"peer"`
	RequiredPermission      acl.Permission     `json:"required_permission"`
	PermissionGranted       bool               `json:"permission_granted"`
	DryRun                  bool               `json:"dry_run"`
	ConfirmationRequired    bool               `json:"confirmation_required"`
	ConfirmationToken       string             `json:"confirmation_token"`
	ConfirmationExpiresAt   time.Time          `json:"confirmation_expires_at"`
	ConfirmationInstruction string             `json:"confirmation_instruction"`
	Payload                 SendFilePayload    `json:"payload"`
	Safety                  SendFilePlanSafety `json:"safety"`
	Status                  SendFilePlanStatus `json:"status"`
}

type SendFilePlanSafety

type SendFilePlanSafety struct {
	NoNetwork             bool   `json:"no_network"`
	NoUpload              bool   `json:"no_upload"`
	CaptionTextRedacted   bool   `json:"caption_text_redacted"`
	TelegramTextUntrusted bool   `json:"telegram_text_untrusted"`
	ForceDocument         bool   `json:"force_document"`
	Notes                 string `json:"notes"`
}

type SendFilePlanStatus

type SendFilePlanStatus struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Next    string `json:"next"`
}

type SendFileRequest

type SendFileRequest struct {
	Actor        string `json:"actor"`
	Peer         string `json:"peer"`
	FilePath     string `json:"file_path"`
	UploadPath   string `json:"-"`
	Caption      string `json:"caption,omitempty"`
	MIMEType     string `json:"mime_type,omitempty"`
	Filename     string `json:"filename,omitempty"`
	MaxFileBytes int64  `json:"max_file_bytes"`
}

type SendFileResult

type SendFileResult struct {
	RemoteMessageID string    `json:"remote_message_id,omitempty"`
	SentAt          time.Time `json:"sent_at"`
}

type SendFileService

type SendFileService struct {
	ACL      acl.ACL
	Executor SendFileExecutor
	Now      func() time.Time
	TTL      time.Duration
}

func (SendFileService) ConfirmAndSendFile

func (s SendFileService) ConfirmAndSendFile(ctx context.Context, request SendFileRequest, pending PendingAction, confirmation string) (SendFileResult, error)

func (SendFileService) Plan

func (s SendFileService) Plan(request SendFileRequest, dryRun bool) (SendFilePlan, error)

type SendPayload

type SendPayload struct {
	Peer       string `json:"peer"`
	TextSHA256 string `json:"text_sha256"`
	TextBytes  int    `json:"text_bytes"`
	TextRunes  int    `json:"text_runes"`
}

func NewSendPayload

func NewSendPayload(request SendRequest) SendPayload

func NewSendPendingPayload

func NewSendPendingPayload(request SendRequest) (SendPayload, error)

type SendPlan

type SendPlan struct {
	Action                  Kind           `json:"action"`
	WriteCapable            bool           `json:"write_capable"`
	Actor                   string         `json:"actor"`
	Peer                    string         `json:"peer"`
	RequiredPermission      acl.Permission `json:"required_permission"`
	PermissionGranted       bool           `json:"permission_granted"`
	DryRun                  bool           `json:"dry_run"`
	ConfirmationRequired    bool           `json:"confirmation_required"`
	ConfirmationToken       string         `json:"confirmation_token"`
	ConfirmationExpiresAt   time.Time      `json:"confirmation_expires_at"`
	ConfirmationInstruction string         `json:"confirmation_instruction"`
	Payload                 SendPayload    `json:"payload"`
	Safety                  SendPlanSafety `json:"safety"`
	Status                  SendPlanStatus `json:"status"`
}

type SendPlanSafety

type SendPlanSafety struct {
	NoNetwork             bool   `json:"no_network"`
	MessageTextRedacted   bool   `json:"message_text_redacted"`
	TelegramTextUntrusted bool   `json:"telegram_text_untrusted"`
	Notes                 string `json:"notes"`
}

type SendPlanStatus

type SendPlanStatus struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Next    string `json:"next"`
}

type SendRequest

type SendRequest struct {
	Actor string `json:"actor"`
	Peer  string `json:"peer"`
	Text  string `json:"text,omitempty"`
}

type SendResult

type SendResult struct {
	RemoteMessageID string    `json:"remote_message_id,omitempty"`
	SentAt          time.Time `json:"sent_at"`
}

type SendService

type SendService struct {
	ACL      acl.ACL
	Executor SendExecutor
	Now      func() time.Time
	TTL      time.Duration
}

func (SendService) ConfirmAndSend

func (s SendService) ConfirmAndSend(ctx context.Context, request SendRequest, pending PendingAction, confirmation string) (SendResult, error)

func (SendService) Plan

func (s SendService) Plan(request SendRequest, dryRun bool) (SendPlan, error)

Jump to

Keyboard shortcuts

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