mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-04 20:05:16 +02:00
feat(gateway): add WhatsApp gateway configuration
This commit is contained in:
parent
5048b0fd7c
commit
a6b2882275
3 changed files with 58 additions and 1 deletions
|
|
@ -7,10 +7,10 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||
|
||||
from app.config import config
|
||||
from app.db import (
|
||||
ExternalChatAccount,
|
||||
ExternalChatAccountMode,
|
||||
ExternalChatHealthStatus,
|
||||
ExternalChatPlatform,
|
||||
ExternalChatAccount,
|
||||
)
|
||||
from app.utils.oauth_security import TokenEncryption
|
||||
|
||||
|
|
@ -50,3 +50,31 @@ async def get_or_create_system_telegram_account(
|
|||
await session.flush()
|
||||
return account
|
||||
|
||||
|
||||
async def get_or_create_system_whatsapp_account(
|
||||
session: AsyncSession,
|
||||
) -> ExternalChatAccount:
|
||||
result = await session.execute(
|
||||
select(ExternalChatAccount).where(
|
||||
ExternalChatAccount.platform == ExternalChatPlatform.WHATSAPP,
|
||||
ExternalChatAccount.is_system_account.is_(True),
|
||||
)
|
||||
)
|
||||
account = result.scalars().first()
|
||||
if account is not None:
|
||||
return account
|
||||
account = ExternalChatAccount(
|
||||
platform=ExternalChatPlatform.WHATSAPP,
|
||||
mode=ExternalChatAccountMode.CLOUD_SHARED,
|
||||
is_system_account=True,
|
||||
cursor_state={
|
||||
"phone_number_id": config.WHATSAPP_SHARED_PHONE_NUMBER_ID,
|
||||
"display_phone_number": config.WHATSAPP_SHARED_DISPLAY_PHONE_NUMBER,
|
||||
"waba_id": config.WHATSAPP_SHARED_WABA_ID,
|
||||
},
|
||||
health_status=ExternalChatHealthStatus.UNKNOWN,
|
||||
)
|
||||
session.add(account)
|
||||
await session.flush()
|
||||
return account
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue