# Messaging

> Conversations and messages shared by channels, record discussions and the inbox: channels, direct and group messages, one conversation per record, members with read markers and notification levels, threads, mentions, edits with history, pins, resolved threads, scheduled sends, files and reactions. Members, the tenant or the record's readers read a conversation; Realtime pings carry ids only.

- Category: Collaboration
- Module: `messaging`
- Modes: `managed`, `custom`
- Docs: https://bettersupabase.com/docs/blocks/messaging
- Page: https://bettersupabase.com/blocks/messaging

## Install

```bash
npx better-supabase add messaging
```

The command also installs `updated-at`, `tenant`, `access`, `subjects`.

## Configure

Add the block to `better-supabase.config.ts`:

```ts
import { defineConfig } from "better-supabase/config";

export default defineConfig({
  blocks: {
    // Required by messaging; add installs them too.
    "updated-at": {},
    tenant: {},
    access: {},
    subjects: {},
    // Modes: "managed", "custom". The default is "managed".
    messaging: { mode: "managed" },
  },
});
```

## Client

The React hooks are in `better-supabase/blocks/messaging/react`. They return data and actions and render no UI. Source: https://github.com/ScaleDockHQ/better-supabase/blob/main/packages/better-supabase/src/blocks/messaging/react/index.ts

## Events

- `conversation.archived`
- `conversation.created`
- `conversation.member_added`
- `conversation.member_removed`
- `message.deleted`
- `message.edited`
- `message.pinned`
- `message.resolved`
- `message.sent`

## Related blocks

Requires: [tenant](https://bettersupabase.com/blocks/tenant.md), [access](https://bettersupabase.com/blocks/access.md), [subjects](https://bettersupabase.com/blocks/subjects.md)

Works with: [notifications](https://bettersupabase.com/blocks/notifications.md), [jobs](https://bettersupabase.com/blocks/jobs.md), [profiles](https://bettersupabase.com/blocks/profiles.md), [attachments](https://bettersupabase.com/blocks/attachments.md), [reactions](https://bettersupabase.com/blocks/reactions.md), [data-lifecycle](https://bettersupabase.com/blocks/data-lifecycle.md), [inbox](https://bettersupabase.com/blocks/inbox.md), [moderation](https://bettersupabase.com/blocks/moderation.md)

## Recipes

- [Channel sidebar](https://bettersupabase.com/recipes/channel-sidebar.md): The caller's channels with unread and mention counts, kept live, with dialogs to browse, join and create channels.
- [Message list](https://bettersupabase.com/recipes/message-list.md): A conversation's messages over Realtime, with older pages on demand, who is typing, reply counts and the composer.
- [Message composer](https://bettersupabase.com/recipes/message-composer.md): A message box that sends on Enter, signals typing, and uploads dropped, pasted or picked files onto the message.
- [Thread panel](https://bettersupabase.com/recipes/thread-panel.md): A thread beside the channel: the root message, its replies live over Realtime, and a composer that replies into it.
- [Presence avatars](https://bettersupabase.com/recipes/presence-avatars.md): Who else has a record open (a channel, a comment thread's record or a document), on the record's presence topic.
