web-push-0.3: Send messages using Web Push protocol.

Safe HaskellNone
LanguageHaskell2010

Web.WebPush

Contents

Synopsis

Functions

generateVAPIDKeys :: MonadRandom m => m VAPIDKeysMinDetails Source #

Generate the 3 integers minimally representing a unique pair of public and private keys.

Store them securely and use them across multiple push notification requests.

readVAPIDKeys :: VAPIDKeysMinDetails -> VAPIDKeys Source #

Read VAPID key pair from the 3 integers minimally representing a unique key pair.

vapidPublicKeyBytes :: VAPIDKeys -> [Word8] Source #

Pass the VAPID public key bytes to browser when subscribing to push notifications. Generate application server key browser using:

applicationServerKey = new Uint8Array( #{toJSON vapidPublicKeyBytes} )

sendPushNotification :: (MonadIO m, ToJSON msg) => VAPIDKeys -> Manager -> PushNotification msg -> m (Either PushNotificationError ()) Source #

Send a Push Message. Read the message in Service Worker notification handler in browser:

self.addEventListener('push', function(event){ console.log(event.data.json()); });

mkPushNotification :: PushEndpoint -> PushP256dh -> PushAuth -> PushNotification () Source #

Constuct a push notification.

PushEndpoint, PushP256dh and PushAuth should be obtained from push subscription in client's browser. Push message can be set through pushMessage; text and json messages are usually supported by browsers. pushSenderEmail and pushExpireInSeconds can be used to set additional details.

Types

data VAPIDKeysMinDetails Source #

3 integers minimally representing a unique VAPID public-private key pair.

data PushNotification msg Source #

Web push subscription and message details. Use mkPushNotification to construct push notification.

data PushNotificationMessage Source #

Example payload structure for web-push. Any datatype with JSON instance can also be used instead. See mkPushNotification.

Constructors

PushNotificationMessage 

Fields

Instances
Eq PushNotificationMessage Source # 
Instance details

Defined in Web.WebPush

Show PushNotificationMessage Source # 
Instance details

Defined in Web.WebPush

Generic PushNotificationMessage Source # 
Instance details

Defined in Web.WebPush

Associated Types

type Rep PushNotificationMessage :: Type -> Type #

ToJSON PushNotificationMessage Source # 
Instance details

Defined in Web.WebPush

type Rep PushNotificationMessage Source # 
Instance details

Defined in Web.WebPush

data PushNotificationError Source #

RecepientEndpointNotFound comes up when the endpoint is no longer recognized by the push service. This may happen if the user has cancelled the push subscription, and hence deleted the endpoint. You may want to delete the endpoint from database in this case, or if EndpointParseFailed.