Add robust button placeholder detection and Meta delivery diagnostics
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
d4bfb522ac
commit
b7ad1218ce
@ -525,10 +525,15 @@ class WhatsAppService:
|
||||
# where {{1}} is replaced by a dynamic parameter
|
||||
if button_type == "URL" and button_url:
|
||||
button_param_key = tpl.get("button_param_key", "")
|
||||
logger.info(f"[WhatsApp] Button check - type={button_type}, url={button_url}, param_key={button_param_key}, has_placeholder={'{{{{1}}}}' in button_url}")
|
||||
|
||||
# More robust check for placeholder - handle different string encodings
|
||||
has_placeholder = "{{1}}" in button_url or "{" in button_url and "1" in button_url
|
||||
|
||||
logger.info(f"[WhatsApp] Button check - type={button_type}, url={button_url}, param_key={button_param_key}, has_placeholder={has_placeholder}")
|
||||
logger.debug(f"[WhatsApp] Button URL bytes: {button_url.encode('utf-8')}, param_key value: {button_param_key}")
|
||||
|
||||
# Check if URL has {{1}} placeholder for dynamic parameter
|
||||
if "{{1}}" in button_url and button_param_key:
|
||||
if has_placeholder and button_param_key:
|
||||
# Dynamic URL button - need to send the parameter value
|
||||
param_value = str(params.get(button_param_key, "")).strip()
|
||||
logger.info(f"[WhatsApp] Dynamic button - param_key={button_param_key}, param_value={param_value}")
|
||||
@ -544,7 +549,10 @@ class WhatsAppService:
|
||||
else:
|
||||
logger.warning(f"[WhatsApp] Button parameter '{button_param_key}' is empty! params keys: {list(params.keys())}")
|
||||
else:
|
||||
logger.warning(f"[WhatsApp] Button conditions not met - url has placeholder: {'{{{{1}}}}' in button_url}, has param_key: {bool(button_param_key)}")
|
||||
if button_type == "URL" and button_url and not has_placeholder:
|
||||
logger.info(f"[WhatsApp] Static URL button (no {{{{1}}}}) - URL will be used as-is: {button_url}")
|
||||
else:
|
||||
logger.warning(f"[WhatsApp] Button not sent - has_placeholder={has_placeholder}, has_param_key={bool(button_param_key)}")
|
||||
|
||||
# Handle url_button component if defined in template (legacy dynamic buttons)
|
||||
url_btn = tpl.get("url_button", {})
|
||||
@ -640,6 +648,15 @@ class WhatsAppService:
|
||||
f"[WhatsApp] Message sent successfully! ID: {message_id}\n"
|
||||
f"Template: {meta_name}, To: {to_e164}, Status: {response.status_code}"
|
||||
)
|
||||
logger.info(
|
||||
f"[WhatsApp] NOTE: HTTP 200 OK only means Meta accepted it.\n"
|
||||
f"For delivery status (sent/delivered/read/failed), check webhooks or use Meta's Message Status API.\n"
|
||||
f"Common reasons for silent failure:\n"
|
||||
f" - Template '{meta_name}' not APPROVED in Meta Business Manager\n"
|
||||
f" - Phone number {to_e164} not on whitelist (for test mode)\n"
|
||||
f" - Business account in test/development mode\n"
|
||||
f" - Template format doesn't match approved structure"
|
||||
)
|
||||
|
||||
# Save message to database for status tracking
|
||||
if self.db:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user