fcm

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

----------------------------------------------------------------*\

  • @author Ly Nam <lyquocnam@live.com>
  • @copyright 2019 Viet Tran <viettranx@gmail.com>
  • @license Apache-2.0
  • @description Plugin to work with Firebase Cloud Messaging *----------------------------------------------------------------

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotifyNotSuccess  = errors.New("can't send notification")
	ErrNotificationEmpty = errors.New("notification can't not be empty")

	ErrMissingRegistration       = createCustomError("MissingRegistration")
	ErrInvalidRegistration       = createCustomError("InvalidRegistration")
	ErrNotRegistered             = createCustomError("NotRegistered")
	ErrInvalidPackageName        = createCustomError("InvalidPackageName")
	ErrMismatchSenderId          = createCustomError("MismatchSenderId")
	ErrInvalidParameters         = createCustomError("InvalidParameters")
	ErrMessageTooBig             = createCustomError("MessageTooBig")
	ErrInvalidDataKey            = createCustomError("InvalidDataKey")
	ErrInvalidTtl                = createCustomError("InvalidTtl")
	ErrUnavailable               = createCustomError("Unavailable")
	ErrInternalServerError       = createCustomError("InternalServerError")
	ErrDeviceMessageRateExceeded = createCustomError("DeviceMessageRateExceeded")
	ErrTopicsMessageRateExceeded = createCustomError("TopicsMessageRateExceeded")
	ErrInvalidApnsCredential     = createCustomError("ErrInvalidApnsCredential")
)

Functions

func New

func New(name string) *fcmClient

Types

type FirebaseCloudMessaging

type FirebaseCloudMessaging interface {
	// Send notification to a topic
	// @topic: /topics/chat
	SendToTopic(ctx context.Context, topic string, notification *Notification) (*Response, error)

	// Send notification to a device
	// @deviceId: fCZ4_yRHP5U:APA91bHJTY...
	SendToDevice(ctx context.Context, deviceId string, notification *Notification) (*Response, error)

	// Send notification to many devices
	// @deviceIds: []string{ "fCZ4_yRHP5U:APA91bHJTY..." }
	SendToDevices(ctx context.Context, deviceIds []string, notification *Notification) (*Response, error)

	// Show the response result of notification, use for debugging
	ShowPrintResult(show bool)

	// Get API Key
	APIKey() string
}

type Notification

type Notification struct {
	Payload          map[string]string `json:"-"`
	CollapseKey      *string           `json:"-"`
	TimeToLive       int               `json:"-"`
	DelayWhileIdle   bool              `json:"-"`
	Title            string            `json:"title,omitempty"`
	Body             string            `json:"body,omitempty"`
	Icon             string            `json:"icon,omitempty"`
	Sound            string            `json:"sound,omitempty"`
	Badge            string            `json:"badge,omitempty"`
	Tag              string            `json:"tag,omitempty"`
	Color            string            `json:"color,omitempty"`
	ClickAction      string            `json:"click_action,omitempty"`
	BodyLocKey       string            `json:"body_loc_key,omitempty"`
	BodyLocArgs      string            `json:"body_loc_args,omitempty"`
	TitleLocKey      string            `json:"title_loc_key,omitempty"`
	TitleLocArgs     string            `json:"title_loc_args,omitempty"`
	AndroidChannelID string            `json:"android_channel_id,omitempty"`
}

func NewNotification

func NewNotification(title string, opts ...Opt) *Notification

type Opt

type Opt func(*Notification)

func WithAction

func WithAction(action string) Opt

func WithBadge

func WithBadge(badge string) Opt

func WithBody

func WithBody(body string) Opt

func WithCollapseKey

func WithCollapseKey(collapseKey string) Opt

func WithColor

func WithColor(color string) Opt

func WithIcon

func WithIcon(icon string) Opt

func WithPayload

func WithPayload(payload map[string]string) Opt

func WithSound

func WithSound(sound string) Opt

func WithTag

func WithTag(tag string) Opt

type Response

type Response struct {
	Success int
	Fail    int
	Results []Result
}

type Result

type Result struct {
	MessageID   *string `json:"message_id,omitempty"`
	Error       error   `json:"error,omitempty"`
	DeviceToken string  `json:"device_token"`
}

Jump to

Keyboard shortcuts

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