Skip to content
TypeScript

fix(relay): preserve conversation routing in iOS push responses (#16350)

Danny58af7ac1eebd
diff --git a/infra/relay/src/agentActivity/ApnsClient.test.ts b/infra/relay/src/agentActivity/ApnsClient.test.ts
index 010f4c30fb8..aafc9c541a5 100644
--- a/infra/relay/src/agentActivity/ApnsClient.test.ts
+++ b/infra/relay/src/agentActivity/ApnsClient.test.ts
@@ -18,6 +18,7 @@ import * as HttpClientResponse from "effect/http/HttpClientResponse";
import type { ApnsCredentials } from "../Config.ts";
import * as ApnsClient from "./ApnsClient.ts";
+import { sanitizeApnsNotificationPayload } from "./agentActivityPayloads.ts";
import * as ApnsProviderTokens from "./ApnsProviderTokens.ts";
const isApnsJwtSigningError = Schema.is(ApnsClient.ApnsJwtSigningError);
@@ -164,7 +165,7 @@ describe("ApnsClient", () => {
}).pipe(Effect.provide(layerTest)),
);
- it.effect("builds a standard APNs alert payload with routing metadata", () =>
+ it.effect("puts remote routing metadata only in Expo's body field", () =>
Effect.gen(function* () {
const apns = yield* ApnsClient.ApnsClient;
const request = apns.makePushNotificationRequest({
@@ -179,7 +180,7 @@ describe("ApnsClient", () => {
});
expect(request.priority).toBe("10");
- expect(request.payload).toMatchObject({
+ expect(request.payload).toEqual({
aps: {
alert: {
title: "Thread",
@@ -188,9 +189,38 @@ describe("ApnsClient", () => {
sound: "default",
"thread-id": "env/thread",
},
- environmentId: "env",
- threadId: "thread",
- deepLink: "/threads/env/thread",
+ body: {
+ environmentId: "env",
+ threadId: "thread",
+ deepLink: "/threads/env/thread",
+ },
+ });
+ }).pipe(Effect.provide(layerTest)),
+ );
+
+ it.effect("fits long routing metadata and multibyte alerts within the APNs 4096-byte limit", () =>
+ Effect.gen(function* () {
+ const apns = yield* ApnsClient.ApnsClient;
+ const environmentId = "é".repeat(191);
+ const threadId = "t".repeat(512);
+ const notification = sanitizeApnsNotificationPayload({
+ title: "界".repeat(120),
+ body: "界".repeat(120),
+ environmentId,
+ threadId,
+ deepLink: `/threads/${encodeURIComponent(environmentId)}/${threadId}`,
+ });
+ const request = apns.makePushNotificationRequest({ token: "push-token", notification });
+
+ expect(
+ new TextEncoder().encode(JSON.stringify(request.payload)).byteLength,
+ ).toBeLessThanOrEqual(4096);
+ expect(request.payload).toMatchObject({
+ body: {
+ environmentId,
+ threadId,
+ deepLink: notification.deepLink,
+ },
});
}).pipe(Effect.provide(layerTest)),
);
diff --git a/infra/relay/src/agentActivity/ApnsClient.ts b/infra/relay/src/agentActivity/ApnsClient.ts
index 57360e3bc28..d2c3cd36c6e 100644
--- a/infra/relay/src/agentActivity/ApnsClient.ts
+++ b/infra/relay/src/agentActivity/ApnsClient.ts
@@ -186,9 +186,12 @@ function makePushNotificationRequest(input: {
sound: "default",
"thread-id": notificationThreadId(input.notification),
},
- environmentId: input.notification.environmentId,
- threadId: input.notification.threadId,
- deepLink: input.notification.deepLink,
+ // Expo iOS exposes userInfo.body as notification.content.data for remote pushes.
+ body: {
+ environmentId: input.notification.environmentId,
+ threadId: input.notification.threadId,
+ deepLink: input.notification.deepLink,
+ },
},
};
}