Glassfy Function
Overview
Functions let you create your own connectors within your dashboard and send data to new tools with just a few lines of JavaScript - no additional infrastructure required.
Your function will take events from glassfy system, transform and deliver them to any external tool or API without worrying about setting up or maintaining any infrastructure.
Use cases:
- Send data from Glassfy to a service thatβs still not supported
- Transform data before sending it downstream
- Enrich outgoing data using external APIs
See our Youtube Tutorial below for inspiration and guidance:
Create a function
- Navigate to
Glassfy Dashboard β Connectors
- Click
Create Connectors
- Select
Glassfy Function
On the modal window
- Optionally add a
description
and configure settings - Upload your source file as described in the next section
- Make sure the state of the connector is
Enable
and selectSave
The settings
will be available as property of the context
parameter passed as the second argument to your handler.
Code your function
The handler is the function in you code that process events. On every new event generated for your app, Glassfy will call the handler onEvent
with two arguments:
The example below shows a function that sends some event details to slack.
Create a Slack webhook URL following this guide and add it in the function setting as SLACK_URL
const fetch = require('node-fetch');
exports.onEvent = async function (event, context) {
console.log(`Processing Event ${event.id}`);
const body = {
text: `π Glassfy Function - event ${event.id}`
};
const url = context.settings.SLACK_URL;
await fetch(url, {
method: 'POST',
body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' }
});
}
The logs from your function will be available for download on the deliveries
page
Runtime and dependecies
- The following packages are available in the function environment:
- @google-cloud/[email protected]
- @google-cloud/[email protected]
- @google-cloud/[email protected]
- @google-cloud/[email protected]
- @google-cloud/[email protected]
- @google-cloud/[email protected]
- @google-cloud/[email protected]
- @google-cloud/[email protected]
- @sendgrid/[email protected]
- @sendgrid/[email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
Currently is not possible to add custom dependencies.
- Your JavaScript code will be executed as a
CommonJS
module byNodeJS v18.x
with a timeout of10s
Test
Before running your code with real events, you can disable the connector before saving. Then click the option button on the connector row and select Send Test Event
. From the deliveries page you can then check the status and optionally download the logs.
Reference
- Context
Key | Description | Type |
---|---|---|
settings | Contains settings saved with the connector | { [key: string]: string } |
Updated about 1 year ago