fcm

package module
v0.0.0-...-19550db Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2016 License: Apache-2.0 Imports: 12 Imported by: 3

README

FCM Library for Go

Provides the following functionality for Firebase Cloud Messaging:

  1. Sending messages.
  2. Listening to receiving messages.

Documentation: http://godoc.org/github.com/mcilloni/go-fcm

Installation

$ go get github.com/mcilloni/go-fcm

Status

This library is in Alpha. We will make an effort to support the library, but we reserve the right to make incompatible changes when necessary.

Feedback

Please read CONTRIBUTING and raise issues here in Github.

Documentation

Overview

Package fcm provides send and receive FCM functionality.

Index

Constants

View Source
const (
	CCSAck     = "ack"
	CCSNack    = "nack"
	CCSControl = "control"
	CCSReceipt = "receipt"
)

Variables

View Source
var (
	// DebugMode determines whether to have verbose logging.
	DebugMode = false
	// Default Min and Max delay for backoff.
	DefaultMinBackoff = 1 * time.Second
	DefaultMaxBackoff = 10 * time.Second
)

Functions

func Listen

func Listen(senderId, apiKey string, h MessageHandler, stop <-chan bool) error

Listen blocks and connects to FCM waiting for messages, calling the handler for CCS message that can be of interest to the listener: upstream messages, delivery receipt notifications, errors. An optional stop channel can be provided to stop listening.

func SendXmpp

func SendXmpp(senderId, apiKey string, m XmppMessage) (string, int, error)

SendXmpp sends a message using the XMPP FCM connection server.

Types

type CcsMessage

type CcsMessage struct {
	From             string `json:"from, omitempty"`
	MessageId        string `json:"message_id, omitempty"`
	MessageType      string `json:"message_type, omitempty"`
	RegistrationId   string `json:"registration_id,omitempty"`
	Error            string `json:"error,omitempty"`
	ErrorDescription string `json:"error_description,omitempty"`
	Category         string `json:"category, omitempty"`
	Data             Data   `json:"data,omitempty"`
	ControlType      string `json:"control_type,omitempty"`
}

CcsMessage is an Xmpp message sent from CCS.

type Data

type Data map[string]interface{}

The data payload of a FCM message.

type HttpMessage

type HttpMessage struct {
	To                    string        `json:"to,omitempty"`
	RegistrationIds       []string      `json:"registration_ids,omitempty"`
	CollapseKey           string        `json:"collapse_key,omitempty"`
	Priority              string        `json:"priority,omitempty"`
	ContentAvailable      bool          `json:"content_available,omitempty"`
	DelayWhileIdle        bool          `json:"delay_while_idle,omitempty"`
	TimeToLive            *uint         `json:"time_to_live,omitempty"`
	RestrictedPackageName string        `json:"restricted_package_name,omitempty"`
	DryRun                bool          `json:"dry_run,omitempty"`
	Data                  Data          `json:"data,omitempty"`
	Notification          *Notification `json:"notification,omitempty"`
}

A FCM Http message.

type HttpResponse

type HttpResponse struct {
	MulticastId  int      `json:"multicast_id,omitempty"`
	Success      uint     `json:"success,omitempty"`
	Failure      uint     `json:"failure,omitempty"`
	CanonicalIds uint     `json:"canonical_ids,omitempty"`
	Results      []Result `json:"results,omitempty"`
	MessageId    int      `json:"message_id,omitempty"`
	Error        string   `json:"error,omitempty"`
}

HttpResponse is the FCM connection server response to an HTTP downstream message request.

func SendHttp

func SendHttp(apiKey string, m HttpMessage) (*HttpResponse, error)

Send a message using the HTTP FCM connection server.

type MessageHandler

type MessageHandler func(cm CcsMessage) error

MessageHandler is the type for a function that handles a CCS message. The CCS message can be an upstream message (device to server) or a message from CCS (e.g. a delivery receipt).

type Notification

type Notification struct {
	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"`
	TitleLocArgs string `json:"title_loc_args,omitempty"`
	TitleLocKey  string `json:"title_loc_key,omitempty"`
}

The notification payload of a FCM message.

type Result

type Result struct {
	MessageId      string `json:"message_id,omitempty"`
	RegistrationId string `json:"registration_id,omitempty"`
	Error          string `json:"error,omitempty"`
}

Result represents the status of a processed Http message.

type XmppMessage

type XmppMessage struct {
	To                       string        `json:"to,omitempty"`
	MessageId                string        `json:"message_id"`
	MessageType              string        `json:"message_type,omitempty"`
	CollapseKey              string        `json:"collapse_key,omitempty"`
	Priority                 string        `json:"priority,omitempty"`
	ContentAvailable         bool          `json:"content_available,omitempty"`
	DelayWhileIdle           bool          `json:"delay_while_idle,omitempty"`
	TimeToLive               *uint         `json:"time_to_live,omitempty"`
	DeliveryReceiptRequested bool          `json:"delivery_receipt_requested,omitempty"`
	DryRun                   bool          `json:"dry_run,omitempty"`
	Data                     Data          `json:"data,omitempty"`
	Notification             *Notification `json:"notification,omitempty"`
}

A FCM Xmpp message.

Directories

Path Synopsis
cmd
fcm-logger
Program fcm-logger logs and echoes as a FCM "server".
Program fcm-logger logs and echoes as a FCM "server".

Jump to

Keyboard shortcuts

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