Skip to content

Latest commit

 

History

History
113 lines (84 loc) · 2.65 KB

README.md

File metadata and controls

113 lines (84 loc) · 2.65 KB

Firebase ThingsDB Module (Go)

Firebase module written using the Go language.

Supported features:

  • Firebase Cloud Messaging

Installation

Install the module by running the following command in the @thingsdb scope:

new_module("firebase", "github.com/thingsdb/module-go-firebase");

Optionally, you can choose a specific version by adding a @ followed with the release tag. For example: @v0.1.0.

Configuration

The firebase module requires configuration with the following properties:

Property Type Description
credentials thing (required) A service account or refresh token JSON credentials.

Example configuration:

// Note: We used 'json_load()' to convert a JSON string into ThingsDB value.
set_module_conf("firebase", {
    credentials: json_load('<paste json here>')
});

Exposed functions

Name Description
send_message Send a message to one registration token
send_multicast_message Send a message to multiple registration tokens

Send message

Syntax: send_message(body, data, title, token)

Arguments

  • body: (str) Body of the message.
  • data: (thing) Collection of key-value pairs that will be added to the message as data fields..
  • title: (str) Title of the message.
  • token: (str) The registration token of the device to which the message should be sent.

Example:

body = "Message body.";
data = {
    key: "value"
};
title = "Message title";
token = "<paste token here>";

// Send a notification
firebase.send_message(
    body,
    data,
    title,
    token
).then(|res| {
    res;  // response as "mpdata"
}).else(|err| {
    err;
});

Send multicast message

Syntax: send_multicast_message(body, data, title, tokens)

Arguments

  • body: (str) Body of the message.
  • data: (thing) Collection of key-value pairs that will be added to the message as data fields..
  • title: (str) Title of the message.
  • tokens: (str) The registration tokens for the devices to which the message should be distributed.

Example:

body = "Message body.";
data = {
    key: "value"
};
title = "Message title";
tokens = [
    '<paste token 1 here>',
    '<paste token 2 here>',
];

// Send a notification to multiple registration tokens
firebase.send_multicast_message(
    body,
    data,
    title,
    tokens
).then(|res| {
    res;  // response as "mpdata"
}).else(|err| {
    err;
});