Spaces:
Runtime error
Runtime error
Commit ·
99e77b9
1
Parent(s): 0cbb7b5
fix: map WATI template params to positional keys (1, 2, ...) instead of named keys
Browse files- app/channels/whatsapp.py +20 -4
app/channels/whatsapp.py
CHANGED
|
@@ -54,10 +54,26 @@ class WhatsAppChannel:
|
|
| 54 |
"Content-Type": "application/json",
|
| 55 |
}
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
url = f"{api_endpoint}/api/v1/sendTemplateMessage"
|
| 63 |
payload = {
|
|
|
|
| 54 |
"Content-Type": "application/json",
|
| 55 |
}
|
| 56 |
|
| 57 |
+
# WATI templates use positional params named "1", "2", etc.
|
| 58 |
+
# If template_data contains positional keys ("1", "2", ...) use them directly.
|
| 59 |
+
# Otherwise map the canonical fields: otp → "1", expiry_minutes → "2".
|
| 60 |
+
has_positional = any(str(k).isdigit() for k in template_data)
|
| 61 |
+
if has_positional:
|
| 62 |
+
parameters = [
|
| 63 |
+
{"name": str(k), "value": str(v)}
|
| 64 |
+
for k, v in template_data.items()
|
| 65 |
+
if str(k).isdigit()
|
| 66 |
+
]
|
| 67 |
+
else:
|
| 68 |
+
# Build positional params from canonical keys in order
|
| 69 |
+
ordered_keys = ["otp", "expiry_minutes", "merchant_name"]
|
| 70 |
+
positional = [
|
| 71 |
+
template_data[k] for k in ordered_keys if k in template_data and template_data[k] not in (None, "")
|
| 72 |
+
]
|
| 73 |
+
parameters = [
|
| 74 |
+
{"name": str(i + 1), "value": str(v)}
|
| 75 |
+
for i, v in enumerate(positional)
|
| 76 |
+
]
|
| 77 |
|
| 78 |
url = f"{api_endpoint}/api/v1/sendTemplateMessage"
|
| 79 |
payload = {
|