Topics
To send a notification to multiple endpoints at once, use topics. Topics also allow you to group messages by category, e.g., security alerts, promotional messages, etc. To group messages, create a separate topic for each category.
Topics enable you to target messages to all endpoints or phone numbers subscribed to the relevant topic. Each topic has an ARN, its unique identifier.
To add endpoints to a topic, you can use a subscription. A subscription associates a topic with a single endpoint added to a notification channel. You do not need to pre-add phone numbers to a notification channel. To send messages to different endpoints, subscribe all these endpoints to the relevant topic.
This is how you set up topics:
- Use CNS to create notification channels.
- Add endpoints to the notification channels. For SMS, adding an endpoint is optional.
- Create a topic and enable logging to keep track of sent notifications.
- Add a subscription to the topic, specifying the ARN of the previously created endpoint or a phone number for SMS notifications.
This is how you send notifications:
-
You can send a notification to the topic's ARN via the SDK or API using the
Publishmethod.You can also use the management console
.Notification format in JSON:
{ "default": "<Default_text>", "sms": "<Notification_text_for_sms>", "WEB": "<Notification_text_for_bowser>", "APNS": { "aps": { "alert": { "title": "Notification_title", "body": "Notification_text" } } }, "GCM": { "notification": { "title": "Notification_title", "body": "Notification_text" } }, "HMS": { "notification": { "title": "Notification_title", "body": "<Notification_text>" } }, "RUSTORE": { "notification": { "title": "Notification_title", "body": "<Notification_text>" } } }You can use the same text for all channel types or add different texts for each channel. If you provide no notification message for a particular channel, the default text will be used.
-
CNS validates the request.
-
If the request is valid, authenticated and authorized, the system sends the notification to all topics’ subscribers.
-
If there is an error, e.g., the limits are exceeded, it will be logged in Cloud Logging. Logging is enabled when you create a topic.