graph api fix
This commit is contained in:
parent
248acba741
commit
6810f392cc
2 changed files with 22 additions and 18 deletions
|
|
@ -115,21 +115,24 @@ def _build_template_components(
|
||||||
customer_name: str,
|
customer_name: str,
|
||||||
report_url: str,
|
report_url: str,
|
||||||
) -> list[dict]:
|
) -> list[dict]:
|
||||||
"""Build Meta template components using positional variables.
|
"""Build Meta template components for agent_run_completion.
|
||||||
|
|
||||||
agent_run_completion uses:
|
Meta template uses parameter_format=NAMED for the body (customer_name) and a
|
||||||
body {{1}} -> customer name
|
positional URL-button suffix for the View Report link.
|
||||||
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.
|
|
||||||
"""
|
"""
|
||||||
components: list[dict] = [
|
components: list[dict] = [
|
||||||
{
|
{
|
||||||
"type": "body",
|
"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:
|
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("/")
|
base = template.button_url_base.rstrip("/")
|
||||||
button_param = report_url[len(base) + 1 :] if report_url.startswith(f"{base}/") else report_url
|
button_param = report_url[len(base) + 1 :] if report_url.startswith(f"{base}/") else report_url
|
||||||
components.append(
|
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.",
|
"Messages are sent from the Urmi AI WhatsApp business number on your behalf.",
|
||||||
"Create the report group in Console → Agent → Urmiport before sending.",
|
"Create the report group in Console → Agent → Urmiport before sending.",
|
||||||
"If report_id is omitted, Urmi generates a unique postfix automatically.",
|
"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.",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -229,21 +229,21 @@ Authorization: Bearer urmi_live_<your_api_key>
|
||||||
| **Slug** | `agent_run_completion` |
|
| **Slug** | `agent_run_completion` |
|
||||||
| **Meta template name** | `agent_run_completion` |
|
| **Meta template name** | `agent_run_completion` |
|
||||||
| **Header** | Agent Run Complete |
|
| **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}}` |
|
| **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 |
|
Urmi sends the button suffix so the final link should be:
|
||||||
|----------|-------------------|---------|
|
|
||||||
| `{{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:
|
|
||||||
|
|
||||||
`https://urmiai.com/reports/desi-clans-test/2026-10-03`
|
`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
|
### Example
|
||||||
|
|
||||||
|
|
@ -256,7 +256,8 @@ curl -X POST 'https://urmiai.com/api/v1/agent/messages/send' \
|
||||||
"to": "919149154337",
|
"to": "919149154337",
|
||||||
"customer_name": "Suyash",
|
"customer_name": "Suyash",
|
||||||
"report_group": "desi-clans-test",
|
"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"
|
||||||
}'
|
}'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue