fcm

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateFCMData

func ValidateFCMData(data map[string]string) error

ValidateFCMData checks that the supplied FCM data does not use re

Types

type ServiceFCM

type ServiceFCM interface {
	SendNotification(
		ctx context.Context,
		payload *firebasetools.SendNotificationPayload,
	) (bool, error)
}

ServiceFCM defines all interactions with the FCM service

func NewService

func NewService() ServiceFCM

NewService initializes a service to interact with Firebase Cloud Messaging

type ServiceFCMImpl

type ServiceFCMImpl struct {
	// contains filtered or unexported fields
}

ServiceFCMImpl provides methods for sending fcm notifications

func (ServiceFCMImpl) SendNotification

func (s ServiceFCMImpl) SendNotification(
	ctx context.Context,
	payload *firebasetools.SendNotificationPayload,
) (bool, error)

SendNotification sends a data message to the specified registration tokens.

It returns:

  • a list of registration tokens for which message sending failed
  • an error, if no message sending occurred

Notification messages can also be accompanied by custom `data`.

For data messages, the following keys should be avoided:

  • reserved words: "from", "notification" and "message_type"
  • any word starting with "gcm" or "google"

Messages that are time sensitive (e.g video calls) should be sent with `HIGH_PRIORITY`. Their time to live should also be limited (or the expiry) set on iOS. For Android, there is a `TTL` key in `messaging.AndroidConfig`. For iOS, the `apns-expiration` header should be set to a specific timestamp e.g `"apns-expiration":"1604750400"`. For web, there's a `TTL` header that is also a number of seconds e.g. `"TTL":"4500"`.

For Android, priority is set via the `messaging.AndroidConfig` `priority` key to either "normal" or "high". It should be set to "high" only for urgent notification e.g video call notifications. For web, it is set via the `Urgency` header e.g "Urgency": "high". For iOS, the "apns-priority" header is used, with "5" for normal/low and "10" to mean urgent/high.

The callers of this method should implement retries and exponential backoff, if necessary.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL