mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-06 20:15:17 +02:00
refactor(gateway): rename persistence models to external chat
This commit is contained in:
parent
f2d82234d4
commit
a57b741d5e
8 changed files with 274 additions and 323 deletions
|
|
@ -1,4 +1,4 @@
|
|||
"""Gateway account helpers."""
|
||||
"""External chat account helpers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
|
@ -7,16 +7,16 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||
|
||||
from app.config import config
|
||||
from app.db import (
|
||||
GatewayAccountMode,
|
||||
GatewayHealthStatus,
|
||||
GatewayPlatform,
|
||||
GatewayPlatformAccount,
|
||||
ExternalChatAccountMode,
|
||||
ExternalChatHealthStatus,
|
||||
ExternalChatPlatform,
|
||||
ExternalChatAccount,
|
||||
)
|
||||
from app.utils.oauth_security import TokenEncryption
|
||||
|
||||
|
||||
def account_token(account: GatewayPlatformAccount) -> str | None:
|
||||
if account.is_system_account and account.platform == GatewayPlatform.TELEGRAM:
|
||||
def account_token(account: ExternalChatAccount) -> str | None:
|
||||
if account.is_system_account and account.platform == ExternalChatPlatform.TELEGRAM:
|
||||
return config.TELEGRAM_SHARED_BOT_TOKEN
|
||||
if not account.encrypted_credentials:
|
||||
return None
|
||||
|
|
@ -27,26 +27,24 @@ def account_token(account: GatewayPlatformAccount) -> str | None:
|
|||
|
||||
async def get_or_create_system_telegram_account(
|
||||
session: AsyncSession,
|
||||
) -> GatewayPlatformAccount:
|
||||
) -> ExternalChatAccount:
|
||||
result = await session.execute(
|
||||
select(GatewayPlatformAccount).where(
|
||||
GatewayPlatformAccount.platform == GatewayPlatform.TELEGRAM,
|
||||
GatewayPlatformAccount.is_system_account.is_(True),
|
||||
select(ExternalChatAccount).where(
|
||||
ExternalChatAccount.platform == ExternalChatPlatform.TELEGRAM,
|
||||
ExternalChatAccount.is_system_account.is_(True),
|
||||
)
|
||||
)
|
||||
account = result.scalars().first()
|
||||
if account is not None:
|
||||
return account
|
||||
account = GatewayPlatformAccount(
|
||||
platform=GatewayPlatform.TELEGRAM,
|
||||
mode=GatewayAccountMode.CLOUD_SHARED,
|
||||
account = ExternalChatAccount(
|
||||
platform=ExternalChatPlatform.TELEGRAM,
|
||||
mode=ExternalChatAccountMode.CLOUD_SHARED,
|
||||
is_system_account=True,
|
||||
account_metadata={
|
||||
"bot_username": config.TELEGRAM_SHARED_BOT_USERNAME,
|
||||
"webhook_secret": config.TELEGRAM_WEBHOOK_SECRET,
|
||||
},
|
||||
bot_username=config.TELEGRAM_SHARED_BOT_USERNAME,
|
||||
webhook_secret=config.TELEGRAM_WEBHOOK_SECRET,
|
||||
cursor_state={},
|
||||
health_status=GatewayHealthStatus.UNKNOWN,
|
||||
health_status=ExternalChatHealthStatus.UNKNOWN,
|
||||
)
|
||||
session.add(account)
|
||||
await session.flush()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue