TsgcWSAPIServer_WebPush › Methods › SendNotification
Encrypts and POSTs a Web Push notification to a single subscription endpoint using the configured VAPID credentials.
procedure SendNotification(const aSubscription : TsgcHTTP_API_WebPush_PushSubscription; const aMessage: TsgcWebPushMessage);
| Name | Type | Description |
|---|---|---|
aSubscription | const TsgcHTTP_API_WebPush_PushSubscription | Target subscription carrying the push service Endpoint plus the browser's p256dh PublicKey and AuthSecret used to encrypt the payload. |
aMessage | const TsgcWebPushMessage | Structured message with Title, Body, Icon and Url; serialized to JSON via AsJSON before encryption. |
Preferred overload when you want the library to build a well-formed notification payload for the browser's service worker. The message's AsJSON representation is encrypted with aes128gcm using the subscription's keys and POSTed to the push service following RFC 8030.
var
oMessage: TsgcWebPushMessage;
begin
oMessage := TsgcWebPushMessage.Create;
try
oMessage.Title := 'eSeGeCe Notification';
oMessage.Body := 'Subscription Successfully Registered!!!';
oMessage.Icon := 'https://www.esegece.com/images/esegece_logo_small.png';
oMessage.Url := 'https://www.esegece.com';
sgcWSAPIServer_WebPush1.SendNotification(aSubscription, oMessage);
finally
oMessage.Free;
end;
end;
procedure SendNotification(const aSubscription : TsgcHTTP_API_WebPush_PushSubscription; const aMessage: string);
| Name | Type | Description |
|---|---|---|
aSubscription | const TsgcHTTP_API_WebPush_PushSubscription | Target subscription whose Endpoint, PublicKey (p256dh) and AuthSecret drive the encrypted POST. |
aMessage | const string | Raw payload sent as-is after encryption; typically a JSON string your service worker knows how to parse. |
Use this overload when you already hold a pre-built JSON or plain-text payload (for example produced by TsgcJSON or loaded from storage). Push services normally accept up to ~4 KB of encrypted content; exceeding that triggers a 413 response that is re-raised via OnWebPushSendNotificationException.
sgcWSAPIServer_WebPush1.SendNotification(aSubscription,
'{"title":"Hello","body":"Raw JSON payload","data":{"url":"https://www.esegece.com"}}');