Skip to content

feat(alerts): add WhatsApp channel - #96

Open
faisalahammad wants to merge 5 commits into
WordPress:trunkfrom
faisalahammad:feature/95-whatsapp-alerts
Open

faisalahammad wants to merge 5 commits into
WordPress:trunkfrom
faisalahammad:feature/95-whatsapp-alerts

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #95

Adds WhatsApp as an alert channel. When an email fails, the plugin sends a message to up to 3 numbers through the Meta WhatsApp Cloud API, with no third party service in between.

The channel extends the shared Http_Channel base and builds its text from Alert_Message, both from #89.

Why?

Today alerts only go to Slack. Many site owners want the alert on their phone. WhatsApp only lets a business start a conversation with an approved template, so the site owner creates the template and the plugin fills in its variables.

How?

A new WhatsApp_Channel extends Http_Channel and is registered next to Slack through smtp_alert_channels.

Before:

$channels = apply_filters( 'smtp_alert_channels', array( new Slack_Channel() ) );

After:

$channels = apply_filters( 'smtp_alert_channels', array( new Slack_Channel(), new WhatsApp_Channel() ) );
  • Fields: access token (stored as a secret), phone number ID, recipient numbers, template name and template language (default en_US). Invalid values are removed and a settings error explains why.
  • The template needs six numbered body variables: site name, error, recipients, subject, number of failures and link to the email log.
  • Values are cleaned for template rules (no new lines, no runs of spaces, no empty values) and long ones are cut.
  • Requests go to Graph API v27.0 through Http_Channel::post_json(), so the timeout, no redirects, 429 handling and secret removal from errors come from the shared base. The token and the phone number ID are removed from error messages.
  • The site name, log link, test text and the cut of long values come from Alert_Message. A test alert has no log link, so variable 6 is -.
  • One message is sent per recipient, inside the request where the email failed. The limit is 3 recipients, so with an unreachable API the delay is about 15 seconds at most. Background sending is Alerts: send alerts in the background #88.
  • A third party channel that already uses the ID whatsapp is now ignored, because the first ID wins.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5, Claude Sonnet 5.5
Used for: Code, tests and documentation. I reviewed and tested the changes.

Testing Instructions

You need a Meta app with the WhatsApp product, an access token, a phone number ID and an approved template with six body variables. The readme FAQ has a sample template.

  1. Go to Tools > SMTP > Alerts, pick WhatsApp, fill in the fields and save.
  2. Check that the access token is not printed in the page source.
  3. Click "Send test alert to WhatsApp". The message arrives on the recipient phone.
  4. In the Settings tab, set a host that can not be reached (for example localhost, port 1) and send a test email. The email fails and an alert with the error arrives.
  5. Save a number without + or with (0). It is removed and a notice names it.

Testing done:

  • composer lint and composer phpstan pass.
  • npm run test-php on PHP 7.4: 776 tests, 2 skipped.
  • WP 7.1.5, PHP 8.3.37 sandbox with Twenty Twenty-Five: settings screen, test alert and failure alert, with the HTTP request to Meta intercepted. No message was sent to Meta.
  • Not covered by this automated testing: delivery to a real WhatsApp number with an approved template.

Screenshots or screencast

Before After
Before After

Checklist

  • I added or updated tests, and npm run test-php passes locally.
  • composer lint passes.
  • New settings can also be set with a wp-config constant and WP-CLI.
  • New personal data is covered by the privacy exporter, eraser and policy text.
  • No password, API key or token can appear in output, logs or error messages.

Unticked item: wp-config constants for channel keys are tracked in #87. The privacy policy text already names the enabled alert channel, so WhatsApp is listed there. The recipient numbers are staff numbers saved in the plugin settings. They are not stored in the email log, so the exporter and eraser do not need to cover them.

Changelog Entry

Added - WhatsApp alert channel through the Meta WhatsApp Cloud API.

Open WordPress Playground Preview

- Add a WhatsApp_Channel that sends alerts through the Meta WhatsApp
  Cloud API
- Register it next to Slack through smtp_alert_channels
- Validate the token, phone number ID, template and up to 5 recipients
- Add tests and document the setup in the readme files

WhatsApp only lets a business start a chat with an approved template, so
the plugin fills the variables of the template that the site owner
created. This gives site owners an alert on their phone without a third
party service in between.

Fixes WordPress#95
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: faisalahammad <faisalahammad@git.wordpress.org>
Co-authored-by: davidperezgar <davidperez@git.wordpress.org>
Co-authored-by: masteradhoc <masteradhoc@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@davidperezgar davidperezgar added this to the 1.3.0 milestone Dec 6, 2026

@davidperezgar davidperezgar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @faisalahammad, nice work. #97 is now in trunk, so this can move to the shared base before merge:

  1. Extend Http_Channel instead of implementing Alert_Channel, and replace post_message() with $this->post_json( $url, $message, array( 'Authorization' => 'Bearer ' . $token ) ). That gives the shared redaction (it also strips the phone number ID from the URL path, not just the token), the user agent, 2xx handling and the 429 / Retry-After message. TIMEOUT can go.
  2. Use Alert_Message for the site name, log URL, test text and truncate(), so WhatsApp says the same thing as Slack. Watch that get_log_url() is empty for a test alert, so {{6}} still needs the - fallback.
  3. Merge trunk (not rebase): AGENTS.md and readme.txt conflict. After the merge, Privacy::get_policy_text() names the enabled channel, so the privacy item in the checklist is partly covered. Please check that the text fits a channel that stores phone numbers.

Minor: 5 recipients × 5 s can block the failing request for 25 s. Consider 3 recipients until #88 lands.

Review done with help from Claude (AI); I checked the findings.

@faisalahammad

Copy link
Copy Markdown
Contributor Author

Thanks for the review @davidperezgar. All points are done in 1988161.

  1. WhatsApp_Channel now extends Http_Channel and sends with post_json(). I merged the current trunk first to get the base class.
  2. The site name, log link, test text and the cut of long values now come from Alert_Message. A test alert has no log link, so variable 6 is -.
  3. I lowered the limit to 3 recipients, as you suggested. The worst case is now about 15 seconds. The readme is updated.
  4. Privacy: the policy text already names the enabled channel, so WhatsApp is listed. The alert numbers are staff numbers in the settings and are not stored in the email log, so I did not change the exporter or eraser.

I also added tests for the headers, the phone number ID removal and the 429 case. The PR description is updated. Please have another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alerts: WhatsApp channel (Meta WhatsApp Cloud API)

2 participants