Motia Icon
ConceptsSteps

Event Step

The Event Step lets you define custom logic in response to subscribed events and at the same time trigger other steps by emitting new events. It enables communication between different parts of your flow.

Config

The following properties are specific to the Event Step, in addition to the common step config.

PropTypeDescription
string[]
This is only required for TS or JS steps that use zod for their input schema, this is used when processing the step to validate the input before executing the step handler.

The following examples showcase how to configure an Event Step

import { EventConfig, StepHandler } from 'motia'
import { z } from 'zod'
 
const inputSchema = z.object({
  message: z.string()
})
 
type Input = typeof inputSchema
 
export const config: EventConfig<Input> = {
  type: 'event',
  name: 'stepA',
  description: 'Hello from Step A',
  subscribes: ['pms.start'],
  emits: ['pms.stepA.done'],
  input: inputSchema,
  flows: ['parallel-merge'],
}
 
export const handler: StepHandler<typeof config> = async (input, { emit, logger }) => {
  logger.info('Processing message:', input.message)
 
  await emit({
    topic: 'pms.stepA.done',
    data: {
      result: `Processed: ${input.message}`
    }
  })
}

Example

Need help? See our Community Resources for questions, examples, and discussions.

On this page