mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +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
|
|
@ -553,6 +553,23 @@ class Config:
|
|||
raise ValueError(
|
||||
"GATEWAY_TELEGRAM_INTAKE_MODE must be one of: webhook, longpoll, disabled"
|
||||
)
|
||||
WHATSAPP_SHARED_BUSINESS_TOKEN = os.getenv("WHATSAPP_SHARED_BUSINESS_TOKEN")
|
||||
WHATSAPP_SHARED_PHONE_NUMBER_ID = os.getenv("WHATSAPP_SHARED_PHONE_NUMBER_ID")
|
||||
WHATSAPP_SHARED_DISPLAY_PHONE_NUMBER = os.getenv(
|
||||
"WHATSAPP_SHARED_DISPLAY_PHONE_NUMBER"
|
||||
)
|
||||
WHATSAPP_SHARED_WABA_ID = os.getenv("WHATSAPP_SHARED_WABA_ID")
|
||||
WHATSAPP_GRAPH_API_VERSION = os.getenv("WHATSAPP_GRAPH_API_VERSION", "v25.0")
|
||||
WHATSAPP_WEBHOOK_VERIFY_TOKEN = os.getenv("WHATSAPP_WEBHOOK_VERIFY_TOKEN")
|
||||
WHATSAPP_WEBHOOK_APP_SECRET = os.getenv("WHATSAPP_WEBHOOK_APP_SECRET")
|
||||
WHATSAPP_BRIDGE_URL = os.getenv("WHATSAPP_BRIDGE_URL", "http://whatsapp-bridge:3000")
|
||||
GATEWAY_WHATSAPP_INTAKE_MODE = os.getenv(
|
||||
"GATEWAY_WHATSAPP_INTAKE_MODE", "disabled"
|
||||
).lower()
|
||||
if GATEWAY_WHATSAPP_INTAKE_MODE not in {"cloud", "baileys", "disabled"}:
|
||||
raise ValueError(
|
||||
"GATEWAY_WHATSAPP_INTAKE_MODE must be one of: cloud, baileys, disabled"
|
||||
)
|
||||
|
||||
# Stripe checkout for pay-as-you-go page packs
|
||||
STRIPE_SECRET_KEY = os.getenv("STRIPE_SECRET_KEY")
|
||||
|
|
|
|||
|
|
@ -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