Firebase module written using the Go language.
Supported features:
- Firebase Cloud Messaging
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
.
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>')
});
Name | Description |
---|---|
send_message | Send a message to one registration token |
send_multicast_message | Send a message to multiple registration tokens |
Syntax: send_message(body, data, title, token)
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.
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;
});
Syntax: send_multicast_message(body, data, title, tokens)
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.
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;
});