Repository navigation
feat(messaging): carry an Android notification channel on push messages - #13945
Conversation
…ages Push messages carried no channel id, so FCM delivered every notification on the app's default channel and Android users could not mute a category. createPush and updatePush now take an optional channelId, stored alongside the other push fields in the message data. The FCM adapter sends it as android.notification.channel_id and the Appwrite adapter puts it on the envelope next to tag.
🟢 Tier S · Ready to merge
This PR adds an optional Android notification channel ID to push-message creation and updates, stores it in message data, and carries it through the messaging worker to the FCM and Appwrite push adapters. FCM payload tests cover channel inclusion and omission, while MQTT end-to-end tests cover delivery and clearing a channel ID before sending a draft. Latest changes: The newest commits allow an empty channel ID on push updates to clear a previously set channel, and add MQTT end-to-end tests for channel delivery and clearing.
📂 Walkthrough · 8
Reviewed the commits since |
|
| if (!\is_null($channelId)) { | ||
| $pushData['channelId'] = $channelId; |
There was a problem hiding this comment.
Stored channel cannot be cleared
If a draft or scheduled push message already has a channel ID, updating it with null leaves the stored ID unchanged, while an empty string fails validation. Callers therefore cannot return that message to the app’s default notification channel.
Knowledge Base Used: Messaging delivery API
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Update.php
Line: 287-288
Comment:
**Stored channel cannot be cleared**
If a draft or scheduled push message already has a channel ID, updating it with `null` leaves the stored ID unchanged, while an empty string fails validation. Callers therefore cannot return that message to the app’s default notification channel.
**Knowledge Base Used:** [Messaging delivery API](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/appwrite/appwrite/-/docs/messaging-api.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| $stub->send(new Push( | ||
| to: ['token'], | ||
| title: 'Title', | ||
| body: 'Body', | ||
| channelId: 'reminders', | ||
| )); |
There was a problem hiding this comment.
Tests skip the message handoff
These tests supply channelId directly to Push, so they verify the FCM request but not whether create or update stores the field and the worker passes it along. A break in that handoff could leave the new API parameter ineffective while both tests pass. Add a delivery-path test that checks the resulting provider request.
Knowledge Base Used: Messaging delivery API
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/messaging/tests/Adapter/Push/FCMTest.php
Line: 17-22
Comment:
**Tests skip the message handoff**
These tests supply `channelId` directly to `Push`, so they verify the FCM request but not whether create or update stores the field and the worker passes it along. A break in that handoff could leave the new API parameter ineffective while both tests pass. Add a delivery-path test that checks the resulting provider request.
**Knowledge Base Used:** [Messaging delivery API](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/appwrite/appwrite/-/docs/messaging-api.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
# Conflicts: # src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Update.php
A stored channelId could not be removed: null leaves the field as it is, and an empty string failed validation. Accept an empty string on update and drop the key, so a draft or scheduled message can go back to the app's default channel. Removing the key rather than storing an empty value keeps the adapters from emitting an empty channel. Cover the channel end to end through the MQTT broker: a campaign carries it to a live subscriber, and a draft sent with its channel cleared arrives without one.
What does this PR do?
FCM never emitted a notification channel, so every Appwrite push landed in the receiving app's default channel and Android users could not mute categories independently.
Adds an optional
channelIdend to end:POST /v1/messaging/messages/pushandPATCH /v1/messaging/messages/push/:messageIdaccept it, it is stored in the messagedataJSON,buildPushMessage()reads it back, and the FCM adapter emits it on the Android notification. No schema or Response model change is needed — push fields live in thedataattribute andModel/Message.phpexposesdataas one generic rule.Three decisions worth calling out:
channel_id, notnotification_channel_id. The latter is a legacyfcm/sendname and does not exist in FCM HTTP v1.AndroidNotificationhas exactly one field for this. FCM v1 rejects unknown JSON fields with400 INVALID_ARGUMENT, so the legacy name would have broken every push that set a channel rather than silently dropping it. Verified against the FirebaseAndroidNotificationreference.channel_idalso matches the adapter's existingclick_action.a461198547appendedcriticalandpriorityat the end rather than grouping them with the iOS params.src/Appwrite/Messaging/Adapter/Push/Appwrite.phpalready carriestag, the exact Android-only sibling, and its docblock says it mirrors the FCM/APNS shape; omittingchannelIdthere would silently drop it for that provider.Update.phpfollows the local convention for every other field in that action: aNullablevalidator plus an!\is_null()guard, so passing null does not clear a previously set channel.Test Plan
composer linton every changed PHP file →{"tool":"pint","result":"passed"}packages/messaging/tests/Adapter/Push/FCMTest.php, two cases, following theSendgridHeadersTestnamed-stub precedent in the same tree — a stub subclass capturing request bodies, no mocks and no reflection. Run and watched: passing.Not run: no e2e. Every push route test lives in
tests/e2e/Services/Messaging/MessagingBase.php, which has uncommitted changes in another branch right now, so it was left untouched. The new HTTP params want e2e coverage there once that settles.Related PRs and Issues
Checklist