> For the complete documentation index, see [llms.txt](https://bus.node-ts.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bus.node-ts.com/guide/workflows/starting.md).

# Starting

Instances of a workflow are started by one or more messages. When one of these types of messages are received a new workflow state is created and execution of the workflow begins.

Declare a handler for the message that starts your workflow, and then map it using the **WorkflowMapper**.

```typescript
import { Workflow } from '@node-ts/bus-core'

export class FulfilmentWorkflow extends Workflow<FulfilmentWorkflowState> {
  configureWorkflow (
    mapper: WorkflowMapper<FulfilmentWorkflowState, FulfilmentWorkflow>
  ): void {
    mapper
      .withState(FulfilmentWorkflowState)
      // Start a new workflow when an `ItemPurchased` event is received
      .startedBy(ItemPurchased, 'shipItem')
  }
  
  // Handles an `ItemPurchased` event
  async shipItem (event: ItemPurchased) {
    // ...
  }
}
```

In this case, when a **ItemPurchased** event is received, it will start a new workflow and dispatch the message to the **shipItem** handler.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bus.node-ts.com/guide/workflows/starting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
