Skip to content

feat(messaging): carry an Android notification channel on push messages - #13945

Merged
HarshMN2345 merged 3 commits into
mainfrom
fix/issue-8086
Sep 29, 2026
Merged

HarshMN2345 merged 3 commits into
mainfrom
fix/issue-8086

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

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 channelId end to end: POST /v1/messaging/messages/push and PATCH /v1/messaging/messages/push/:messageId accept it, it is stored in the message data JSON, 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 the data attribute and Model/Message.php exposes data as one generic rule.

Three decisions worth calling out:

  1. Field name is channel_id, not notification_channel_id. The latter is a legacy fcm/send name and does not exist in FCM HTTP v1. AndroidNotification has exactly one field for this. FCM v1 rejects unknown JSON fields with 400 INVALID_ARGUMENT, so the legacy name would have broken every push that set a channel rather than silently dropping it. Verified against the Firebase AndroidNotification reference. channel_id also matches the adapter's existing click_action.
  2. The param is appended, not grouped with the other Android params. Generated SDKs expose these positionally, so inserting mid-list is a silent breaking change. Repo history agrees — a461198547 appended critical and priority at the end rather than grouping them with the iOS params.
  3. The in-house MQTT fan-out adapter gets it too. src/Appwrite/Messaging/Adapter/Push/Appwrite.php already carries tag, the exact Android-only sibling, and its docblock says it mirrors the FCM/APNS shape; omitting channelId there would silently drop it for that provider.

Update.php follows the local convention for every other field in that action: a Nullable validator plus an !\is_null() guard, so passing null does not clear a previously set channel.

Test Plan

  • composer lint on every changed PHP file → {"tool":"pint","result":"passed"}
  • New packages/messaging/tests/Adapter/Push/FCMTest.php, two cases, following the SendgridHeadersTest named-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

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? — adds a public param on two routes, so specs need regenerating before merge

…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.
@ghost

ghost commented Sep 28, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new clearing behavior and its MQTT delivery tests are consistent with the existing push-message flow, with no concrete issue found in these commits.

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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 8
File Change
packages/messaging/src/Adapter/Push/FCM.php Emits the channel ID in the FCM Android notification payload.
packages/messaging/src/Messages/Push.php Adds an optional channel ID to push message objects.
packages/messaging/tests/Adapter/Push/FCMTest.php Tests FCM payloads with and without a channel ID.
src/Appwrite/Messaging/Adapter/Push/Appwrite.php Carries the channel ID in Appwrite push envelopes.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Create.php Accepts and stores a channel ID when creating a push message.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Update.php Accepts and stores channel IDs on updates, and allows an empty string to clear one.
src/Appwrite/Platform/Workers/Messaging.php Loads stored channel IDs into outgoing push messages.
tests/e2e/Services/Mqtt/MqttServerTest.php Tests MQTT delivery with a channel ID and without one after clearing it.

Reviewed the commits since 035bfaa · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds Android notification channel support to push messages.

The PR appears safe to merge; the previously reported clearing and message-handoff gaps are addressed.

Fix All in Claude CodeFindings

  1. P1 Stored channel cannot be cleared ▶
  2. P2 Tests skip the message handoff ▶
Fix with agent prompt
### Issue 1
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Push/Update.php:287-288
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.

### Issue 2
packages/messaging/tests/Adapter/Push/FCMTest.php:17-22
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.

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!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR carries an optional Android notification channel from push-message creation and updates through storage, worker delivery, FCM, and Appwrite MQTT delivery. The latest changes allow an empty string to clear a stored channel and add delivery-path MQTT tests.

Reviews (3) · Last reviewed commit: "fix(messaging): let a push update clear ..."

Comment on lines +287 to +288
if (!\is_null($channelId)) {
$pushData['channelId'] = $channelId;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 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.

Fix in Claude Code Fix in Codex

Comment on lines +17 to +22
$stub->send(new Push(
to: ['token'],
title: 'Title',
body: 'Body',
channelId: 'reminders',
));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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!

Fix in Claude Code Fix in Codex

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/issue-8086 (after).

Metric Before After Change
🚀 Requests/sec 176.39 173.83 ⚪ -1.5%
⏱️ Latency P50 97.81 ms 99.41 ms ⚪ +1.6%
⏱️ Latency P95 231.94 ms 234.13 ms ⚪ +0.9%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 99.41 234.13 11,115 173.83 +2.19
Account 192.72 384.28 585 9.71 -7.74
TablesDB 96.74 184.44 6,045 97.73 +0.79
Storage 88.73 198.78 2,925 48.96 +8.77
Functions 137.97 283.9 1,560 26.76 +7.51

Top API waits (after)

API request Max wait (ms)
account.name.update 588.21
account.prefs.update 534.11
functions.variables.update 468.16
functions.create 385.68
account.get 378.9

# 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.
@HarshMN2345
HarshMN2345 merged commit 948e295 into main Sep 29, 2026
50 checks passed
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.

🚀 Enhancement: Add support for push notification channels (Android/FCM)

1 participant