Repository navigation
feat(alerts): add WhatsApp channel - #96
faisalahammad wants to merge 5 commits into
Conversation
- 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
|
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. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
davidperezgar
left a comment
There was a problem hiding this comment.
Thanks @faisalahammad, nice work. #97 is now in trunk, so this can move to the shared base before merge:
- Extend
Http_Channelinstead of implementingAlert_Channel, and replacepost_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.TIMEOUTcan go. - Use
Alert_Messagefor the site name, log URL, test text andtruncate(), so WhatsApp says the same thing as Slack. Watch thatget_log_url()is empty for a test alert, so{{6}}still needs the-fallback. - Merge trunk (not rebase):
AGENTS.mdandreadme.txtconflict. 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.
Limit WhatsApp recipients to 3. Refs WordPress#96
|
Thanks for the review @davidperezgar. All points are done in 1988161.
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. |
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_Channelbase and builds its text fromAlert_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_ChannelextendsHttp_Channeland is registered next to Slack throughsmtp_alert_channels.Before:
After:
en_US). Invalid values are removed and a settings error explains why.v27.0throughHttp_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.Alert_Message. A test alert has no log link, so variable 6 is-.whatsappis 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.
localhost, port1) and send a test email. The email fails and an alert with the error arrives.+or with(0). It is removed and a notice names it.Testing done:
composer lintandcomposer phpstanpass.npm run test-phpon PHP 7.4: 776 tests, 2 skipped.Screenshots or screencast
Checklist
npm run test-phppasses locally.composer lintpasses.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