mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
feat(gateway): improve WhatsApp account mode handling and connection filtering
This commit is contained in:
parent
a151e8f729
commit
fc2467be3d
3 changed files with 82 additions and 12 deletions
|
|
@ -16,6 +16,7 @@ from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
|||
from app.config import config
|
||||
from app.db import (
|
||||
ExternalChatAccount,
|
||||
ExternalChatAccountMode,
|
||||
ExternalChatBinding,
|
||||
ExternalChatBindingState,
|
||||
ExternalChatEventStatus,
|
||||
|
|
@ -40,6 +41,21 @@ def _dashboard_url() -> str:
|
|||
return config.NEXT_FRONTEND_URL or "/dashboard"
|
||||
|
||||
|
||||
def _active_whatsapp_account_mode() -> ExternalChatAccountMode | None:
|
||||
if config.GATEWAY_WHATSAPP_INTAKE_MODE == "cloud":
|
||||
return ExternalChatAccountMode.CLOUD_SHARED
|
||||
if config.GATEWAY_WHATSAPP_INTAKE_MODE == "baileys":
|
||||
return ExternalChatAccountMode.SELF_HOST_BYO
|
||||
return None
|
||||
|
||||
|
||||
def _is_inactive_whatsapp_account(account: ExternalChatAccount) -> bool:
|
||||
return (
|
||||
account.platform == ExternalChatPlatform.WHATSAPP
|
||||
and account.mode != _active_whatsapp_account_mode()
|
||||
)
|
||||
|
||||
|
||||
async def claim_next_inbound_event(
|
||||
session_maker: SessionMaker = async_session_maker,
|
||||
) -> int | None:
|
||||
|
|
@ -293,6 +309,11 @@ async def _dispatch_inbound_event(
|
|||
event.last_error = "account_missing"
|
||||
await session.commit()
|
||||
return
|
||||
if _is_inactive_whatsapp_account(account):
|
||||
event.status = ExternalChatEventStatus.IGNORED
|
||||
event.last_error = "inactive_whatsapp_mode"
|
||||
await session.commit()
|
||||
return
|
||||
|
||||
try:
|
||||
bundle = resolve_platform_bundle(account)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue