Skip to content

Latest commit

 

History

History
155 lines (127 loc) · 17.9 KB

12-Develop-Send-Notification.mdx

File metadata and controls

155 lines (127 loc) · 17.9 KB
id title hide_title slug displayed_sidebar sidebar_position image
docs-notifications-develop-send-notification
Send Notification
true
./send-notification
pushNotificationSidebar
12
/assets/docs/previews/docs_notifications_develop--send_notification.png

Send notification overview

This section covers all APIs related to sending notifications from a created channel.

<title>{`Send Notification | Push Notifications | Push Documentation`}</title>

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import Details from '@theme/Details'; import { ModalContainer, ModalSmall, ModalWrapper, AFocus, } from '@site/src/css/SharedStyling';

Send notification API

// userAlice.channel.send([recipients], {options?})
const sendNotifRes = await userAlice.channel.send(['*'], {
  notification: { title: 'test', body: 'test' },
});

Send notification parameters

Param Type Subtype Default Remarks
recipients string[] - - An array of recipient addresses passed in any supported wallet address format. Possible values are: Broadcast -> [*], Targeted -> [0xA], Subset -> [0xA, 0xB], see types of notifications for more info.
options NotificationOptions - - Configuration options for sending notifications.
- options.notification INotification - An object containing the notification's title and body. (Mandatory)
- options.notification.title string - The title for the notification. If not provided, it is taken from notification.title.
- options.notification.body string - The body of the notification. If not provided, it is taken from notification.body.
- options.secret string - Type of encryption standard to use for sending encrypted notification. Accepts eitherPGPV1 or LITV1.
- options.payload IPayload - An object containing additional payload information for the notification.
- options.payload.title string - The title for the notification. If not provided, it is taken from notification.title.
- options.payload.body string - The body of the notification. If not provided, it is taken from notification.body.
- options.payload.cta string - Call to action for the notification.
- options.payload.embed string - Media information like image/video links
- options.payload.category string - Don't pass category if you are sending a generic notification. Notification category represents index point of each individual settings. Pass this if you want to indicate what category of notification you are sending (If channel has settings enabled). For example, if a channel has 10 settings, then a notification of category 7 indicates it's a notification sent for setting 7, if user has turned setting 7 off then Push ndoes will stop notif from getting to the user.
- options.payload.meta { domain?: string, type: string, data: string } - Metadata for the notification, including domain, type, and data.
- options.config IConfig - An object containing configuration options for the notification.
- options.config.expiry number - Expiry time for the notification in seconds
- options.config.silent boolean - Indicates whether the notification is silent.
- options.config.hidden boolean - Indicates whether the notification is hidden.
- options.advanced IAdvance - An object containing advanced options for the notification.
- options.advanced.graph { id: string, counter: number } - Advanced options related to the graph based notification.
- options.advanced.ipfs string - IPFS information for the notification.
- options.advanced.minimal string - Minimal Payload type notification.
- options.advanced.chatid string - For chat based notification.
- options.advanced.pgpPrivateKey string - PGP private key for chat based notification.
- options.channel string - Channel address in CAIP. Mostly used when a delegator sends a notification on behalf of the channel

Note: Parameters in this style are mandatory.

// PushAPI.payloads.sendNotification | Response - 204 OK

Send notification interface

interface INotification {
  title: string;
  body: string;
}

interface IPayload {
  title?: string;
  body?: string;
  cta?: string;
  embed?: string;
  category?: number;
  meta?: {
    domain?: string;
    type: string;
    data: string;
  };
}

interface IConfig {
  expiry?: number;
  silent?: boolean;
  hidden?: boolean;
}

interface IAdvanced {
  graph?: {
    id: string;
    counter: number;
  };
  ipfs?: string;
  minimal?: string;
  chatid?: string;
  pgpPrivateKey?: string;
}

interface NotificationOptions = {
  notification: INotification;
  payload?: IPayload;
  config?: IConfig;
  advanced?: IAdvance;
  channel?: string;
};

// Usage example:
const apiResponse: ApiResponse = await userAlice.channel.send(recipients, {
  // NotificationOptions - as per your given object structure
});

Encrypted notification example

Push Protocol supports sending encrypted notifications, which can only be decrypted by the intended recipients. You can send encrypted notifications to targeted/subsets of users. Currently, Push Notification supports two encryption standards: PGPV1 and LITV1. Use LITV1 to use Lit Protocol encryption and PGPV1 to use PGP_V1 encryption.

// userAlice.channel.send([recipients], {options?})
const sendNotifRes = await userAlice.channel.send(['AliceWalletAddress'], {
  notification: { title: 'test', body: 'test' },
  secret: 'PGPV1', // or "LITV1"
});