Documentation ¶
Index ¶
- func ValidateFCMData(data map[string]string) error
- func ValidateSendNotificationPayload(w http.ResponseWriter, r *http.Request) (*firebasetools.SendNotificationPayload, error)
- type PushService
- type RemotePushService
- type ServiceFCM
- type ServiceFCMImpl
- func (s ServiceFCMImpl) Notifications(ctx context.Context, registrationToken string, newerThan time.Time, limit int) ([]*dto.SavedNotification, error)
- func (s ServiceFCMImpl) SendFCMByPhoneOrEmail(ctx context.Context, phoneNumber *string, email *string, ...) (bool, error)
- func (s ServiceFCMImpl) SendNotification(ctx context.Context, registrationTokens []string, data map[string]string, ...) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateFCMData ¶
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 ¶
func (s ServiceFCMImpl) 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)
SendFCMByPhoneOrEmail is used to send FCM notification by phone or email
func (ServiceFCMImpl) SendNotification ¶
func (s ServiceFCMImpl) SendNotification( ctx context.Context, registrationTokens []string, data map[string]string, notification *firebasetools.FirebaseSimpleNotificationInput, android *firebasetools.FirebaseAndroidConfigInput, ios *firebasetools.FirebaseAPNSConfigInput, web *firebasetools.FirebaseWebpushConfigInput, ) (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.