From 6810f392cc5c1a4255842b13c2a0f9963f2b87a3 Mon Sep 17 00:00:00 2001 From: debu-2 Date: Sat, 3 Oct 2026 03:06:55 +0530 Subject: [PATCH] graph api fix --- backend/app/agent_message_service.py | 19 +++++++++++-------- docs/URMIPORT_AND_WHATSAPP_APIS.md | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/backend/app/agent_message_service.py b/backend/app/agent_message_service.py index 7e0b782..b0e9626 100644 --- a/backend/app/agent_message_service.py +++ b/backend/app/agent_message_service.py @@ -115,21 +115,24 @@ def _build_template_components( customer_name: str, report_url: str, ) -> list[dict]: - """Build Meta template components using positional variables. + """Build Meta template components for agent_run_completion. - agent_run_completion uses: - body {{1}} -> customer name - button {{1}} -> report URL path suffix OR full URL depending on Meta template config. - We pass the full hosted report URL for the button so the View Report link resolves correctly. + Meta template uses parameter_format=NAMED for the body (customer_name) and a + positional URL-button suffix for the View Report link. """ components: list[dict] = [ { "type": "body", - "parameters": [{"type": "text", "text": customer_name.strip()}], + "parameters": [ + { + "type": "text", + "parameter_name": "customer_name", + "text": customer_name.strip(), + } + ], } ] if template.button_label and template.button_url_base: - # Meta URL button: pass path suffix relative to button_url_base (e.g. desi-clans-test/2026-10-03) base = template.button_url_base.rstrip("/") button_param = report_url[len(base) + 1 :] if report_url.startswith(f"{base}/") else report_url components.append( @@ -319,6 +322,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.", - "The WhatsApp button uses positional template variables: body {{1}} = customer_name, button suffix = report_group/report_id.", + "Body uses named parameter customer_name; button URL suffix is report_group/report_id.", ], } diff --git a/docs/URMIPORT_AND_WHATSAPP_APIS.md b/docs/URMIPORT_AND_WHATSAPP_APIS.md index 891d3f2..45d5fe6 100644 --- a/docs/URMIPORT_AND_WHATSAPP_APIS.md +++ b/docs/URMIPORT_AND_WHATSAPP_APIS.md @@ -229,21 +229,21 @@ Authorization: Bearer urmi_live_ | **Slug** | `agent_run_completion` | | **Meta template name** | `agent_run_completion` | | **Header** | Agent Run Complete | -| **Body** | Hello {{1}}, your agent run is complete… | +| **Body** | Hello {{customer_name}}, your agent run is complete… | | **Button** | View Report → `https://urmiai.com/reports/{{1}}` | -The Meta template uses **positional** variables (not named): +| Component | Meta format | API field | Example | +|-----------|-------------|-----------|---------| +| Body | **Named** `customer_name` | `customer_name` | `Team Desi Clans` | +| Button URL | Positional `{{1}}` suffix | `report_group`/`report_id` | `desi-clans-test/2026-10-03` | -| Variable | Maps to API field | Example | -|----------|-------------------|---------| -| `{{1}}` (body) | `customer_name` | `Suyash` | -| `{{1}}` (button) | `report_group`/`report_id` path suffix | `desi-clans-test/2026-10-03` | - -Urmi sends the button suffix `desi-clans-test/2026-10-03` so the final link is: +Urmi sends the button suffix so the final link should be: `https://urmiai.com/reports/desi-clans-test/2026-10-03` -> **Common bug:** If body parameters are sent as named (`parameter_name`) instead of positional, Meta leaves `{{1}}` literal in the URL, producing broken links like `https://urmiai.com/reports/%7B%7B1%7D%7Ddesi-clans-test/2026-10-03`. +> **400 Invalid parameter:** Body must use named `parameter_name: "customer_name"` — positional body params fail on this template. +> +> **Broken button URL:** If the approved Meta template button URL contains a literal `{{1}}` prefix (e.g. `https://urmiai.com/reports/{{1}}{{1}}`), fix it in WhatsApp Manager → Message templates → edit button URL to `https://urmiai.com/reports/{{1}}` only. ### Example @@ -256,7 +256,8 @@ curl -X POST 'https://urmiai.com/api/v1/agent/messages/send' \ "to": "919149154337", "customer_name": "Suyash", "report_group": "desi-clans-test", - "report_id": "desi-clans-demo-v1" + "report_id": "2026-10-03", + "report_url": "https://urmiai.com/reports/desi-clans-test/2026-10-03" }' ```