Copy as Markdown[View as Markdown](/docs/sdk/functions/addMessageToDomain.md)

***

# Function: addMessageToDomain()

> **addMessageToDomain**(`directory`): (`id`, `direction`, `message`, `version`?) => `Promise`<`void`>

Defined in: domains.ts:542

Add an event/command/query to a domain by its id.

Optionally specify a version to add the message to a specific version of the domain.

## Parameters[​](#parameters "Direct link to Parameters")

| Parameter   | Type     |
| ----------- | -------- |
| `directory` | `string` |

## Returns[​](#returns "Direct link to Returns")

`Function`

### Parameters[​](#parameters-1 "Direct link to Parameters")

| Parameter          | Type                                                                               |
| ------------------ | ---------------------------------------------------------------------------------- |
| `id`               | `string`                                                                           |
| `direction`        | `string`                                                                           |
| `message`          | { `fields`: `string`\[]; `group`: `string`; `id`: `string`; `version`: `string`; } |
| `message.fields`?  | `string`\[]                                                                        |
| `message.group`?   | `string`                                                                           |
| `message.id`?      | `string`                                                                           |
| `message.version`? | `string`                                                                           |
| `version`?         | `string`                                                                           |

### Returns[​](#returns-1 "Direct link to Returns")

`Promise`<`void`>

## Example[​](#example "Direct link to Example")

```
import utils from '@eventcatalog/utils';

// Adds an event to the domain
const { addEventToDomain, addCommandToDomain, addQueryToDomain } = utils('/path/to/eventcatalog');

// Adds a new event (OrderCreated) that the Orders domain will send
await addEventToDomain('Orders', 'sends', { id: 'OrderCreated', version: '2.0.0' });

// Adds a new event (PaymentProcessed) that the Orders domain will receive
await addEventToDomain('Orders', 'receives', { id: 'PaymentProcessed', version: '1.0.0' });

// Adds a new command (ProcessOrder) that the Orders domain will receive
await addCommandToDomain('Orders', 'receives', { id: 'ProcessOrder', version: '1.0.0' });

// Adds a message to a specific version of the domain
await addEventToDomain('Orders', 'sends', { id: 'OrderShipped', version: '1.0.0' }, '2.0.0');
```
