> ## Documentation Index
> Fetch the complete documentation index at: https://docs.twenty.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Inbox

> Post messages from your app in members' inbox or in a channel it ships, from a logic function or a front component.

## Overview

Your app can start and continue conversations in the inbox of workspace members, where they also talk with Twenty's assistant. A message can end on questions, forms or changes to approve, which the member answers from the chat before the conversation continues with the assistant.

The inbox helpers are exported from both `twenty-sdk/logic-function` and `twenty-sdk/front-component`, so a scheduled run and a button in your app post the same way.

## Sending a message

`sendInboxMessage()` posts a message from your app in the chats of one or more workspace members and returns the conversation's `threadId`.

```ts src/logic-functions/notify-first-recording.ts theme={null}
import { sendInboxMessage } from 'twenty-sdk/logic-function';

const { threadId } = await sendInboxMessage({
  workspaceMemberIds: [workspaceMemberId],
  threadKey: 'first-call-recording',
  idempotencyKey: 'first-call-recording',
  title: 'Your first call recording is ready',
  text: 'Your first call was recorded: **Weekly sync**.',
  toolCalls: [
    {
      toolName: 'ask_question',
      input: {
        header: 'Share',
        question: 'Do you want to share it with the other attendees?',
        options: [{ label: 'Draft a recap email' }, { label: 'Not now' }],
      },
    },
  ],
});
```

Key points:

* `workspaceMemberIds` lists the members who receive the conversation, at least one unless you [post to a channel](#posting-to-a-channel). The first member of a new conversation owns it, and the others follow it as participants. A later send under the same key that lists new members adds them; members it leaves out keep the conversation.
* `threadKey` picks the conversation for this app, shared by every member it is sent to. A new key starts a conversation titled `title`; a key you used before adds the message to that conversation.
* `idempotencyKey` identifies the message within the conversation. Sending again with the same keys writes nothing new, so retries and concurrent runs never duplicate a message.
* `text` is markdown, and can carry [mentions and record references](#mentions-and-record-references). A member it mentions is notified, even when they are not in `workspaceMemberIds`.
* `toolCalls` (optional) ends the message on [one or more actions](#several-actions-in-one-message), each one of:
  * a call the member answers, which pauses the conversation: `ask_question` (one multiple-choice question), `request_form` (fields to fill in) or `propose_tool_call` (a call to approve). Its `input` takes the `toolName`, the `arguments` you would call the tool with and a one-sentence `summary`. The tool must be one your app's default role could run itself, such as `create_one_person` or `update_one_opportunity` (with the record `id`); an email (`send_email` or `draft_email`, with `recipients`, `subject` and a `body` that names its format: `{ type: 'html', html }` or `{ type: 'text', text }`; a bare string is rejected) needs no permission of your app. The member reviews the call in the same card as a call the assistant proposes, edits it if they want, and the approved call runs with their own access;
  * one of your app's own tools, by `logicFunctionUniversalIdentifier`, rendered by its front component with the `input` and `output` you pass. It does not pause the conversation.
* `toolCall` is deprecated and will be removed: it takes a single action, like `toolCalls` with one entry. Use `toolCalls`, and never set both.
* A conversation waits on one message at a time: sending another message with a call the member answers, before they have answered every call of the waiting one, fails with `THREAD_AWAITING_ANSWER`. Plain messages and app tool calls are still accepted.
* Only the member who owns a conversation can delete it, and a deleted conversation is gone for every member: it is not recreated, and nothing is added to it. The other members can unsubscribe to take it out of their own inbox.
* Every member must have the `AI` permission, and the call fails without writing the message when one of them cannot have the conversation. Your app's [default role](https://docs.twenty.com/developers/extend/apps/config/roles.md) must grant `SystemPermissionFlag.AI`.

### Several actions in one message

`toolCalls` takes up to 10 calls, in the order the message shows them. Calls the member answers stack like the ones the assistant proposes in a single reply: the member approves, edits or discards each one on its own, and the assistant takes over the conversation after the last answer. Your app's own tools in the list render with the message and wait for nothing.

```ts src/logic-functions/post-call-recap.ts theme={null}
import { sendInboxMessage } from 'twenty-sdk/logic-function';

await sendInboxMessage({
  workspaceMemberIds: [workspaceMemberId],
  threadKey: `call-recap-${call.id}`,
  idempotencyKey: `call-recap-${call.id}`,
  title: `Recap of ${call.title}`,
  text: call.summary,
  toolCalls: [
    {
      logicFunctionUniversalIdentifier: CALL_RECORDING_TOOL_UNIVERSAL_IDENTIFIER,
      input: { callRecordingId: call.id },
    },
    {
      toolName: 'propose_tool_call',
      input: {
        toolName: 'send_email',
        arguments: {
          recipients: { to: attendeeEmails.join(', '), cc: '', bcc: '' },
          subject: `Follow-up: ${call.title}`,
          body: { type: 'text', text: followUpEmailText },
        },
        summary: 'Send the follow-up email to the attendees',
      },
    },
    {
      toolName: 'propose_tool_call',
      input: {
        toolName: 'update_one_opportunity',
        arguments: { id: opportunity.id, stage: 'PROPOSAL' },
        summary: 'Move the deal to proposal',
      },
    },
  ],
});
```

A message with more than 10 calls, or with both `toolCall` and `toolCalls`, is refused without writing anything, and so is a message with one invalid call.

### Who sends the message

A message is always written by your app, whatever triggered the call. The call itself runs like the default [API clients](https://docs.twenty.com/developers/extend/apps/logic/logic-functions.md#whose-access-a-call-uses):

* In a logic function, it acts as the person who triggered the run, or as your application when nobody did, such as on a cron schedule.
* In a front component, it acts as the member looking at the page. When the token has expired, the call refreshes it once through Twenty and retries.

The person behind the call needs the `AI` permission as well, like every recipient.

To post from a front component, import the same helpers from `twenty-sdk/front-component`. [Posting to the inbox](https://docs.twenty.com/developers/extend/apps/layout/front-components.md#posting-to-the-inbox) shows how to open the conversation afterwards.

## Posting to a channel

Declare a channel with `defineInboxChannel()` to give your app's conversations a shared place, such as a triage queue, instead of naming members one by one.

```ts src/inbox-channels/factory.inbox-channel.ts theme={null}
import { defineInboxChannel } from 'twenty-sdk/define';

import { FACTORY_ROLE_UNIVERSAL_IDENTIFIER } from 'src/roles/factory.role';

export const FACTORY_INBOX_CHANNEL_UNIVERSAL_IDENTIFIER =
  'b6c1d1a4-3c1e-4c55-9a38-6f2b2f5d7e10';

export default defineInboxChannel({
  universalIdentifier: FACTORY_INBOX_CHANNEL_UNIVERSAL_IDENTIFIER,
  name: 'Factory',
  icon: 'IconBuildingFactory2',
  roleUniversalIdentifiers: [FACTORY_ROLE_UNIVERSAL_IDENTIFIER],
});
```

* `roleUniversalIdentifiers` opens the channel to roles your app ships. Name your app's default role to let your app post to it. Workspaces open it to their own roles from Settings.
* Workspaces can rename, recolor and reorder the channel: later syncs keep their changes. They cannot delete it, since it belongs to your app.
* Removing the channel from your app, or uninstalling the app, deletes it. Its conversations move to General.

Then send with `inboxChannelUniversalIdentifier`:

```ts src/logic-functions/notify-review.ts theme={null}
import { sendInboxMessage } from 'twenty-sdk/logic-function';

import { FACTORY_INBOX_CHANNEL_UNIVERSAL_IDENTIFIER } from 'src/inbox-channels/factory.inbox-channel';

await sendInboxMessage({
  inboxChannelUniversalIdentifier: FACTORY_INBOX_CHANNEL_UNIVERSAL_IDENTIFIER,
  threadKey: `pull-request-${pullRequest.number}`,
  idempotencyKey: `pull-request-${pullRequest.number}-ready`,
  title: pullRequest.title,
  text: 'Ready for review.',
});
```

* A new conversation is filed in the channel, and so is an earlier one under the same key that is in no channel and has no owner. A conversation a member already moved stays where it is.
* `workspaceMemberIds` becomes optional. Name members as well to also bring the conversation to their inbox.
* A conversation started with no member has no owner. Later sends cannot add members to it (they fail with `THREAD_NOT_FOUND`), and its mentions notify no one, so name the members on the first send if they should hear about it.
* The caller needs access to the channel, through one of its roles or a role that can access every channel; otherwise the call fails with `CHAT_CHANNEL_NOT_FOUND` and writes nothing.

## Mentions and record references

The inbox renders reference tokens in `text` as chips. Write them with these helpers rather than by hand:

```ts src/logic-functions/flag-idle-deal.ts theme={null}
import {
  inboxMention,
  inboxReferenceRecord,
  sendInboxMessage,
} from 'twenty-sdk/logic-function';

const ownerMention = await inboxMention({ workspaceMemberId: owner.id });
const managerMention = await inboxMention({ workspaceMemberId: manager.id });

const dealReference = await inboxReferenceRecord({
  objectNameSingular: 'opportunity',
  recordId: opportunity.id,
});

await sendInboxMessage({
  workspaceMemberIds: [owner.id, salesOps.id],
  threadKey: `idle-deal-${opportunity.id}`,
  idempotencyKey: `idle-deal-${opportunity.id}-${weekNumber}`,
  title: `${opportunity.name} is idle`,
  text: `${ownerMention}, ${dealReference} has had no activity for two weeks. ${managerMention}, can you help?`,
});
```

* `inboxMention({ workspaceMemberId })` writes a mention of a workspace member, and `inboxReferenceRecord({ objectNameSingular, recordId })` a chip that links to any record.
* Both read the label the chip shows, as the composer does: the member's full name, or their email when the name is empty, and the record's label identifier, such as a company name. Brackets become parentheses and line breaks become spaces, so the chip always renders.
* They read with the same access as the rest of the call, so that access needs to reach the member or record. A record reference makes two requests, one for the object's label field and one for the record.
* A mentioned member gets the conversation in their inbox, unread, with a mention to resolve, as when a teammate mentions them. They don't need to be in `workspaceMemberIds`, and the member who owns the conversation can be mentioned too. A mentioned member who cannot have the conversation, for example without the `AI` permission, is skipped and the message is still sent.
* Mentions notify once, when the message is first written: sending it again with the same keys notifies no one, even with a different `text`, and a new `idempotencyKey` mentions again.
* Only a complete mention notifies. One in inline code or a code block, one whose brackets are escaped (`\[\[`), and a typed `@name` notify no one. A record reference never notifies, and never shares the record.
* `INBOX_ASSISTANT_MENTION` writes the composer's canonical assistant reference. The inbox displays it as `@Ada`; its stable identity is separate from its label. This reference alone does not request an assistant reply from an application message.

## Attaching records to a conversation

`attachRecordToInboxThread()` links a conversation to a record, and `detachRecordFromInboxThread()` removes the link.

```ts src/logic-functions/file-call-recap.ts theme={null}
import {
  attachRecordToInboxThread,
  sendInboxMessage,
} from 'twenty-sdk/logic-function';

const { threadId } = await sendInboxMessage({
  workspaceMemberIds: [owner.id],
  threadKey: `call-recap-${call.id}`,
  idempotencyKey: `call-recap-${call.id}`,
  title: `Recap of ${call.title}`,
  text: call.summary,
});

await attachRecordToInboxThread({
  threadId,
  objectNameSingular: 'company',
  recordId: company.id,
});
```

* Both take the conversation's `threadId` and the record as `objectNameSingular` and `recordId`. A conversation can be linked to people, companies, opportunities and custom object records.
* Both are idempotent: attaching a record twice keeps a single link, and detaching a record that is not attached changes nothing.
* The call runs with the same access as [sending a message](#who-sends-the-message), which needs the `AI` permission. A member must be able to edit the conversation, and your application can act on a conversation it wrote in itself or one its default role was granted; otherwise the call fails with `THREAD_NOT_FOUND`.
* The record must be readable with that access, or the call fails with `RECORD_NOT_FOUND`.

## Archiving a conversation

`archiveInboxThread()` archives a conversation your application wrote, for the members you name, as if each of them had archived it from their inbox. Use it when the work behind a message got done somewhere else: the email you proposed was sent from Gmail, the meeting you asked about was approved in the calendar.

```ts src/logic-functions/on-email-sent-archive-thread.ts theme={null}
import { archiveInboxThread } from 'twenty-sdk/logic-function';

await archiveInboxThread({
  threadId,
  workspaceMemberIds: [owner.id],
});
```

* Only your application can call it, on a conversation it wrote in itself or one its default role was granted; otherwise the call fails with `THREAD_NOT_FOUND`. Members archive from their own inbox.
* Every member you name must be able to read the conversation. If one cannot, the call fails with `THREAD_NOT_FOUND` and archives it for nobody.
* A new message in the conversation brings it back to the inbox, as it does after a member archives it.
* A member who stopped following the conversation is skipped, so it stays out of their inbox.

Leave out `workspaceMemberIds` to mark a conversation done in its channel instead, as a member does from the channel view. Members' own inboxes are left as they are, and a conversation that is in no channel fails with `CHAT_THREAD_NOT_IN_CHANNEL`.

```ts theme={null}
await archiveInboxThread({ threadId });
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.