TsgcWSAPIServer_WebPushMethods › SendNotification

SendNotification Method

Encrypts and POSTs a Web Push notification to a single subscription endpoint using the configured VAPID credentials.

Overloads

Overload 1

Syntax

procedure SendNotification(const aSubscription : TsgcHTTP_API_WebPush_PushSubscription; const aMessage: TsgcWebPushMessage);

Parameters

NameTypeDescription
aSubscriptionconst TsgcHTTP_API_WebPush_PushSubscriptionTarget subscription carrying the push service Endpoint plus the browser's p256dh PublicKey and AuthSecret used to encrypt the payload.
aMessageconst TsgcWebPushMessageStructured message with Title, Body, Icon and Url; serialized to JSON via AsJSON before encryption.

Remarks

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.

Example

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;

Overload 2

Syntax

procedure SendNotification(const aSubscription : TsgcHTTP_API_WebPush_PushSubscription; const aMessage: string);

Parameters

NameTypeDescription
aSubscriptionconst TsgcHTTP_API_WebPush_PushSubscriptionTarget subscription whose Endpoint, PublicKey (p256dh) and AuthSecret drive the encrypted POST.
aMessageconst stringRaw payload sent as-is after encryption; typically a JSON string your service worker knows how to parse.

Remarks

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.

Example

sgcWSAPIServer_WebPush1.SendNotification(aSubscription,
  '{"title":"Hello","body":"Raw JSON payload","data":{"url":"https://www.esegece.com"}}');

Back to Methods