Reference
Discover methods and types available in the @flows/js and @flows/js-components packages.
@flows/js
Flows JS SDK is a lightweight library that allows you to integrate Flows into any application that runs JavaScript.
Install the package from npm:
Methods
init()
Initializes the @flows/js
SDK and identifies the user. This method must be called at least once in your application.
Parameters:
Name | Type | Required | Notes |
---|---|---|---|
organizationId | string | Yes | Your organization ID, available in Settings > General. |
environment | string | Yes | The environment key, available in Settings > Environments. |
userId | string | Yes | Unique ID for identifying the user. |
userProperties | object | No | Object with custom user properties as key-value pairs. Accepts string , number , boolean , or date . |
apiUrl | string | No | Custom API URL for proxying requests through your domain. |
addFloatingBlocksChangeListener()
Registers a listener for updates to floating workflow and tour blocks. Slottable blocks are not included.
Parameters:
Name | Type | Required | Notes |
---|---|---|---|
listener | function | Yes | Callback invoked with the updated ActiveBlock array. |
Returns:
A function to unsubscribe the listener and avoid memory leaks.
addSlotBlocksChangeListener()
Registers a listener for updates to blocks in a specific slot.
Parameters:
Name | Type | Required | Notes |
---|---|---|---|
slotId | string | Yes | Slot ID of the slot to monitor. |
listener | function | Yes | Callback function that receives updated array of ActiveBlock . |
Returns:
A function to unsubscribe the listener and avoid memory leaks.
getCurrentFloatingBlocks()
Retrieves all currently active floating workflow and tour blocks. Slot blocks are not included.
Parameters: None
Returns:
An array of ActiveBlock objects.
getCurrentSlotBlocks()
Retrieves all currently active blocks for a specific slot.
Parameters:
Name | Type | Required | Notes |
---|---|---|---|
slotId | string | Yes | Slot ID to query. |
Returns:
An array of ActiveBlock objects.
startWorkflow()
Starts a workflow for the current user in the current environment using a the block key of a manual start block. The workflow will start only if:
- Workflow is published in the current environment
- Workflow has a manual start block with a matching block key
- The current user can access the workflow based on the frequency setting
- The current user matches the start block's user property conditions
Parameters:
Name | Type | Required | Notes |
---|---|---|---|
blockKey | string | Yes | The block key of the manual start block you want to trigger. Learn more |
Returns: Promise<void>
resetWorkflowProgress()
The resetWorkflowProgress()
function resets the progress of a specific workflow for the current user in the current environment.
Parameters:
Name | Type | Required | Notes |
---|---|---|---|
workflowId | string | Yes | The ID of the workflow to reset. You can find it in the Flows app in the workflow detail. |
resetAllWorkflowsProgress()
The resetAllWorkflowsProgress()
function resets the progress of all workflows for the current user in the current environment.
Parameters: None
Types
ActiveBlock
Represents a block visible to the user.
Name | Type | Notes |
---|---|---|
id | string | Internal identifier for the block. Changes with every workflow version, for persistent identifier use props.__flows.key . |
type | "component" | "tour-component" | The block type. |
component | string | The UI component that should be used to render the block. |
props | ComponentProps | TourComponentProps | Props passed to the component, including data and exit node callbacks. |
ComponentProps
Represents the props passed to a component. In addition to your custom props, it includes the __flows
object with Flows properties.
Name | Type | Required | Notes |
---|---|---|---|
__flows.key | string | No | Unique key for the block. Set by you in a workflow. Learn more |
__flows.workflowId | string | Yes | The ID of the workflow. Set by Flows. |
StateMemory
Represents the state memory property of a block.
Name | Type | Required | Notes |
---|---|---|---|
value | boolean | Yes | The value of the state memory. |
setValue | function | Yes | Callback to set the value of the state memory. |
triggers | array | Yes | Object with triggers to update the state memory. See table below. |
triggers
type:
Name | Type | Required | Notes |
---|---|---|---|
type | string | Yes | The trigger type. Can be manual or transition . |
blockId | string | Yes | The block ID of the block that triggers the state memory. |
blockKey | string | No | The block key of the block that triggers the state memory. |
TourComponentProps
Represents the props passed to a tour component. In addition to your custom props, it includes tour component exit nodes and the __flows
object with Flows properties.
Name | Type | Required | Notes |
---|---|---|---|
continue | function | Yes | Callback to go to the next step. |
previous | function | No | Callback to go back to the previous step. |
cancel | function | Yes | Callback to cancel the tour. |
__flows.key | string | No | Unique key for the block. Set by you in a workflow. Learn more |
@flows/js-components
To simplify implementation, you can use the @flows/js-components
package, which provides pre-built UI components and utilities for block rendering.
Install the package from npm:
@flows/js-components methods
render()
Renders floating blocks into the body element. This should be called every time the floating blocks change.
Parameters:
Name | Type | Required | Notes |
---|---|---|---|
blocks | ActiveBlock[] | Yes | Array of floating blocks to render. |
components | object | Yes | Workflow block components. |
tourComponents | object | Yes | Tour block components. |
updateSlotComponents()
Updates the components available for slot-based rendering and registers <flows-slot>
element.
Parameters:
Name | Type | Required | Notes |
---|---|---|---|
components | object | Yes | Workflow block components. |
tourComponents | object | Yes | Tour block components. |
flows-slot
A custom HTML element for rendering slot blocks. Use the data-slot-id
attribute to specify the slot. For this custom element to function correctly, you need to call updateSlotComponents()
with your slottable components after initializing the SDK.
@flows/js-components types
Component
Helps with defining a custom component for use with @flows/js-components
. Define the props that you have entered in your block template and return object with root element
and cleanup
function that will be run before the element is removed from the DOM.
Last updated on