How to get started with browser push notifications in Yandex Cloud Notification Service
Note
The service is at the preview stage.
To enable Cloud Notification Service, request access to the service from your account manager or technical support
Cloud Notification Service (CNS) is a service for multichannel notifications of users. The service's HTTP API is compatible with the Amazon SNS API
With Cloud Notification Service, you can send push notifications to users' browsers.
To get started with push notifications:
- Get your cloud ready.
- Create an in-browser push notification channel.
- Get the data you need to send to notifications to a user.
- Create an endpoint.
- Send a notification.
Get your cloud ready
Sign up for Yandex Cloud and create a billing account:
- Go to the management console
and log in to Yandex Cloud or create an account if you do not have one yet. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not have a billing account, create one.
If you have an active billing account, you can go to the cloud page
Learn more about clouds and folders.
Create an in-browser push notification channel
In Cloud Notification Service, messages to end users are sent through notification channels.
To create a channel:
-
In the management console
, select the folder you want to create a notification channel in. -
From the list of services, select Cloud Notification Service.
-
Click Create notifications channel.
-
Select the Push notifications in browser tab.
-
Enter a name for your notification channel. The channel name must be unique within Cloud Notification Service.
-
Click Create.
Creating a notification channel may take some time.
Get the data you need to send to notifications to a user
For each channel, you need to create a set of endpoints through which to send notifications to specific users' browsers.
To create an endpoint, get this user data:
-
From the user's browser, use Service Worker
to call the JavaScript subscribe method.The PushSubscription
object will be returned in response. -
Convert the object you got into JSON by calling the toJSON
method.
Example of subscription parameters in JSON
{
"endpoint": "https://fcm.googleapis.com/fcm/send/abcdef123456",
"expirationTime": 1704093740000,
"keys": {
"p256dh": "BOrLkr7sEt8tERyAv6c8ZG5UC********",
"auth": "aBcDeFg12345"
}
}
Create an endpoint
- Select the notification channel you created.
- Select the
Endpoints tab. - Click Create endpoint.
- Enter the Endpoint parameters in JSON you received in the user’s browser.
- Click Create.
Send a notification
- Select the endpoint you created.
- Enter the notification text.
- Click Send.
Each sent notification is assigned a unique ID. To save it, click Copy ID.