feat: add realtime capturing

This commit is contained in:
h
2026-05-29 18:19:06 +02:00
parent 920a0235e2
commit 3c1a12750c
29 changed files with 967 additions and 47 deletions
+88 -1
View File
@@ -1,7 +1,7 @@
from datetime import datetime
from typing import Any
from sqlalchemy import BigInteger, Column, DateTime, func
from sqlalchemy import BigInteger, Column, DateTime, LargeBinary, func
from sqlalchemy.dialects.postgresql import JSONB
from sqlmodel import Field, SQLModel
@@ -42,9 +42,16 @@ class Message(SQLModel, table=True):
chat_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
message_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
date: datetime = Field(sa_column=Column(DateTime(timezone=True), primary_key=True))
sender_id: int | None = Field(default=None, sa_column=Column(BigInteger))
text: str | None = None
raw: dict[str, Any] = Field(
default_factory=dict, sa_column=Column(JSONB, nullable=False)
)
has_media: bool = False
is_self_destruct: bool = False
edited_at: datetime | None = Field(
default=None, sa_column=Column(DateTime(timezone=True))
)
deleted_at: datetime | None = Field(
default=None, sa_column=Column(DateTime(timezone=True))
)
@@ -71,6 +78,86 @@ class Folder(SQLModel, table=True):
)
class MessageVersion(SQLModel, table=True):
__tablename__ = "message_versions"
account_id: int = Field(primary_key=True)
chat_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
message_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
observed_at: datetime = Field(
sa_column=Column(DateTime(timezone=True), primary_key=True)
)
edit_date: datetime | None = Field(
default=None, sa_column=Column(DateTime(timezone=True))
)
text: str | None = None
raw: dict[str, Any] = Field(
default_factory=dict, sa_column=Column(JSONB, nullable=False)
)
class Media(SQLModel, table=True):
__tablename__ = "media"
id: int | None = Field(default=None, primary_key=True)
account_id: int
chat_id: int = Field(sa_column=Column(BigInteger, nullable=False))
message_id: int = Field(sa_column=Column(BigInteger, nullable=False))
kind: str
storage_key: str | None = None
file_size: int | None = Field(default=None, sa_column=Column(BigInteger))
mime: str | None = None
ttl_seconds: int | None = None
downloaded: bool = False
extracted_text: str | None = None
created_at: datetime = Field(
sa_column=Column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
)
class Callback(SQLModel, table=True):
__tablename__ = "callbacks"
id: int | None = Field(default=None, primary_key=True)
account_id: int
chat_id: int = Field(sa_column=Column(BigInteger, nullable=False))
message_id: int = Field(sa_column=Column(BigInteger, nullable=False))
position: int
label: str | None = None
data: bytes | None = Field(default=None, sa_column=Column(LargeBinary))
created_at: datetime = Field(
sa_column=Column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
)
class Reaction(SQLModel, table=True):
__tablename__ = "reactions"
id: int | None = Field(default=None, primary_key=True)
account_id: int
chat_id: int = Field(sa_column=Column(BigInteger, nullable=False))
message_id: int = Field(sa_column=Column(BigInteger, nullable=False))
peer_id: int = Field(sa_column=Column(BigInteger, nullable=False))
reaction: str
added_at: datetime = Field(
sa_column=Column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
)
removed_at: datetime | None = Field(
default=None, sa_column=Column(DateTime(timezone=True))
)
created_at: datetime = Field(
sa_column=Column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
)
class CapturePolicy(SQLModel, table=True):
__tablename__ = "capture_policy"