Overview
When a user enables notifications for your Mini App, the Base App generates a unique notificationtoken
and url
which is sent to your server via webhook.
This token
grants your app permission to send push 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.
Implementation
1
Create a webhook server
Create a webhook server to handle webhook events.
app/api/webhook/route.ts
2
Add the Webhook URL to your manifest
Add the Webhook URL to your manifest file
app/.well-known/farcaster.json
3
Prompt users to add your Mini App
Use the
addMiniApp()
hook to prompt users to add your Mini Apppage.tsx
4
Save the token and URL from the webhook event
The
token
and url
need to be securely saved to a database so they can be looked up when you want to send a notification to a particular user.miniapp_added_payload.json
5
Send notifications
Send notifications by sending a
POST
request to the url
associated with the user’s token
sendNotification.ts
Schema
Send Notification Request Schema
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.
Title of the notification. Max length 32 characters.
Body of the notification. Max length 128 characters.
URL to open when the user clicks the notification. Max length 1024 characters. Must be on the same domain as the Mini App.
Array of notification tokens to send to. Max 100 tokens.
Send Notification Response Schema
Tokens for which the notification succeeded.
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.
Tokens for which the rate limit was exceeded. The Mini App server can try later.
Events
Mini App events use the following object structure:type
: notification event typenotificationDetails.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
.miniapp_added
Sent when the user adds the Mini App to their Farcaster client (whether or not it was triggered by an addMiniApp()
prompt).
miniapp_added_payload.json
miniapp_removed
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:
miniapp_removed_payload
notifications_enabled
Sent when a user enables notifications (e.g. after disabling them). The payload includes a new token
and url
:
notifications_enabled_payload
notifications_disabled
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:
notifications_disabled_json