mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-04 20:05:16 +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
|
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||
from sqlalchemy.dialects.postgresql import insert
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.db import GatewayInboundEvent, GatewayPlatform
|
||||
from app.db import ExternalChatInboundEvent, ExternalChatPlatform
|
||||
|
||||
|
||||
def telegram_event_dedupe_key(update_id: int | str) -> str:
|
||||
|
|
@ -16,15 +16,16 @@ async def persist_inbound_event(
|
|||
session: AsyncSession,
|
||||
*,
|
||||
account_id: int,
|
||||
platform: GatewayPlatform,
|
||||
platform: ExternalChatPlatform,
|
||||
event_dedupe_key: str,
|
||||
event_kind: str,
|
||||
raw_payload: dict,
|
||||
external_event_id: str | None = None,
|
||||
external_message_id: str | None = None,
|
||||
request_id: str | None = None,
|
||||
) -> int | None:
|
||||
stmt = (
|
||||
insert(GatewayInboundEvent)
|
||||
insert(ExternalChatInboundEvent)
|
||||
.values(
|
||||
account_id=account_id,
|
||||
platform=platform,
|
||||
|
|
@ -33,11 +34,12 @@ async def persist_inbound_event(
|
|||
external_message_id=external_message_id,
|
||||
event_kind=event_kind,
|
||||
raw_payload=raw_payload,
|
||||
request_id=request_id,
|
||||
)
|
||||
.on_conflict_do_nothing(
|
||||
index_elements=["account_id", "event_dedupe_key"],
|
||||
)
|
||||
.returning(GatewayInboundEvent.id)
|
||||
.returning(ExternalChatInboundEvent.id)
|
||||
)
|
||||
result = await session.execute(stmt)
|
||||
return result.scalar_one_or_none()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue