Skip to main content

Custom Event

GridStudio allows you to define and emit custom events from within server-side functions. These events can be captured in your automation flows (such as AI Flows or Workflows) to trigger follow-up actions and continue the flow execution.

The sdk.customEvent.emitAsync method sends an event signal to the flow engine along with optional metadata. This makes it easy to create reactive, event-driven systems across sessions and users.


API

await sdk.customEvent.emitAsync(eventKey, payload)

ParameterTypeDescription
eventKeystringThe unique key of the custom event.
payloadobjectOptional. The event payload. Must include customerUserId and may include sessionId and additional data.

Example

await sdk.customEvent.emitAsync('property:created', {
customerUserId: 'abc123',
sessionId: 'xyz456',
title: 'New property listed',
price: 500000,
})

sdk.utils.logger.info('Custom event emitted')

Notes

  • customerUserId is required. This indicates the target user for whom the event is emitted.
  • If sessionId is provided, it will be associated with the event context.
  • The event can be caught in any automation flow that listens for the specified eventKey.
  • Make sure the customer user exists in the current tenant; otherwise the event will be ignored silently.

Use Cases

  • Triggering follow-up actions after a form submission.
  • Updating AI conversation state when a certain backend action occurs.
  • Notifying agents or users asynchronously through flows.