meta api fix
This commit is contained in:
parent
6810f392cc
commit
e98036cd31
5 changed files with 33 additions and 50 deletions
|
|
@ -24,7 +24,6 @@ class SendAgentMessagePayload(BaseModel):
|
|||
customer_name: str = Field(min_length=1, max_length=120)
|
||||
report_group: str = Field(min_length=3, max_length=50)
|
||||
report_id: str | None = Field(default=None, max_length=120)
|
||||
report_url: str | None = Field(default=None, max_length=500)
|
||||
|
||||
|
||||
def serialize_agent_template(template: AgentMessageTemplate, *, subscribed: bool = False) -> dict:
|
||||
|
|
@ -98,14 +97,7 @@ def _validate_report_id(report_id: str) -> str:
|
|||
return cleaned
|
||||
|
||||
|
||||
def _build_report_url(
|
||||
template: AgentMessageTemplate,
|
||||
report_group: str,
|
||||
report_id: str,
|
||||
override: str | None = None,
|
||||
) -> str:
|
||||
if override:
|
||||
return override.strip()
|
||||
def _report_url(template: AgentMessageTemplate, report_group: str, report_id: str) -> str:
|
||||
base = (template.button_url_base or "https://urmiai.com/reports/").rstrip("/")
|
||||
return f"{base}/{report_group}/{report_id}"
|
||||
|
||||
|
|
@ -113,12 +105,13 @@ def _build_report_url(
|
|||
def _build_template_components(
|
||||
template: AgentMessageTemplate,
|
||||
customer_name: str,
|
||||
report_url: str,
|
||||
report_group: str,
|
||||
report_id: str,
|
||||
) -> list[dict]:
|
||||
"""Build Meta template components for agent_run_completion.
|
||||
"""Build Meta components for agent_run_completion_v2.
|
||||
|
||||
Meta template uses parameter_format=NAMED for the body (customer_name) and a
|
||||
positional URL-button suffix for the View Report link.
|
||||
Body uses named customer_name. Button suffix is report_group/report_id only —
|
||||
never derived from a posted report_url.
|
||||
"""
|
||||
components: list[dict] = [
|
||||
{
|
||||
|
|
@ -133,14 +126,12 @@ def _build_template_components(
|
|||
}
|
||||
]
|
||||
if template.button_label and template.button_url_base:
|
||||
base = template.button_url_base.rstrip("/")
|
||||
button_param = report_url[len(base) + 1 :] if report_url.startswith(f"{base}/") else report_url
|
||||
components.append(
|
||||
{
|
||||
"type": "button",
|
||||
"sub_type": "url",
|
||||
"index": "0",
|
||||
"parameters": [{"type": "text", "text": button_param}],
|
||||
"parameters": [{"type": "text", "text": f"{report_group}/{report_id}"}],
|
||||
}
|
||||
)
|
||||
return components
|
||||
|
|
@ -167,8 +158,8 @@ async def send_agent_template_message(
|
|||
|
||||
report_group = _validate_report_group(payload.report_group)
|
||||
report_id = _validate_report_id(payload.report_id or f"run-{secrets.token_hex(3)}")
|
||||
report_url = _build_report_url(template, report_group, report_id, payload.report_url)
|
||||
components = _build_template_components(template, payload.customer_name, report_url)
|
||||
components = _build_template_components(template, payload.customer_name, report_group, report_id)
|
||||
report_url = _report_url(template, report_group, report_id)
|
||||
|
||||
client = _whatsapp_client(db)
|
||||
try:
|
||||
|
|
@ -295,7 +286,6 @@ def build_agent_message_docs(template: AgentMessageTemplate) -> dict:
|
|||
"customer_name": "Recipient name inserted into the template body",
|
||||
"report_group": "Urmiport report group slug used in the hosted report URL",
|
||||
"report_id": "Optional report postfix; auto-generated when omitted",
|
||||
"report_url": "Optional full report URL override for the WhatsApp button (auto-built when omitted)",
|
||||
},
|
||||
"example": {
|
||||
"template": template.slug,
|
||||
|
|
@ -303,7 +293,6 @@ def build_agent_message_docs(template: AgentMessageTemplate) -> dict:
|
|||
"customer_name": "Suyash",
|
||||
"report_group": "desi-clans-test",
|
||||
"report_id": "2026-10-03",
|
||||
"report_url": "https://urmiai.com/reports/desi-clans-test/2026-10-03",
|
||||
},
|
||||
"response_example": {
|
||||
"success": True,
|
||||
|
|
@ -322,6 +311,6 @@ def build_agent_message_docs(template: AgentMessageTemplate) -> dict:
|
|||
"Messages are sent from the Urmi AI WhatsApp business number on your behalf.",
|
||||
"Create the report group in Console → Agent → Urmiport before sending.",
|
||||
"If report_id is omitted, Urmi generates a unique postfix automatically.",
|
||||
"Body uses named parameter customer_name; button URL suffix is report_group/report_id.",
|
||||
"Uses Meta template agent_run_completion_v2. Button suffix is built from report_group/report_id only.",
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,29 +11,36 @@ DEFAULT_AGENT_TEMPLATES = [
|
|||
"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",
|
||||
"header_text": "Agent Run Successful",
|
||||
"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",
|
||||
"meta_template_name": "agent_run_completion_v2",
|
||||
"language": "en",
|
||||
"category": "utility",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "{{1}}",
|
||||
"name": "customer_name",
|
||||
"type": "string",
|
||||
"required": True,
|
||||
"description": "Positional body variable — recipient display name",
|
||||
"description": "Recipient display name (template body variable)",
|
||||
"example": "Suyash",
|
||||
},
|
||||
{
|
||||
"name": "{{2}}",
|
||||
"name": "report_group",
|
||||
"type": "string",
|
||||
"required": True,
|
||||
"description": "Positional button variable — report path suffix (report_group/report_id)",
|
||||
"example": "desi-clans-test/2026-10-03",
|
||||
"description": "Urmiport report group slug",
|
||||
"example": "desi-clans-test",
|
||||
},
|
||||
{
|
||||
"name": "report_id",
|
||||
"type": "string",
|
||||
"required": True,
|
||||
"description": "Report postfix; combined with report_group for the button URL suffix",
|
||||
"example": "2026-10-03",
|
||||
},
|
||||
],
|
||||
"button_label": "View Report",
|
||||
|
|
|
|||
|
|
@ -57,12 +57,6 @@ def _explorer_doc_for_template(template: AgentMessageTemplate) -> dict:
|
|||
"description": "Report postfix; auto-generated when omitted",
|
||||
"example": "2026-10-03",
|
||||
},
|
||||
"report_url": {
|
||||
"type": "string",
|
||||
"required": False,
|
||||
"description": "Full hosted report URL for the WhatsApp button; auto-built when omitted",
|
||||
"example": "https://urmiai.com/reports/desi-clans-test/2026-10-03",
|
||||
},
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue