Usage
In this section, we showcase the aspects of using the Notify API. We’ll guide you through the initial steps of initializing the Notify client and logging in a blockchain account. You’ll also learn how to manage your subscriptions and messages. Additionally, we cover the process of setting up and displaying push notifications on your preferred platform. To ensure a good user experience, we include best practices for spam protection, helping you to enable the users to maintain control over the notifications wallet receives.
Content
Links to sections on this page. Some sections are platform specific and are only visible when the platform is selected. To view a summary of useful platform specific topics, check out Extra (Platform Specific) under this section.
- Initialization: Creating a new Notify Client instance and initializing it with a projectId from Cloud.
- Account login: A SIWE message must be signed by the user in order to authorize the client to use Notify API
- Subscribing to a new dapp: Opt-in to receive notifications from dapp
- Fetching active subscriptions: Get active subscriptions
- Fetching subscription’s notification: Get notifications of a subscription
- Fetching available notification types: Get latest notification types
- Updating subscriptions notification settings: Change allowed notification types sent by dapp
- Unsubscribe from a dapp: Opt-out from receiving notifications from a dapp
- Account logout: To stop receiving notifications to this client, accounts can logout of using Notify API
- Push Notification best practices: Guidelines on how to implement Push Notifications across different platforms
- Firebase Cloud Messaging setup (Android): Configuring Android app in order to decrypt notifications
- NotifyClient.Delegate (Android): Setting and overriding functions through NotifyDelegate.
Initialization
To initialize the Notify client, create a Notify.Params.Init
object in the Android Application class with the Core Client passed as a parameter. The Notify.Params.Init
object will then be passed to the Notify.initialize
function. There is also an onError
callback that will need to be provided which will return an instance of Notify.Model.Error
if there’s an issue initializing the client.
Note: The CoreClient used here will be the same instance of the CoreClient used in other WalletConnect Kotlin SDKs
Account login
In order to register account in Notify API to be able to subscribe to any dapp to start receiving notifications, account needs to sign SIWE message to prove ownership. Developers can check if an account is registered by calling isRegistered()
function. If the account is not registered, developers should call prepareRegistration()
and then register()
function to register the account.
Snippet below shows how to check if an account is registered and how to register an account if it’s not registered yet. Developers could use CacaoSigner
to sign the message or use their own signing method.
Subscribing to a new dapp
To begin receiving notifications from a dapp, users must opt-in by subscribing. This subscription process grants permission for the dapp to send notifications to the user. These notifications can serve a variety of purposes, such as providing updates on the user’s blockchain account activities or informing them about ongoing campaigns within the dapp. Upon initial subscription, clients will be automatically enrolled to receive all types of notifications as defined by the dapp at that moment. Users have the flexibility to modify their notification settings later, allowing them to tailor the types of alerts they receive according to their preferences.
Fetching active subscriptions
To fetch the current list of subscriptions an account has, call getActiveSubscriptions()
.
Method will return a map with the topic as the key and Notify.Model.Subscription
as the value.
Fetching subscription’s notifications
To fetch subscription’s notifications by calling getNotificationHistory()
.
Fetching available notification types
Developers can fetch latest notification types specified by dapp by calling getNotificationTypes()
function.
Method will return a map with the notification type id as the key and Notify.Model.NotificationType
as the value.
Updating subscriptions notification settings
Users can alter their notification settings to filter out unwanted alerts from a dapp. During this process, they review and select the types of notifications they wish to receive, based on the latest options provided by the dapp. Available notification types fetching is shown in the next section.
Unsubscribe from a dapp
To opt-out of receiving notifications from a dap, a user can decide to unsubscribe from dapp.
Account logout
If an account is removed from the client or a user no longer wants to receive notifications for this account, you can logout the account from Notify API by calling unregister()
. This will remove all subscriptions and messages for this account from the client’s storage.
Push Notification best practices
To create a good user experience and to guide users into unsubscribing from the correct dapp, there are certain best practices when displaying push notifications.
Core.Model.Message
contains a type
field, which is a unique id of the notification type. It is recommended to use this field as a notification channel id. By doing so it will create a channel for each notification type. To allow users to granularly control which notifications they want to receive within system settings, it is recommended to create a separate channel for every dapp and every notification type they might have. By doing so user would be able to turn off notifications for specific notification type per every subscribed dapp.
Firebase Cloud Messaging setup
To setup Firebase Cloud Messaging please follow our Push Notifications docs.
NotifyClient.Delegate
NotifyClient
needs a NotifyClient.Delegate
passed to it for it to be able to expose asynchronous updates sent from the dapp. It’s recommended to set the delegate in the onCreate
function of the Application
class.
Was this page helpful?