Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions xchat/migrate-from-legacy-dms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Existing conversations are upgraded on X's side — you do **not** need to migra
| **Credentials** | OAuth token only | User-context OAuth token **plus** P-256 identity & signing private keys (Juicebox PIN or exported key blob) |
| **Send body** | `{"text": "...", "attachments": [{"media_id": "..."}]}` | SDK-built encrypted, signed payload (`message_id`, `encoded_message_create_event`, `encoded_message_event_signature`, `xdk_version`) |
| **Read response** | `dm_events` objects with plaintext `text`, `sender_id`, `attachments` | `ChatMessageEvent` objects with encrypted `encoded_event`, decrypted via the Chat XDK |
| **Starting a 1:1** | One send call | Conversation-key handshake (`POST /2/chat/conversations/{id}/keys`) first if no key exists, then send |
| **Starting a 1:1** | One send call | Conversation key setup (`POST /2/chat/conversations/{id}/keys`) first if no key exists, then send |
| **Reading history** | Cross-conversation `GET /2/dm_events` feed | No global feed — list `GET /2/chat/conversations` (`?start_time=`), then page `GET /2/chat/conversations/{id}/events` |
| **Media** | Uploaded once via general media upload; server-readable | Client-encrypted (`encrypt_file`), uploaded in chunks, downloaded as ciphertext (`media.write` required for **both** upload and download) |
| **Real-time delivery** | Account Activity `direct_message_*` webhooks / XAA `dm.*` | X Activity API `chat.*` events (stream or webhook), decrypted client-side |
Expand Down Expand Up @@ -184,7 +184,7 @@ Every `/2/chat/*` and `/2/users/*/public_keys` route requires **user-context aut
- **Auth:** `POST /2/activity/subscriptions` accepts both OAuth 2.0 user tokens (`dm.read`) and OAuth 1.0a user tokens (**"Read, Write and Direct Messages"**) for `chat.*` events. OAuth 1.0a tokens without that permission get `403 oauth1-permissions` when subscribing to `chat.*` or `dm.*` events.
- **Group joins:** Subscribe to `chat.conversation.join` so bots learn when added to a group and receive the group conversation key.
- **During cutover:** Unencrypted conversations still arrive as `dm.received` — subscribe to both `dm.received` and `chat.received` and deduplicate until cutover completes.
- **Sender profiles:** Chat events currently carry user IDs only, not names or profiles. Look up profiles with `GET /2/users?ids=...` or `GET /2/chat/conversations?expansions=participant_ids&user.fields=...` and cache by user ID (`includes.users` hydration is being added to chat events).
- **Sender profiles:** Chat events include profile details for the sender and subscribed user in `includes.users` (match `payload.sender_id` against `includes.users[].id`). Because `includes` is best-effort, fall back to `GET /2/users?ids=...` or `GET /2/chat/conversations?expansions=participant_ids&user.fields=...` and cache by user ID if a profile is omitted or you need extra fields.
</Note>
</Tab>

Expand Down Expand Up @@ -218,15 +218,15 @@ Every `/2/chat/*` and `/2/users/*/public_keys` route requires **user-context aut
OAuth access and encryption keys are **separate control planes**: an OAuth token authorizes API calls, while private keys unlock and sign message contents. See [Handling private keys](/xchat/handling-private-keys) for full security rules.

<Warning>
**Never register new keys (`POST /2/users/{id}/public_keys`) on an account that already uses X Chat in the official X app.** Each X account has one active identity key. Registering a new keypair replaces the account's identity, breaks X Chat in the X app, and cuts the account off from existing encrypted conversations.
**Never register new keys (`POST /2/users/{id}/public_keys`) silently on an account that already uses X Chat.** Each X account has one active identity key. Registering a new keypair replaces the account's previous identity and makes messages encrypted under the old keys unreadable — only create new keys on an existing X Chat account with the customer's explicit approval (and have the admin choose a new PIN for secure key backup so they can also use X Chat in the X app).
</Warning>

<Tabs>
<Tab title="Check keys & unlock flow">
<Steps>
<Step title="Check whether the account already has keys">
Call `GET /2/users/{id}/public_keys` (or batch `GET /2/users/public_keys?ids=...` for up to 100 accounts).
- **Key backup details returned:** The account already uses X Chat. Recover the existing keys with the owner's PIN — do **not** register new keys.
- **Key backup details returned:** The account already uses X Chat. Recover the existing keys with the owner's PIN. Only generate and register new keys if the customer explicitly authorizes replacing their existing identity (which makes messages encrypted under the old keys unreadable).
- **No keys returned:** The account has never set up X Chat. For a dedicated bot account (or an uninitialized business account where the admin chooses the PIN in your connect flow so they can still use X Chat in the X app later), generate and register a keypair once via `POST /2/users/{id}/public_keys`.
</Step>

Expand All @@ -251,7 +251,7 @@ OAuth access and encryption keys are **separate control planes**: an OAuth token
| **User-facing web app / agent console** | Run `@xdevplatform/chat-xdk` (WASM) in the browser. User enters PIN on-device; keys stay in memory for the session. | Send PIN or keys to your servers; store raw key blobs in `localStorage`. |
| **Native mobile / desktop app** | Chat XDK on device with Juicebox secure key backup or an OS-keystore-backed blob. | Sync unencrypted key blobs to your cloud. |
| **Dedicated bot account you fully own** | Generate and register keys once; store `export_keys` blob in a secret manager or HSM; load with `import_keys`. | Commit blobs to git, log them, or register per session. |
| **B2B server-side automation on a brand account** | One-time PIN unlock + `export_keys()` into KMS/HSM/Secrets Manager; discard PIN. **Requires explicit customer agreement and X partner approval.** | Register new keys on an existing brand account, or store the PIN. |
| **B2B server-side automation on a brand account** | One-time PIN unlock + `export_keys()` into KMS/HSM/Secrets Manager; discard PIN. **Requires explicit customer agreement and X partner approval.** | Replace an existing brand account's keys without explicit customer approval, or store the PIN. |
| **Ciphertext-only relay or archive** | Hold no private keys. Store and forward encrypted events (including conversation key-change events); decrypt only where keys legitimately live. | Decrypt on the server "for convenience." |
| **Consumer (end-user) accounts** | On-device crypto only. | Collect consumer PINs or private keys on a server. |
</Tab>
Expand Down Expand Up @@ -284,7 +284,7 @@ OAuth access and encryption keys are **separate control planes**: an OAuth token
## 5. Key workflows and caveats

<Tabs>
<Tab title="1:1 handshake & sending">
<Tab title="1:1 key setup & sending">
**Conversation ID formats**

| Form | Example | Where used |
Expand All @@ -293,9 +293,9 @@ OAuth access and encryption keys are **separate control planes**: an OAuth token
| Hyphenated 1:1 (`A-B`) or bare user ID | `1215441834412953600-1603419180975409153` or `1603419180975409153` | Returned in listings and accepted in URL paths. Self-conversations (`A-A`) can appear in listings. |
| Group ID (`g…`) | `g1851674867135033661` | Valid everywhere unchanged. |

**Mandatory 1:1 key handshake (first contact only)**
**Mandatory 1:1 conversation key setup (first contact only)**

If your bot only replies to inbound messages, skip this handshake and reply encrypted with `chat-xdk`. To initiate a new 1:1 conversation with no key yet:
If your bot only replies to inbound messages, skip this step and reply encrypted with `chat-xdk`. To initiate a new 1:1 conversation with no key yet:

<Steps>
<Step title="Fetch and verify both participants' keys">
Expand Down Expand Up @@ -372,11 +372,11 @@ OAuth access and encryption keys are **separate control planes**: an OAuth token

**Key custody & security**
- [ ] Key architecture chosen per [Handling private keys](/xchat/handling-private-keys); X partner approval and customer contract/disclosures completed for any B2B server-side key custody.
- [ ] No code path registers new keys on an account that already has keys; brand account's official X app still works after onboarding.
- [ ] No code path silently registers new keys on an account that already has keys without explicit customer approval; brand account's official X app still works after onboarding.
- [ ] Zero PINs or private keys in databases, env vars, logs, or APM; Juicebox `unlock()` fails closed after one wrong attempt with no auto-retry; `public_key_version` rotation monitored; offboarding deletes all key copies and instructs Reset Chat.

**End-to-end & cutover**
- [ ] Tested: `:` → `-` URL conversion, new 1:1 key handshake, encrypted send & idempotent retry, `chat.received` / `chat.sent` / `chat.conversation.join` delivery & deduplication, encrypted media round-trip, message request accept, group create, and mark read.
- [ ] Tested: `:` → `-` URL conversion, new 1:1 conversation key setup, encrypted send & idempotent retry, `chat.received` / `chat.sent` / `chat.conversation.join` delivery & deduplication, encrypted media round-trip, message request accept, group create, and mark read.
- [ ] Spec caveats handled (`POST …/read` omits `seen_until_sequence_id`; `POST …/members` hand-parsed); permanent `403`s not retried in a loop; rate-limit headers and `retry-after` honored.
- [ ] Enterprise allowlisted apps: coordinated with your X account representative to remove the app from the legacy-DM allowlist after cutover.

Expand Down
12 changes: 6 additions & 6 deletions xchat/migrate-from-legacy-dms/faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ There is no time limit on how far back you can read — page with `pagination_to
<div className="x-faq-item" id="will-my-customers-notice">
<div className="x-faq-q">Will my customers notice?</div>

For most customers this is a small change. At most, a customer may need to enter their X Chat PIN once. Accounts that have never set up X Chat do not need an existing PIN, because you can create encryption keys for them through the API (only do this for accounts with no X Chat keys; storing customer keys on your servers requires X's approval).
For most customers this is a small change. At most, a customer may need to enter their X Chat PIN once. Accounts that have never set up X Chat do not need an existing PIN, because you can create encryption keys for them through the API (never replace existing X Chat keys without the customer's explicit approval; storing customer keys on your servers requires X's approval).

</div>

Expand Down Expand Up @@ -171,7 +171,7 @@ The PIN is used only once, when the admin connects the company's X account. Unlo
<div className="x-faq-q">What if the account has never set a PIN, or the admin doesn't know it?</div>

- **Never set up X Chat (`GET /2/users/{id}/public_keys` returns no keys):** You can create a new keypair for the account through the API and save it. Have the admin choose the account's PIN in your connect flow rather than picking one for them, so the business can still use X Chat in the X app later.
- **Already uses X Chat, but the admin doesn't know the PIN:** Do **not** create new keys — a new keypair replaces the account's identity and breaks X Chat in the X app. The admin must find the PIN or reset it in the X app (resetting makes messages encrypted under the old keys unreadable).
- **Already uses X Chat, but the admin doesn't know the PIN:** Do **not** replace existing keys silently. If the customer authorizes it and understands the trade-off, you can create and register a new keypair through the API (have the admin choose a new PIN in your connect flow so they can also use X Chat in the X app), or the admin can reset their PIN in the X app. Either way, registering new keys replaces the account's previous identity and makes messages encrypted under the old keys unreadable.

Older unencrypted DMs do not need keys at all.

Expand All @@ -180,7 +180,7 @@ Older unencrypted DMs do not need keys at all.
<div className="x-faq-item" id="how-do-i-check-whether-an-account-already-has-keys-or-can-receive-encrypted-chats">
<div className="x-faq-q">How do I check whether an account already has keys or can receive encrypted chats?</div>

Call `GET /2/users/{id}/public_keys` (or batch `GET /2/users/public_keys?ids=...`). If key backup details are returned, the account already uses X Chat — recover the existing keys with the PIN instead of creating new ones.
Call `GET /2/users/{id}/public_keys` (or batch `GET /2/users/public_keys?ids=...`). If key backup details are returned, the account already uses X Chat — recover the existing keys with the PIN, or only create new keys with the customer's explicit approval (replacing keys makes messages encrypted under the old keys unreadable).

To check whether you can start an encrypted chat with someone, request `GET /2/users/{id}?user.fields=receives_your_chat` with the sending account's token: `encrypted` means you can, `unencrypted` means the pair cannot be encrypted yet, and `none` means you cannot message them.

Expand All @@ -198,7 +198,7 @@ Unlock once per account and reuse the result — do not unlock per message or pe
<div className="x-faq-item" id="when-a-recipient-changes-their-pin-or-someone-is-added-to-a-group-chat-do-we-need-to-do-anything">
<div className="x-faq-q">When a recipient changes their PIN or someone is added to a group chat, do we need to do anything?</div>

**No.** The conversation key updates automatically, and you do not need to redo the handshake.
**No.** The conversation key updates automatically, and you do not need to redo conversation key setup.

</div>

Expand Down Expand Up @@ -285,9 +285,9 @@ Existing DM subscriptions do not carry chat events, so create new subscriptions
</div>

<div className="x-faq-item" id="the-chat-events-dont-include-the-senders-name-or-profile-how-do-i-get-them">
<div className="x-faq-q">The chat events don't include the sender's name or profile. How do I get them?</div>
<div className="x-faq-q">Do chat events include the sender's name and profile?</div>

Chat events currently include user IDs only, not names or profiles — each event has the sender's user ID and the conversation ID. Look up profile details with `GET /2/users?ids=...`, or use `GET /2/chat/conversations` / `GET /2/chat/conversations/{id}` with `expansions=participant_ids` and `user.fields`, and cache profiles by user ID. Profile details for the sender and subscribed user are being added to chat events in an `includes.users` block, matching other X Activity API events.
**Yes.** Chat events include profile details for the sender and subscribed user in an `includes.users` block, matching other X Activity API events — resolve each user by matching `payload.sender_id` (and `filter.user_id`) against `includes.users[].id`. Because `includes.users` is hydrated on a best-effort basis, fall back to `GET /2/users?ids=...` or `GET /2/chat/conversations` / `GET /2/chat/conversations/{id}` with `expansions=participant_ids` and `user.fields` (and cache profiles by user ID) if a user is omitted or you need additional fields.

</div>

Expand Down
Loading