Safe Haskell | None |
---|---|
Language | Haskell2010 |
- generateVAPIDKeys :: MonadRandom m => m VAPIDKeysMinDetails
- readVAPIDKeys :: VAPIDKeysMinDetails -> VAPIDKeys
- vapidPublicKeyBytes :: VAPIDKeys -> [Word8]
- sendPushNotification :: MonadIO m => VAPIDKeys -> Manager -> PushNotificationDetails -> m (Either PushNotificationError ())
- type VAPIDKeys = KeyPair
- data VAPIDKeysMinDetails = VAPIDKeysMinDetails {}
- data PushNotificationDetails = PushNotificationDetails {
- endpoint :: Text
- p256dh :: Text
- auth :: Text
- senderEmail :: Text
- expireInHours :: Int64
- message :: PushNotificationMessage
- data PushNotificationMessage = PushNotificationMessage {}
- data PushNotificationError
Functions
generateVAPIDKeys :: MonadRandom m => m VAPIDKeysMinDetails Source #
Generate the 3 integers minimally representing a unique pair of public and private keys.
Store them in configuration 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 using applicationServerKey = new Uint8Array(vapidPublicKeyBytes) in Javascript.
sendPushNotification :: MonadIO m => VAPIDKeys -> Manager -> PushNotificationDetails -> m (Either PushNotificationError ()) Source #
Send a Push Message. The message sent is Base64 URL encoded. Decode the message in Service Worker notification handler in browser before trying to read the JSON.
Types
data VAPIDKeysMinDetails Source #
3 integers minimally representing a unique VAPID key pair.
data PushNotificationDetails Source #
Web push subscription and message details.
Get subscription details from front end using subscription.endpoint, subscription.toJSON().keys.p256dh and subscription.toJSON().keys.auth. Save subscription details to send messages to the endpoint in future.
PushNotificationDetails | |
|
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.