Skip to content

Reading messages

List your conversations and read decrypted message history. Reading needs a loaded identity (decryption uses your private key).

js
await client.xchat.loadIdentity(identity);

for (const convo of await client.xchat.conversations()) {
  console.log(convo.conversationId, convo.latestMessage?.text);
}

const { messages } = await client.xchat.read("tiagozip_");
for (const m of messages) {
  if (m.kind === "message") console.log(m.senderId, m.text);
}

client.xchat.conversations(opts?)

List all your conversations (the inbox), newest first. Each conversation's latest message is decrypted for you.

Returns an array of:

FieldDescription
conversationIdThe conversation id (for 1:1, minId:maxId)
type"direct" or "group"
participantsMember user ids
groupNameGroup name (groups only)
isMutedWhether you've muted it
latestSequenceIdSequence id of the most recent event
latestMessageThe decoded latest message (see read below), if any
js
const convos = await client.xchat.conversations();

client.xchat.read(recipient, opts?)

Read and decrypt a conversation's messages. Returns { conversationId, hasMore, messages }. Pass opts.before (a sequence id) to page into older history.

Each entry in messages is decoded and decrypted:

FieldDescription
sequenceIdThe event's sequence id
senderIdWho sent it
createdAtTimestamp (ms, string)
kind"message", "reaction_add", "reaction_remove", "edit", "delete", "conversation_key_change", …
textThe decrypted message text (for message / edit)
emojiThe reaction (for reaction_add / reaction_remove)
targetSequenceIdThe message a reaction/edit applies to
js
const { messages, hasMore } = await client.xchat.read("tiagozip_");
for (const m of messages) {
  if (m.kind === "message") console.log(`${m.senderId}: ${m.text}`);
  if (m.kind === "reaction_add") console.log(`${m.senderId} reacted ${m.emoji}`);
}

TIP

read decrypts received messages (and reactions, edits, deletes). Like the official client, the server's message pull does not re-deliver your own sent messages, so a fresh client sees the other party's messages plus key-change and delete events; your outgoing messages are the ones you got back from message().

not affiliated with X Corp.