The step() Helper
Use the step() helper function for ergonomic multi-trigger Step definitions
The step() helper provides a streamlined way to define multi-trigger Steps with full type safety. It wraps your config and handler together, giving you access to ctx.getData() and ctx.match() with proper type inference.
Basic Usage
The step() function returns both the config and handler exports that Motia expects, with full type inference from the config definition.
ctx.getData()
Extracts the data payload from the input regardless of which trigger activated the handler:
- For HTTP triggers, returns the request body
- For queue triggers, returns the message data
- For cron triggers, returns the cron input (typically empty)
- For state triggers, returns the state change event
- For stream triggers, returns the stream event
ctx.match()
Routes execution based on which trigger type activated the handler. Each key corresponds to a trigger type:
Only include the keys for trigger types your Step actually uses. The default key is optional and handles any unmatched trigger types.
Trigger Helper Functions
Use these shorthand helpers for concise trigger definitions:
| Helper | Arguments | Creates |
|---|---|---|
http(method, path, options?) | HTTP method, URL path, optional body/response schemas | HTTP trigger |
queue(topic, options?) | Topic name, optional input schema and infrastructure config | Queue trigger |
cron(expression) | 7-field cron expression | Cron trigger |
state(condition?) | Optional condition function | State trigger |
stream(streamName, condition?) | Stream name, optional condition function | Stream trigger |