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 bothtwenty-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.
src/logic-functions/notify-first-recording.ts
workspaceMemberIdslists the members who receive the conversation, at least one unless you post 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.threadKeypicks the conversation for this app, shared by every member it is sent to. A new key starts a conversation titledtitle; a key you used before adds the message to that conversation.idempotencyKeyidentifies the message within the conversation. Sending again with the same keys writes nothing new, so retries and concurrent runs never duplicate a message.textis markdown, and can carry mentions and record references. A member it mentions is notified, even when they are not inworkspaceMemberIds.toolCalls(optional) ends the message on one or more actions, each one of:- a call the member answers, which pauses the conversation:
ask_question(one multiple-choice question),request_form(fields to fill in) orpropose_tool_call(a call to approve). Itsinputtakes thetoolName, theargumentsyou would call the tool with and a one-sentencesummary. The tool must be one your app’s default role could run itself, such ascreate_one_personorupdate_one_opportunity(with the recordid); an email (send_emailordraft_email, withrecipients,subjectand abodythat 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 theinputandoutputyou pass. It does not pause the conversation.
- a call the member answers, which pauses the conversation:
toolCallis deprecated and will be removed: it takes a single action, liketoolCallswith one entry. UsetoolCalls, 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
AIpermission, and the call fails without writing the message when one of them cannot have the conversation. Your app’s default role must grantSystemPermissionFlag.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.
src/logic-functions/post-call-recap.ts
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:- 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.
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 shows how to open the conversation afterwards.
Posting to a channel
Declare a channel withdefineInboxChannel() to give your app’s conversations a shared place, such as a triage queue, instead of naming members one by one.
src/inbox-channels/factory.inbox-channel.ts
roleUniversalIdentifiersopens 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.
inboxChannelUniversalIdentifier:
src/logic-functions/notify-review.ts
- 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.
workspaceMemberIdsbecomes 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_FOUNDand writes nothing.
Mentions and record references
The inbox renders reference tokens intext as chips. Write them with these helpers rather than by hand:
src/logic-functions/flag-idle-deal.ts
inboxMention({ workspaceMemberId })writes a mention of a workspace member, andinboxReferenceRecord({ 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 theAIpermission, 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 newidempotencyKeymentions again. - Only a complete mention notifies. One in inline code or a code block, one whose brackets are escaped (
\[\[), and a typed@namenotify no one. A record reference never notifies, and never shares the record. INBOX_ASSISTANT_MENTIONwrites 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.
src/logic-functions/file-call-recap.ts
- Both take the conversation’s
threadIdand the record asobjectNameSingularandrecordId. 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, which needs the
AIpermission. 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 withTHREAD_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.
src/logic-functions/on-email-sent-archive-thread.ts
- 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_FOUNDand 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.
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.