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

***

# Function: addMessageToService()

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

Defined in: services.ts:400

Add an event/command to a service by it's id.

Optionally specify a version to add the event to a specific version of the service.

## 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`                                                                           |
| `event`          | { `fields`: `string`\[]; `group`: `string`; `id`: `string`; `version`: `string`; } |
| `event.fields`?  | `string`\[]                                                                        |
| `event.group`?   | `string`                                                                           |
| `event.id`?      | `string`                                                                           |
| `event.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 service or command to the service
const { addEventToService, addCommandToService } = utils('/path/to/eventcatalog');

// Adds a new event (InventoryUpdatedEvent) that the InventoryService will send
await addEventToService('InventoryService', 'sends', { event: 'InventoryUpdatedEvent', version: '2.0.0' });
* // Adds a new event (OrderComplete) that the InventoryService will receive
await addEventToService('InventoryService', 'receives', { event: 'OrderComplete', version: '1.0.0' });

// Adds a new command (UpdateInventoryCommand) that the InventoryService will send
await addCommandToService('InventoryService', 'sends', { command: 'UpdateInventoryCommand', version: '2.0.0' });
// Adds a new command (VerifyInventory) that the InventoryService will receive
await addCommandToService('InventoryService', 'receives', { command: 'VerifyInventory', version: '1.0.0' });
```
