feat: /new_creative tg_bot
This commit is contained in:
@@ -8,6 +8,8 @@ __all__ = (
|
||||
'Subscription',
|
||||
'Subscriber',
|
||||
'PlacementViewsHistory',
|
||||
'TelegramState',
|
||||
'TelegramStateEnum',
|
||||
'TargetChannelStatus',
|
||||
'CreativeStatus',
|
||||
'PlacementStatus',
|
||||
@@ -52,4 +54,5 @@ from .placement_views_history import PlacementViewsHistory
|
||||
from .subscriber import Subscriber
|
||||
from .subscription import Subscription, SubscriptionStatus
|
||||
from .target_channel import TargetChannel, TargetChannelStatus
|
||||
from .telegram_state import TelegramState, TelegramStateEnum
|
||||
from .user import User
|
||||
|
||||
24
src/domain/telegram_state.py
Normal file
24
src/domain/telegram_state.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import enum
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import BigInteger, Enum
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from . import Base
|
||||
|
||||
|
||||
class TelegramStateEnum(str, enum.Enum):
|
||||
"""Telegram bot conversation states."""
|
||||
|
||||
CREATIVE_WAITING_CHANNEL = 'creative_waiting_channel'
|
||||
CREATIVE_WAITING_NAME = 'creative_waiting_name'
|
||||
CREATIVE_WAITING_TEXT = 'creative_waiting_text'
|
||||
|
||||
|
||||
class TelegramState(Base):
|
||||
"""Хранит текущее состояние разговора пользователя с ботом для multi-step flows."""
|
||||
|
||||
telegram_id: Mapped[int] = mapped_column(BigInteger, unique=True, nullable=False, index=True)
|
||||
state: Mapped[TelegramStateEnum] = mapped_column(Enum(TelegramStateEnum), nullable=False)
|
||||
context: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False, default=dict)
|
||||
@@ -12,5 +12,4 @@ class User(domain.Base):
|
||||
telegram_id: Mapped[int] = mapped_column(unique=True, index=True)
|
||||
username: Mapped[str | None]
|
||||
|
||||
# Relationship with channels
|
||||
target_channels: Mapped[list['TargetChannel']] = relationship(back_populates='user')
|
||||
|
||||
19
src/domain/user_conversation_state.py
Normal file
19
src/domain/user_conversation_state.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import enum
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from src import domain
|
||||
|
||||
|
||||
class TelegramStateEnum(enum.StrEnum):
|
||||
CREATIVE_WAITING_CHANNEL = 'creative_waiting_channel'
|
||||
CREATIVE_WAITING_NAME = 'creative_waiting_name'
|
||||
CREATIVE_WAITING_TEXT = 'creative_waiting_text'
|
||||
|
||||
|
||||
class TelegramState(domain.Base):
|
||||
telegram_id: Mapped[int] = mapped_column(unique=True, index=True)
|
||||
state: Mapped[TelegramStateEnum]
|
||||
context: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False, default=dict)
|
||||
Reference in New Issue
Block a user