Skip to content

Commit 7b26f73

Browse files
committed
add batch send API
1 parent 6ba500b commit 7b26f73

File tree

4 files changed

+252
-56
lines changed

4 files changed

+252
-56
lines changed

example/convex/_generated/api.d.ts

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,23 @@ export declare const components: {
5252
"internal",
5353
{ id: string; logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR" },
5454
null | {
55+
_contentAvailable?: boolean;
5556
_creationTime: number;
57+
badge?: number;
5658
body?: string;
57-
categoryIdentifier?: string;
59+
categoryId?: string;
60+
channelId?: string;
5861
data?: any;
62+
expiration?: number;
63+
interruptionLevel?:
64+
| "active"
65+
| "critical"
66+
| "passive"
67+
| "time-sensitive";
68+
mutableContent?: boolean;
5969
numPreviousFailures: number;
60-
sound?: string;
70+
priority?: "default" | "normal" | "high";
71+
sound?: string | null;
6172
state:
6273
| "awaiting_delivery"
6374
| "in_progress"
@@ -67,7 +78,8 @@ export declare const components: {
6778
| "maybe_delivered"
6879
| "unable_to_deliver";
6980
subtitle?: string;
70-
title: string;
81+
title?: string;
82+
ttl?: number;
7183
}
7284
>;
7385
getNotificationsForUser: FunctionReference<
@@ -79,13 +91,24 @@ export declare const components: {
7991
userId: string;
8092
},
8193
Array<{
94+
_contentAvailable?: boolean;
8295
_creationTime: number;
96+
badge?: number;
8397
body?: string;
84-
categoryIdentifier?: string;
98+
categoryId?: string;
99+
channelId?: string;
85100
data?: any;
101+
expiration?: number;
86102
id: string;
103+
interruptionLevel?:
104+
| "active"
105+
| "critical"
106+
| "passive"
107+
| "time-sensitive";
108+
mutableContent?: boolean;
87109
numPreviousFailures: number;
88-
sound?: string;
110+
priority?: "default" | "normal" | "high";
111+
sound?: string | null;
89112
state:
90113
| "awaiting_delivery"
91114
| "in_progress"
@@ -95,7 +118,8 @@ export declare const components: {
95118
| "maybe_delivered"
96119
| "unable_to_deliver";
97120
subtitle?: string;
98-
title: string;
121+
title?: string;
122+
ttl?: number;
99123
}>
100124
>;
101125
getStatusForUser: FunctionReference<
@@ -139,17 +163,61 @@ export declare const components: {
139163
allowUnregisteredTokens?: boolean;
140164
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
141165
notification: {
166+
_contentAvailable?: boolean;
167+
badge?: number;
142168
body?: string;
143-
categoryIdentifier?: string;
169+
categoryId?: string;
170+
channelId?: string;
144171
data?: any;
145-
sound?: string;
172+
expiration?: number;
173+
interruptionLevel?:
174+
| "active"
175+
| "critical"
176+
| "passive"
177+
| "time-sensitive";
178+
mutableContent?: boolean;
179+
priority?: "default" | "normal" | "high";
180+
sound?: string | null;
146181
subtitle?: string;
147-
title: string;
182+
title?: string;
183+
ttl?: number;
148184
};
149185
userId: string;
150186
},
151187
string | null
152188
>;
189+
sendPushNotificationBatch: FunctionReference<
190+
"mutation",
191+
"internal",
192+
{
193+
allowUnregisteredTokens?: boolean;
194+
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
195+
notifications: Array<{
196+
notification: {
197+
_contentAvailable?: boolean;
198+
badge?: number;
199+
body?: string;
200+
categoryId?: string;
201+
channelId?: string;
202+
data?: any;
203+
expiration?: number;
204+
interruptionLevel?:
205+
| "active"
206+
| "critical"
207+
| "passive"
208+
| "time-sensitive";
209+
mutableContent?: boolean;
210+
priority?: "default" | "normal" | "high";
211+
sound?: string | null;
212+
subtitle?: string;
213+
title?: string;
214+
ttl?: number;
215+
};
216+
userId: string;
217+
}>;
218+
},
219+
Array<string | null>
220+
>;
153221
shutdown: FunctionReference<
154222
"mutation",
155223
"internal",

src/client/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ export class PushNotifications<UserType extends string = GenericId<"users">> {
102102
});
103103
}
104104

105+
/**
106+
* Sends push notifications to multiple users in batch.
107+
*
108+
* @param ctx The mutation context
109+
* @param args Object containing list of {userId, notification} pairs and allowUnregisteredTokens flag
110+
* @returns Promise resolving when all notifications are processed
111+
*/
112+
sendPushNotificationBatch(
113+
ctx: RunMutationCtx,
114+
args: {
115+
notifications: Array<{
116+
userId: UserType;
117+
notification: NotificationFields;
118+
}>;
119+
allowUnregisteredTokens?: boolean;
120+
}
121+
) {
122+
return ctx.runMutation(this.component.public.sendPushNotificationBatch, {
123+
...args,
124+
logLevel: this.config.logLevel,
125+
});
126+
}
127+
105128
/**
106129
* Gets the notification by ID returned from {@link sendPushNotification}.
107130
* Returns null if there is no record of a notification with that ID.

src/component/_generated/api.d.ts

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import type * as functions from "../functions.js";
1212
import type * as helpers from "../helpers.js";
1313
import type * as internal_ from "../internal.js";
14-
import type * as public from "../public.js";
14+
import type * as public_ from "../public.js";
1515

1616
import type {
1717
ApiFromModules,
@@ -31,7 +31,7 @@ declare const fullApi: ApiFromModules<{
3131
functions: typeof functions;
3232
helpers: typeof helpers;
3333
internal: typeof internal_;
34-
public: typeof public;
34+
public: typeof public_;
3535
}>;
3636
export type Mounts = {
3737
public: {
@@ -46,12 +46,23 @@ export type Mounts = {
4646
"public",
4747
{ id: string; logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR" },
4848
null | {
49+
_contentAvailable?: boolean;
4950
_creationTime: number;
51+
badge?: number;
5052
body?: string;
51-
categoryIdentifier?: string;
53+
categoryId?: string;
54+
channelId?: string;
5255
data?: any;
56+
expiration?: number;
57+
interruptionLevel?:
58+
| "active"
59+
| "critical"
60+
| "passive"
61+
| "time-sensitive";
62+
mutableContent?: boolean;
5363
numPreviousFailures: number;
54-
sound?: string;
64+
priority?: "default" | "normal" | "high";
65+
sound?: string | null;
5566
state:
5667
| "awaiting_delivery"
5768
| "in_progress"
@@ -61,7 +72,8 @@ export type Mounts = {
6172
| "maybe_delivered"
6273
| "unable_to_deliver";
6374
subtitle?: string;
64-
title: string;
75+
title?: string;
76+
ttl?: number;
6577
}
6678
>;
6779
getNotificationsForUser: FunctionReference<
@@ -73,13 +85,24 @@ export type Mounts = {
7385
userId: string;
7486
},
7587
Array<{
88+
_contentAvailable?: boolean;
7689
_creationTime: number;
90+
badge?: number;
7791
body?: string;
78-
categoryIdentifier?: string;
92+
categoryId?: string;
93+
channelId?: string;
7994
data?: any;
95+
expiration?: number;
8096
id: string;
97+
interruptionLevel?:
98+
| "active"
99+
| "critical"
100+
| "passive"
101+
| "time-sensitive";
102+
mutableContent?: boolean;
81103
numPreviousFailures: number;
82-
sound?: string;
104+
priority?: "default" | "normal" | "high";
105+
sound?: string | null;
83106
state:
84107
| "awaiting_delivery"
85108
| "in_progress"
@@ -89,7 +112,8 @@ export type Mounts = {
89112
| "maybe_delivered"
90113
| "unable_to_deliver";
91114
subtitle?: string;
92-
title: string;
115+
title?: string;
116+
ttl?: number;
93117
}>
94118
>;
95119
getStatusForUser: FunctionReference<
@@ -133,17 +157,61 @@ export type Mounts = {
133157
allowUnregisteredTokens?: boolean;
134158
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
135159
notification: {
160+
_contentAvailable?: boolean;
161+
badge?: number;
136162
body?: string;
137-
categoryIdentifier?: string;
163+
categoryId?: string;
164+
channelId?: string;
138165
data?: any;
139-
sound?: string;
166+
expiration?: number;
167+
interruptionLevel?:
168+
| "active"
169+
| "critical"
170+
| "passive"
171+
| "time-sensitive";
172+
mutableContent?: boolean;
173+
priority?: "default" | "normal" | "high";
174+
sound?: string | null;
140175
subtitle?: string;
141-
title: string;
176+
title?: string;
177+
ttl?: number;
142178
};
143179
userId: string;
144180
},
145181
string | null
146182
>;
183+
sendPushNotificationBatch: FunctionReference<
184+
"mutation",
185+
"public",
186+
{
187+
allowUnregisteredTokens?: boolean;
188+
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
189+
notifications: Array<{
190+
notification: {
191+
_contentAvailable?: boolean;
192+
badge?: number;
193+
body?: string;
194+
categoryId?: string;
195+
channelId?: string;
196+
data?: any;
197+
expiration?: number;
198+
interruptionLevel?:
199+
| "active"
200+
| "critical"
201+
| "passive"
202+
| "time-sensitive";
203+
mutableContent?: boolean;
204+
priority?: "default" | "normal" | "high";
205+
sound?: string | null;
206+
subtitle?: string;
207+
title?: string;
208+
ttl?: number;
209+
};
210+
userId: string;
211+
}>;
212+
},
213+
Array<string | null>
214+
>;
147215
shutdown: FunctionReference<
148216
"mutation",
149217
"public",

0 commit comments

Comments
 (0)