Skip to content

Commit cfed850

Browse files
authored
Notification doc update (#547)
* usenotif hook depreciated * updated warning * removed * switched call out * added async to switch statement * added async to switch statement * added async to switch statement * added async to switch statement * removed await from both save notification and client behaviour * added moved under overview * added bold
1 parent 5707e9b commit cfed850

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

docs/mini-apps/core-concepts/notifications.mdx

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,25 @@ To send a notification, make a `POST` request to the `url` with the user's notif
1313

1414
You will receive webhook events when users enable or disable notifications for your app. When disabled, the notification token becomes invalid and should no longer be used.
1515

16+
## Client App Behavior
17+
18+
Different client apps handle webhook responses differently:
19+
20+
**Farcaster app**: Activates notification tokens immediately without waiting for a webhook success response.
21+
22+
**Base app**: Waits for a successful webhook response before activating tokens.
23+
24+
<Note>
25+
If your webhook processes token saving and sends notifications synchronously before returning a response, tokens may work on Farcaster but fail to activate on Base app.
26+
</Note>
27+
1628

1729
<Panel>
1830
![notification-image-iphone](/images/minikit/notifications-sample.png)
1931
<Info>
2032
Notification tokens are unique to each client app. This means a user can have separate notification preferences for your Mini App across different clients (e.g., Farcaster, the Base app). Removing your Mini App in one client does not affect its status in other clients.
2133
</Info>
34+
2235
</Panel>
2336
## Implementation
2437
<Steps>
@@ -54,19 +67,21 @@ Notification tokens are unique to each client app. This means a user can have se
5467
// Return appropriate error responses with status codes 400, 401, or 500
5568
}
5669

70+
5771
// Extract webhook data
5872

5973
const fid = data.fid;
6074
const appFid = data.appFid; // The FID of the client app that the user added the Mini App to
6175
const event = data.event;
6276

63-
// Handle different event types
77+
// Handle different event types
78+
79+
try {
6480
switch (event.event) {
6581
case "miniapp_added":
66-
// Save notification details and send welcome notification
6782
if (event.notificationDetails) {
68-
await setUserNotificationDetails(fid, appFid, event.notificationDetails);
69-
await sendMiniAppNotification({
83+
setUserNotificationDetails(fid, appFid, event.notificationDetails);
84+
sendMiniAppNotification(fid, appFid, "Welcome to Base Mini Apps", "Mini app is now added to your client");
7085
fid,
7186
appFid,
7287
title: "Welcome to Base Mini Apps",
@@ -76,14 +91,14 @@ Notification tokens are unique to each client app. This means a user can have se
7691
break;
7792

7893
case "miniapp_removed":
79-
// Delete notification details
94+
// Delete notification details
8095
await deleteUserNotificationDetails(fid, appFid);
8196
break;
8297

8398
case "notifications_enabled":
8499
// Save new notification details and send confirmation
85-
await setUserNotificationDetails(fid, appFid, event.notificationDetails);
86-
await sendMiniAppNotification({
100+
setUserNotificationDetails(fid, appFid, event.notificationDetails);
101+
sendMiniAppNotification({
87102
fid,
88103
appFid,
89104
title: "Ding ding ding",
@@ -92,13 +107,16 @@ Notification tokens are unique to each client app. This means a user can have se
92107
break;
93108

94109
case "notifications_disabled":
95-
// Delete notification details
110+
// Delete notification details
96111
await deleteUserNotificationDetails(fid, appFid);
97112
break;
98113
}
99-
100-
return Response.json({ success: true });
114+
} catch (error) {
115+
console.error("Error processing webhook:", error);
101116
}
117+
118+
return response;
119+
102120
```
103121
</Step>
104122
<Step title="Add the Webhook URL to your manifest">
@@ -129,6 +147,11 @@ Notification tokens are unique to each client app. This means a user can have se
129147
<Step title="Prompt users to add your Mini App">
130148
Use the `addMiniApp()` hook to prompt users to add your Mini App
131149

150+
<Warning>
151+
**Important: Webhook Response Timing**
152+
Webhooks must respond within 10 seconds to avoid timeouts from the Base app. If you encounter a "Failed to add mini app" error, your webhook may be taking too long to respond.
153+
</Warning>
154+
132155
```tsx page.tsx highlight={11, 25-27}
133156
"use client";
134157

@@ -343,3 +366,4 @@ Sent when a user disables notifications from, e.g., a settings panel in the clie
343366
"event": "notifications_disabled"
344367
}
345368
```
369+

docs/onchainkit/latest/components/minikit/hooks/useNotification.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ description: Send notifications via a backend proxy to users who saved your Mini
66
Defined in [@coinbase/onchainkit](https://github.com/coinbase/onchainkit)
77

88
<Warning>
9-
Notifications are not yet available in Base App but are coming soon. This documentation describes the upcoming API that will be available when notifications are fully deployed.
9+
This hook is now deprecated. Please follow the [Notifications Guide](/mini-apps/core-concepts/notifications) for implementation.
1010
</Warning>
11-
ebcbglkhecg
11+
1212

1313
<Info>
1414
Allows Mini Apps to send push notifications to users who have saved your app. Notifications require a backend proxy route to handle the actual delivery and enforce rate limiting.

0 commit comments

Comments
 (0)