Send Event to Flows
This function can be used to send a generic event to Flows. Sending event to Flows using this function will allow multiple flows to be triggered based on the event coming in. Furthermore, new Flows can be added at any time that listen to these events allowing Flows to be extended without having to change front end code.
Syntax
flows.SendEventToFlows(<Workspaces>, <Event>, <Payload>, <Callback>)
Parameter | Description |
---|---|
Workspaces | One or more workspaces that this event should be sent to. Workspace IDs can be found under the workspace properties page in your Team Settings. In order to send an event to multiple workspaces, you can separate each workspace ID with a comma. |
Event | The name of the event to send to Flows (e.g. PageVisit, Deposit Started, Login etc). This can be any string you decide and will be learnt by Flows (see learning section below). |
Payload | The JSON payload to pass to the flow. This could be anything you define and will be automatically parsed by Flows so that the field values can be used within the flow. |
Callback | An optional callback function that will be called with the result once the call to Flows is complete |
Example
<script>
var workspaces = "W2-8j982q0-SLA12-aA,MLas21-asd-123";
var event = "PageVisit";
var payload = Object();
payload['user_id'] = '123';
payload['page_visited'] = 'deposit';
flows.SendEventToFlows(workspaces, event, payload, function(response) {
console.log(response);
});
</script>
Learning
When sending in new events or new fields within an event it's important that Flows learns them first before they can be used within as a trigger or field value. Learning needs to be switched on through the Team settings:
Once this is switched on, then Flows will automatically learn events as they are coming in and you will see them appear in the flow builder automatically once they are learnt.
If you do not have access to your Team settings, ask an Owner of the team to toggle learning on when required
Learning of events should not be left on all the time as this can slow down processing time and also runs the risk of malicious users sending erroneous data to Flows that will be learnt.