When a user enables notifications for your Mini App, the Base App generates a unique notification token and url which is sent to your server via webhook.This token grants your app permission to send in-app notifications to that specific user.To send a notification, make a POST request to the url with the user’s notification token and your content.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.
export async function POST(request: NextRequest) { const requestJson = await request.json(); // Parse and verify the webhook event let data; try { data = await validateWebhookEventSignature(requestJson); // Events are signed by the app key of a user with a JSON Farcaster Signature. } catch (e: unknown) { // Handle verification errors (invalid data, invalid app key, etc.) // Return appropriate error responses with status codes 400, 401, or 500 } const fid = data.fid; const event = data.event; // Handle different event types switch (event.event) { case "miniapp_added": // Save notification details and send welcome notification if (event.notificationDetails) { await setUserNotificationDetails(fid, event.notificationDetails); await sendMiniAppNotification({ fid, title: "Welcome to Base Mini Apps", body: "Mini app is now added to your client", }); } break; case "miniapp_removed": // Delete notification details await deleteUserNotificationDetails(fid); break; case "notifications_enabled": // Save new notification details and send confirmation await setUserNotificationDetails(fid, event.notificationDetails); await sendMiniAppNotification({ fid, title: "Ding ding ding", body: "Notifications are now enabled", }); break; case "notifications_disabled": // Delete notification details await deleteUserNotificationDetails(fid); break; } return Response.json({ success: true });}
Identifier that is combined with the FID to form an idempotency key. When the user opens the Mini App from the notification this ID will be included in the context object. Maximum length of 128 characters.
Tokens which are no longer valid and should never be used again. This could happen if the user disabled notifications but for some reason the Mini App server has no record of it.
Mini App events use the following object structure:
type: notification event type
notificationDetails.url: URL that the app should call to send a notification.
notificationDetails.token: A secret token generated by the Base App and shared with the Notification Server. A token is unique for each (Farcaster Client, Mini App, user Fid) tuple.
If users are not seeing the option to enable notifications when they call addMiniApp(), verify that your manifest file contains a valid webhookUrl.
Sent when a user removes the Mini App, which means that any notification tokens for that FID and client app (based on signer requester) should be considered invalid:
Sent when a user disables notifications from, e.g., a settings panel in the client app. Any notification tokens for that FID and client app (based on signer requester) should be considered invalid: