> For the complete documentation index, see [llms.txt](https://marblejs.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://marblejs.gitbook.io/docs/other/api-reference/messaging/reply.md).

# reply

### **Importing** <a href="#importing" id="importing"></a>

```typescript
import { reply } from '@marblejs/messaging';
```

### **Type declaration**

```haskell
reply :: string -> Event -> Event
reply :: EventMetadata -> Event -> Event
reply :: Event -> Event -> Event
```

The function is responsible for constructing a reply-event for a channel name, EventMetadata object or origin event.

### **Example**

**Reply to channel:**

```typescript
import { act, matchEvent } from '@marblejs/core';
import { reply, MsgEffect } from '@marblejs/messaging';

const foo$: MsgEffect = event$ =>
  event$.pipe(
    matchEvent('FOO'),
    act(event => reply('event_bus')({ type: 'FOO_RESPONSE' })),
  );
```

**Reply with metadata construct:**

```typescript
import { act, matchEvent } from '@marblejs/core';
import { reply, MsgEffect } from '@marblejs/messaging';

const foo$: MsgEffect = event$ =>
  event$.pipe(
    matchEvent('FOO'),
    act(event => reply({
      replyTo: event.metadata.replyTo,
      correlationId: event.metadata.correlationId,
    })({ type: 'FOO_RESPONSE' })),
  );
```

**Reply to event:**

```typescript
import { act, matchEvent } from '@marblejs/core';
import { reply, MsgEffect } from '@marblejs/messaging';

const foo$: MsgEffect = event$ =>
  event$.pipe(
    matchEvent('FOO'),
    act(event => reply(event)({ type: 'FOO_RESPONSE' })),
  );
```
