import os import json from app.providers.whatsapp_cloud import WhatsAppCloudProvider def main() -> None: to_number = os.getenv("WHATSAPP_TEST_TO", "") if not to_number: raise SystemExit("ERROR: Set WHATSAPP_TEST_TO to an E.164 number (e.g., 14155552671 or +14155552671)") template_name = os.getenv("WHATSAPP_TEMPLATE_NAME", "hello_world") template_language = os.getenv("WHATSAPP_TEMPLATE_LANGUAGE", "en_US") first_name = os.getenv("WHATSAPP_TEST_FIRST_NAME", "Friend") # Determine template body based on template name # hello_world has NO variables (no {{...}}) # custom_hello_world has {{first_name}} if template_name == "hello_world": template_body = "Hello World" # No variables variables = {} else: template_body = "Hello {{first_name}}, welcome!" # Has variable variables = {"first_name": first_name} print(f"\n{'='*70}") print(f"WhatsApp Cloud Template Debug Test") print(f"{'='*70}") print(f"Phone Number: {to_number}") print(f"Template Name: {template_name}") print(f"Template Language: {template_language}") print(f"Template Body: {template_body}") print(f"Variables: {variables}") print(f"{'='*70}\n") try: provider = WhatsAppCloudProvider() message_id = provider.send_message( to=to_number, template_name=template_name, template_body=template_body, variables=variables, language=template_language ) print(f"✅ SUCCESS: Message sent with ID: {message_id}\n") return 0 except Exception as e: print(f"❌ FAILED: {str(e)}\n") return 1 if __name__ == "__main__": exit(main())