- Backend: FastAPI app with all models, services, schemas, routes - Admin Panel: Next.js dashboard with all modules (CRM, POS, repairs, warranties, billing, notifications, etc.) - Ecommerce: storefront (submodule) + product catalog - AI Agents: .agents/ skill library for Antigravity IDE - Docs: architecture, billing, notification gateway markdown - Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
63 lines
2.5 KiB
Python
63 lines
2.5 KiB
Python
import sys
|
|
import os
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from app.core.database.db_session import SessionLocal
|
|
from app.services.NotificationGatewayService import NotificationGatewayService
|
|
from app.services.TemplateService import TemplateService, EVENT_REGISTRY
|
|
from app.schemas.NotificationGateway import NotificationDispatchCreate
|
|
|
|
def run_tests():
|
|
db = SessionLocal()
|
|
tenant_id = "tenant_default"
|
|
|
|
for event_key, data in EVENT_REGISTRY.items():
|
|
print(f"Triggering {event_key}...")
|
|
|
|
# Build mock context
|
|
mock_context = {}
|
|
for var in data["variables"]:
|
|
if var["name"] == "items":
|
|
mock_context["items"] = [{"product_name": "Test Item 1", "sku": "SKU-1", "quantity": 1, "unit_price": 500}]
|
|
else:
|
|
name_val = var.get("name")
|
|
mock_context[var["name"]] = var.get("example", f"[{name_val}]")
|
|
|
|
# Try for EMAIL
|
|
rendered_email = TemplateService.render_template(db, event_key, "EMAIL", mock_context, tenant_id)
|
|
if not rendered_email:
|
|
rendered_email = (f"Test Subject: {event_key}", f"<p>This is a test fallback email for {event_key}. Context: {mock_context}</p>")
|
|
|
|
subj, body = rendered_email
|
|
payload = NotificationDispatchCreate(
|
|
recipient="adithiyan.elan@gmail.com",
|
|
channel="EMAIL",
|
|
subject=subj,
|
|
message_body=body
|
|
)
|
|
try:
|
|
NotificationGatewayService.dispatch_notification(db, tenant_id, payload)
|
|
print(f" -> Dispatched EMAIL (rerouted to Adithiyan)")
|
|
except Exception as e:
|
|
print(f" -> EMAIL failed: {e}")
|
|
|
|
# Try for WHATSAPP
|
|
rendered_wa = TemplateService.render_template(db, event_key, "WHATSAPP", mock_context, tenant_id)
|
|
if not rendered_wa:
|
|
rendered_wa = (None, f"[Test {event_key}] Context: {mock_context}")
|
|
|
|
subj, body = rendered_wa
|
|
payload = NotificationDispatchCreate(
|
|
recipient="919080323589",
|
|
channel="WHATSAPP",
|
|
subject=subj,
|
|
message_body=body
|
|
)
|
|
try:
|
|
NotificationGatewayService.dispatch_notification(db, tenant_id, payload)
|
|
print(f" -> Dispatched WHATSAPP (rerouted to Adithiyan)")
|
|
except Exception as e:
|
|
print(f" -> WHATSAPP failed: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
run_tests()
|