mirror of
http://88.130.71.182:3000/BlitTech/contexta_be.git
synced 2026-06-12 23:23:21 +00:00
updates Mar6
This commit is contained in:
@@ -73,6 +73,14 @@ async def create_chatbot(data: ChatbotCreate, user=Depends(get_current_user)):
|
||||
"visibility": "preview",
|
||||
"is_published": False,
|
||||
"qdrant_collection_name": collection_name,
|
||||
"show_branding": data.show_branding,
|
||||
"lead_capture_enabled": data.lead_capture_enabled,
|
||||
"lead_capture_fields": data.lead_capture_fields,
|
||||
"lead_capture_trigger": data.lead_capture_trigger,
|
||||
"handoff_enabled": data.handoff_enabled,
|
||||
"handoff_message": data.handoff_message,
|
||||
"handoff_email": data.handoff_email,
|
||||
"handoff_keywords": data.handoff_keywords,
|
||||
}
|
||||
|
||||
result = supabase.table("chatbots").insert(chatbot_data).execute()
|
||||
@@ -180,8 +188,8 @@ async def export_chatbot(chatbot_id: str, user=Depends(get_current_user)):
|
||||
# Check plan
|
||||
sub = supabase.table("subscriptions").select("plan").eq("user_id", user.id).eq("status", "active").execute()
|
||||
plan = sub.data[0]["plan"] if sub.data else "free"
|
||||
if plan not in ("pro", "enterprise"):
|
||||
raise HTTPException(status_code=402, detail="Code export requires Pro plan or higher")
|
||||
if plan not in ("agency", "enterprise"):
|
||||
raise HTTPException(status_code=402, detail="Code export requires Agency plan or higher")
|
||||
|
||||
zip_bytes = generate_export_package(
|
||||
chatbot=chatbot,
|
||||
@@ -198,6 +206,55 @@ async def export_chatbot(chatbot_id: str, user=Depends(get_current_user)):
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{chatbot_id}/public")
|
||||
async def get_chatbot_public(chatbot_id: str):
|
||||
"""Public endpoint - returns basic info for a published chatbot (used by PublicChatPage)."""
|
||||
supabase = get_supabase()
|
||||
result = supabase.table("chatbots").select("id, name, welcome_message, primary_color, logo_url, show_branding, is_published, description").eq("id", chatbot_id).execute()
|
||||
if not result.data:
|
||||
raise HTTPException(status_code=404, detail="Chatbot not found")
|
||||
chatbot = result.data[0]
|
||||
if not chatbot.get("is_published"):
|
||||
raise HTTPException(status_code=404, detail="Chatbot not found or not published")
|
||||
return {
|
||||
"id": chatbot["id"],
|
||||
"name": chatbot["name"],
|
||||
"welcome_message": chatbot.get("welcome_message", "Hello! How can I help?"),
|
||||
"primary_color": chatbot.get("primary_color", "#6366f1"),
|
||||
"logo_url": chatbot.get("logo_url"),
|
||||
"show_branding": chatbot.get("show_branding", True),
|
||||
"is_published": chatbot.get("is_published", False),
|
||||
"description": chatbot.get("description"),
|
||||
}
|
||||
|
||||
|
||||
@router.get("/{chatbot_id}/embed")
|
||||
async def get_chatbot_embed(chatbot_id: str, user=Depends(get_current_user)):
|
||||
"""Returns embed info including the widget script tag for a chatbot."""
|
||||
from app.config import settings
|
||||
supabase = get_supabase()
|
||||
company = _get_user_company(user.id, supabase)
|
||||
chatbot = _get_owned_chatbot(chatbot_id, company["id"], supabase)
|
||||
|
||||
api_url = "http://localhost:8000" # In production, read from settings
|
||||
app_url = settings.app_url
|
||||
|
||||
embed_script = f'<script src="{api_url}/widget.js" data-chatbot="{chatbot_id}"></script>'
|
||||
chat_url = f"{app_url}/chat/{chatbot_id}"
|
||||
|
||||
return {
|
||||
"chatbot_id": chatbot_id,
|
||||
"name": chatbot.get("name"),
|
||||
"primary_color": chatbot.get("primary_color", "#6366f1"),
|
||||
"welcome_message": chatbot.get("welcome_message"),
|
||||
"logo_url": chatbot.get("logo_url"),
|
||||
"show_branding": chatbot.get("show_branding", True),
|
||||
"embed_script": embed_script,
|
||||
"chat_url": chat_url,
|
||||
"is_published": chatbot.get("is_published", False),
|
||||
}
|
||||
|
||||
|
||||
# ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
def _get_owned_chatbot(chatbot_id: str, company_id: str, supabase) -> dict:
|
||||
@@ -238,4 +295,12 @@ def _format_chatbot(chatbot: dict, supabase) -> ChatbotResponse:
|
||||
conversation_count=conv_count.count or 0,
|
||||
created_at=chatbot.get("created_at"),
|
||||
published_at=chatbot.get("published_at"),
|
||||
show_branding=chatbot.get("show_branding", True),
|
||||
lead_capture_enabled=chatbot.get("lead_capture_enabled", False),
|
||||
lead_capture_fields=chatbot.get("lead_capture_fields") or ["email"],
|
||||
lead_capture_trigger=chatbot.get("lead_capture_trigger", "after_first_message"),
|
||||
handoff_enabled=chatbot.get("handoff_enabled", False),
|
||||
handoff_message=chatbot.get("handoff_message", "I'll connect you with our team. Please wait."),
|
||||
handoff_email=chatbot.get("handoff_email"),
|
||||
handoff_keywords=chatbot.get("handoff_keywords") or ["human", "agent", "speak to someone", "talk to a person", "real person"],
|
||||
)
|
||||
Reference in New Issue
Block a user