Firebase Cloud Function server for Label Commander client.
- The cloud functions in this project write label requests to a Firebase Realtime database.
- The Label Commander client reads these entries and then prints labels on an attached Dymo LabelWriter.
- IFTTT is optional, but provides numerous triggers to call the cloud functions. It acts as a frontend. The cloud functions can also be called directly. See below for the API.
- On the command line, clone this repo and change into the cloned directory.
- Follow the Firebase Cloud Functions Get Started Guide.
- If prompted to overwrite any files during the init process, always select
no
. - When prompted to select a language, select
Javascript
.
- If prompted to overwrite any files during the init process, always select
- Set your authentication key by running:
firebase functions:secrets:set IFTTT_SECRETKEY
.- Follow any prompts to set up Google Cloud Secret Manager.
- Select a long random string to use as an authentication key. It doesn't matter what this is, only that it's a strong password. Here's a good starting place:
openssl rand -base64 18
. - Take note of this key, as you will need it later.
- Deploy the functions:
npm run deploy
. - Take note of the
Function URL
lines printed near the end. You will need these later.
To print a label, you need to set up IFTTT to trigger a Webhook action in response to a trigger of your choice.
- Create a new applet in IFTTT.
- Set up the "If This" trigger of your choice. In my case, I used the Google Assistant "Say a phrase with a text ingredient" trigger.
- For the "Then That" service, select "Webhooks."
- Select the "Make a web request" action.
- Set the URL to the
Function URL
parameter printed during deployment. It will be something like,https://us-central1-myproject.cloudfunctions.net/printBatch
, wheremyproject
will be the name of your Firebase project. - Set the method to
POST
. - Set the content type to
application/json
. - Under "Additional Headers" enter:
Where
Authorization: AUTH_KEY
AUTH_KEY
is the authentication key you set earlier. - Set the body to:
The
{ "items": [ {"body": "Text to print", "qty": 1} ] }
body
andqty
may be ingredients from your trigger. - Click "Update action" to save your applet.
- Try it out!
This project provides two cloud functions: printLabel
and printBatch
. The former prints a single label, while the latter prints any number of different labels.
In the below examples, replace MY-PROJECT
with the name of your cloud function deployment. The complete URLs for your particular project are printed on the console after a successful deployment (see Installation, above).
The AUTH_KEY
set during setup must be provided for every request. There are two ways to do this:
-
As a header (preferred). Send the following header with every request:
Authorization: AUTH_KEY
-
In the JSON body of the request. Set the following key in the JSON request body:
"authentication": "AUTH_KEY"
For example, the body of the request sent to
printLabel
would look like this:{ "authentication": "AUTH_KEY", "body": "Text to print", "qty": 1 }
POST
https://MY-PROJECT.cloudfunctions.net/printLabel
{
"body": "Text to print",
"qty": 1
}
Returns 200
on success.
POST
https://MY-PROJECT.cloudfunctions.net/printBatch
{
"items": [
{
"body": "Text to print",
"qty": 2
},
{
"body": "Other text to print",
"qty": 1
}
]
}
Returns 200
on success.