Sending a push notification
- In the management console
, go to the folder containing your endpoint. - From the list of services, select Cloud Notification Service.
- Select a push notification channel.
- Navigate to the
Endpoints tab. - Select the endpoint you need.
- Select a notification format under Send messages:
Text
orJSON
. - Enter notification text or a JSON object with notification data.
- Click Send.
Each sent notification is assigned a unique ID. To save it, click Copy ID.
You can send a new notification immediately or resend the previous one.
If you do not have the AWS CLI yet, install and configure it.
Explicit notifications (Bright Push)
To send an explicit notification, run this command:
-
Apple iOS (APNs)
aws sns publish \ --target-arn "<endpoint_ARN>" \ --message-structure json \ --message '{"default": "<notification_text>", "APNS": "{ \"aps\": { \"alert\": \"<notification_text>\"} }" }'
-
Google Android (FCM)
aws sns publish \ --target-arn "<endpoint_ARN>" \ --message-structure json \ --message '{"default": "<notification_text>", "GCM": "{ \"notification\": { \"body\": \"<notification_text>\"} }" }'
Where:
--target-arn
: Mobile endpoint ID (ARN)--message-structure
: Message format--message
: Message
Silent notifications (Silent Push)
To send a silent notification, run this command:
aws sns publish \
--target-arn <endpoint_ARN> \
--message-structure json \
--message '{"data": { "key": "value" } }'
Where:
--target-arn
: Mobile endpoint ID (ARN)--message-structure
: Message format--message
: Message
If you do not have the AWS SDK for Python (boto3) yet, install and configure it.
Explicit notifications (Bright Push)
To send an explicit notification, use this code:
-
Apple iOS (APNs)
response = client.publish( TargetArn="<endpoint_ID>", Message=json.dumps({ "default": "<notification_text>", "APNS": json.dumps({ "aps": { "alert": "<notification_text>" } }) }), MessageStructure="json" ) print ("Message id:", response["MessageId"])
-
Google Android (FCM)
response = client.publish( TargetArn="<endpoint_ID>", Message=json.dumps({ "default": "<notification_text>", "GCM": json.dumps({ "notification": { "body": "<notification_text>" } }) }), MessageStructure="json" ) print ("Message id:", response["MessageId"])
-
RuStore Android
response = client.publish( TargetArn="<endpoint_ID>", Message=json.dumps({ "default": "<default_notification_text>", "RUSTORE": json.dumps({ "notification": { "title": "<notification_title>", "body": "<notification_text>", } }) }), MessageStructure="json" ) message_id = response["MessageId"] print(f"Message id is: {message_id}")
Where:
TargetArn
: Mobile endpoint ID (ARN).MessageStructure
: Message format.Message
: Message.
Silent notifications (Silent Push)
To send a silent notification, use this code:
response = client.publish(
TargetArn="<endpoint ARN>",
Message='{"data": { "key": "value" } }')
print ("Message id:", response["MessageId"])
Where:
TargetArn
: Mobile endpoint ID (ARN)Message
: Message
If you do not have the AWS SDK for PHP yet, install and configure it.
Explicit notifications (Bright Push)
To send an explicit notification, use this code:
-
Apple iOS (APNs)
$response = $client->publish( [ 'TargetArn' => '<endpoint_ID>', 'Message' => json_encode([ 'default' => '<notification_text>', 'APNS' => json_encode([ 'aps' => [ 'alert' => '<notification_text>', ], ]) ]), 'MessageStructure' => 'json', ] ); print($response->get('MessageId'));
-
Google Android (FCM)
$response = $client->publish( [ 'TargetArn' => '<endpoint_ID>', 'Message' => json_encode([ 'default' => '<notification_text>', 'GCM' => json_encode([ 'notification' => [ 'title' => '<notification_title>', 'body' => '<notification_text>', ], ]) ]), 'MessageStructure' => 'json', ] ); print($response->get('MessageId'));
Where:
TargetArn
: Mobile endpoint ID (ARN).MessageStructure
: Message format.Message
: Message.
Silent notifications (Silent Push)
To send a silent notification, use this code:
-
Google Android (FCM)
$response = $client->publish( [ 'TargetArn' => '<endpoint_ID>', 'Message' => json_encode([ 'default' => '<notification_text>', 'GCM' => json_encode([ 'data' => ['<key>' => '<value>'], ]) ]), 'MessageStructure' => 'json', ] ); print($response->get('MessageId'));
Where:
TargetArn
: Mobile endpoint ID (ARN).MessageStructure
: Message format.Message
: Message.
Use the HTTP API publish method for the Yandex Cloud Notification Service Publish resource.