files

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package files provides file processing utilities for Telegram messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecordFileDownload

func RecordFileDownload(userID int64, fileType FileType, durationSeconds float64, sizeBytes int64, success bool)

RecordFileDownload records metrics for a file download operation.

Types

type FileType

type FileType string

FileType represents the type of file being processed.

const (
	FileTypePhoto    FileType = "photo"
	FileTypeImage    FileType = "image" // image sent as document
	FileTypePDF      FileType = "pdf"
	FileTypeVoice    FileType = "voice"
	FileTypeDocument FileType = "document" // text files
)

type ProcessedFile

type ProcessedFile struct {
	// LLMParts contains the file data formatted for OpenRouter API
	// (ImagePart, FilePart, TextPart from openrouter package)
	LLMParts []interface{}

	// Instruction is the localized LLM instruction for this file type
	// (e.g., "Quote the transcription..." for voice messages)
	Instruction string

	// FileType indicates the type of file
	FileType FileType

	// FileID is the Telegram file ID
	FileID string

	// FileName is the original file name (if available)
	FileName string

	// MimeType is the MIME type of the file
	MimeType string

	// Size is the file size in bytes
	Size int64

	// Duration is the download time (for metrics)
	Duration time.Duration
}

ProcessedFile represents a processed file ready for LLM consumption.

type Processor

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

Processor handles file downloads and processing from Telegram messages.

func NewProcessor

func NewProcessor(
	downloader telegram.FileDownloader,
	translator *i18n.Translator,
	language string,
	logger *slog.Logger,
) *Processor

NewProcessor creates a new file processor.

func (*Processor) ProcessMessage

func (p *Processor) ProcessMessage(ctx context.Context, msg *telegram.Message, userID int64) ([]*ProcessedFile, error)

ProcessMessage extracts and processes the file from a message. A Telegram message contains at most one file (photo OR document OR voice). Individual file errors are logged as warnings and nil is returned for that file. Returns a slice with 0 or 1 successfully processed files.

Jump to

Keyboard shortcuts

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