urmi-ai/backend/app/agent_templates_seed.py
2026-10-03 00:54:52 +05:30

63 lines
2.4 KiB
Python

from sqlalchemy import select
from sqlalchemy.orm import Session
from .models import AgentMessageTemplate
DEFAULT_AGENT_TEMPLATES = [
{
"slug": "agent_run_completion",
"name": "Agent Run Success",
"description": (
"Notify end users when an Urmi AI agent run completes, with a dynamic "
"View Report button linking to the completion report."
),
"header_text": "Agent Run Complete",
"body_preview": (
"Hello {{customer_name}}, your agent run is complete, you can access "
"the completion report at your URMI AI Portal."
),
"footer_text": "Thanks and regards, team - URMI AI",
"meta_template_name": "agent_run_completion",
"language": "en",
"category": "utility",
"parameters": [
{
"name": "{{1}}",
"type": "string",
"required": True,
"description": "Positional body variable — recipient display name",
"example": "Suyash",
},
{
"name": "{{2}}",
"type": "string",
"required": True,
"description": "Positional button variable — report path suffix (report_group/report_id)",
"example": "desi-clans-test/2026-10-03",
},
],
"button_label": "View Report",
"button_url_base": "https://urmiai.com/reports/",
},
]
def seed_agent_message_templates(db: Session) -> None:
for item in DEFAULT_AGENT_TEMPLATES:
existing = db.scalar(select(AgentMessageTemplate).where(AgentMessageTemplate.slug == item["slug"]))
if existing:
existing.name = item["name"]
existing.description = item["description"]
existing.header_text = item["header_text"]
existing.body_preview = item["body_preview"]
existing.footer_text = item["footer_text"]
existing.meta_template_name = item["meta_template_name"]
existing.language = item["language"]
existing.category = item["category"]
existing.parameters = item["parameters"]
existing.button_label = item["button_label"]
existing.button_url_base = item["button_url_base"]
existing.is_active = True
else:
db.add(AgentMessageTemplate(**item))
db.commit()