71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to verify WhatsApp template payload structure is correct
|
|
"""
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from whatsapp import WhatsAppService
|
|
import json
|
|
|
|
# Sample template parameters (7 required)
|
|
parameters = [
|
|
"דוד", # {{1}} contact_name
|
|
"דוד", # {{2}} groom_name
|
|
"שרה", # {{3}} bride_name
|
|
"אולם בן-גוריון", # {{4}} hall_name
|
|
"15/06", # {{5}} event_date
|
|
"18:30", # {{6}} event_time
|
|
"https://invy.dvirlabs.com/guest?event=123" # {{7}} guest_link
|
|
]
|
|
|
|
print("=" * 80)
|
|
print("WhatsApp Template Payload Test")
|
|
print("=" * 80)
|
|
|
|
print("\nTesting parameter validation...")
|
|
try:
|
|
WhatsAppService.validate_template_params(parameters, expected_count=7)
|
|
print(f"✓ Parameter validation passed: {len(parameters)} parameters")
|
|
for i, p in enumerate(parameters, 1):
|
|
display = p if len(p) < 40 else f"{p[:30]}...{p[-5:]}"
|
|
print(f" {{{{%d}}}} = {display}" % i)
|
|
except Exception as e:
|
|
print(f"✗ Validation failed: {e}")
|
|
sys.exit(1)
|
|
|
|
print("\nExpected Meta API payload structure:")
|
|
expected_payload = {
|
|
"messaging_product": "whatsapp",
|
|
"to": "+972541234567",
|
|
"type": "template",
|
|
"template": {
|
|
"name": "wedding_invitation",
|
|
"language": {
|
|
"code": "he"
|
|
},
|
|
"components": [
|
|
{
|
|
"type": "body",
|
|
"parameters": [
|
|
{"type": "text", "text": param}
|
|
for param in parameters
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
|
|
print(json.dumps(expected_payload, indent=2, ensure_ascii=False))
|
|
|
|
print("\n" + "=" * 80)
|
|
print("Validation Results:")
|
|
print("=" * 80)
|
|
print(f"✓ Parameters: {len(parameters)}/7")
|
|
print(f"✓ Structure: Valid (has 'components' array)")
|
|
print(f"✓ Template name: wedding_invitation")
|
|
print(f"✓ Language code: he")
|
|
print("\n✓ All validations passed! Ready to send to Meta API.")
|
|
print("=" * 80)
|