fcm

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 22 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

func ValidateSendNotificationPayload

func ValidateSendNotificationPayload(w http.ResponseWriter, r *http.Request) (*firebasetools.SendNotificationPayload, error)

ValidateSendNotificationPayload checks that the request payload supplied in the indicated request are valid

Types

type PushService

type PushService interface {
	Push(
		ctx context.Context,
		sender string,
		payload firebasetools.SendNotificationPayload,
	) error
}

PushService defines the behavior of our FCM push implementation

type RemotePushService

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

RemotePushService sends instructions to a remote FCM service over Google Cloud Pub-Sub

func NewRemotePushService

func NewRemotePushService(
	ctx context.Context,
) (*RemotePushService, error)

NewRemotePushService initializes an FCM push service

func (RemotePushService) Push

func (rfs RemotePushService) Push(
	ctx context.Context,
	sender string,
	notificationPayload firebasetools.SendNotificationPayload,
) error

Push instructs a remote FCM service to send a push notification.

This is done over Google Cloud Pub-Sub.

type ServiceFCM

type ServiceFCM interface {
	SendNotification(
		ctx context.Context,
		registrationTokens []string,
		data map[string]string,
		notification *firebasetools.FirebaseSimpleNotificationInput,
		android *firebasetools.FirebaseAndroidConfigInput,
		ios *firebasetools.FirebaseAPNSConfigInput,
		web *firebasetools.FirebaseWebpushConfigInput,
	) (bool, error)

	Notifications(
		ctx context.Context,
		registrationToken string,
		newerThan time.Time,
		limit int,
	) ([]*dto.SavedNotification, error)

	SendFCMByPhoneOrEmail(
		ctx context.Context,
		phoneNumber *string,
		email *string,
		data map[string]interface{},
		notification firebasetools.FirebaseSimpleNotificationInput,
		android *firebasetools.FirebaseAndroidConfigInput,
		ios *firebasetools.FirebaseAPNSConfigInput,
		web *firebasetools.FirebaseWebpushConfigInput,
	) (bool, error)
}

ServiceFCM defines all interactions with the FCM service

type ServiceFCMImpl

type ServiceFCMImpl struct {
	Repository database.Repository
	// contains filtered or unexported fields
}

ServiceFCMImpl provides methods for sending Firebase Cloud Messaging notifications

func NewService

func NewService(repository database.Repository, onboarding onboarding.ProfileService) *ServiceFCMImpl

NewService initializes a service to interact with Firebase Cloud Messaging

func (ServiceFCMImpl) Notifications

func (s ServiceFCMImpl) Notifications(
	ctx context.Context,
	registrationToken string,
	newerThan time.Time,
	limit int,
) ([]*dto.SavedNotification, error)

Notifications is used to query a user's priorities

func (ServiceFCMImpl) SendFCMByPhoneOrEmail

SendFCMByPhoneOrEmail is used to send FCM notification by phone or email

func (ServiceFCMImpl) SendNotification

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