notifications

package
v0.0.0-...-eec4b17 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NotificationTitleKey = "notification_title"
	NotificationBodyKey  = "notification_body"
	NotificationImageKey = "notification_image"

	ApplicationIDKey   = "application_id"
	ApplicationNameKey = "application_name"
)
View Source
const (
	EnvCredentialsFilePath = "FIREBASE_CREDENTIALS_FILE_PATH"
)

Variables

This section is empty.

Functions

func SignNotification

func SignNotification(notification types.Notification, secretKey string) (string, error)

SignNotification signs the given notification using the given secret key

func VerifyNotificationSignature

func VerifyNotificationSignature(notification types.Notification, signature string, secretKey string) (bool, error)

VerifyNotificationSignature verifies that the given signature is valid for the given notification

Types

type Client

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

func NewClient

func NewClient(config *Config, db Database) (*Client, error)

NewClient returns a new Client instance

func NewClientFromEnvVariables

func NewClientFromEnvVariables(db Database) (*Client, error)

NewClientFromEnvVariables returns a new Client instance by using the environment variables

func (*Client) SendNotificationToApp

func (c *Client) SendNotificationToApp(appID string, notification types.Notification) error

SendNotificationToApp allows to send the given notification to the application having the given id

func (*Client) SendNotificationToUsers

func (c *Client) SendNotificationToUsers(app *types.Application, usersAddresses []string, notification *types.Notification) error

SendNotificationToUsers sends the given notification to the devices of the users having the given addresses

type Config

type Config struct {
	CredentialsFilePath string `json:"credentials_file_path" yaml:"credentials_file_path" toml:"credentials_file_path"`
}

func ReadConfigFromEnvVariables

func ReadConfigFromEnvVariables() (*Config, error)

type Database

type Database interface {
	GetUserNotificationTokens(address string) ([]string, error)

	GetApp(appID string) (*types.Application, bool, error)

	SaveSentNotification(notification *types.SentNotification) error
}

type SentNotificationBody

type SentNotificationBody struct {
	// Notification contains the notification to send
	Notification types.Notification `json:"notification"`

	// Signature contains the signature of the notification.
	// This is achieved by signing the Notification's JSON representation
	// using the application's secret key
	Signature string `json:"signature"`
}

Jump to

Keyboard shortcuts

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