Skip to content

Sending messages

All of these are one call and fully end-to-end encrypted; the key agreement, cipher, signature, and encoding are handled for you. They need a loaded identity. The first argument is the recipient: a numeric user id, a @handle, or a { id } object (handles are resolved and cached).

js
const { sequenceId } = await client.xchat.message("tiagozip_", "hey, encrypted ^w^");
await client.xchat.react("tiagozip_", sequenceId, "🔥");

client.xchat.message(recipient, text, opts?)

Send an encrypted text message. Returns { conversationId, recipientId, messageId, sequenceId, response }. Use the returned sequenceId to react to, edit, or delete the message.

ParamTypeDescription
recipientstring | objectUser id, @handle, or { id }
textstringThe message text
opts.ttlMsecnumberOptional disappearing-message lifetime
js
const sent = await client.xchat.message("44196397", "hello!");
console.log(sent.sequenceId);

client.xchat.react(recipient, messageSequenceId, emoji, opts?)

React to a message with an emoji. messageSequenceId is the target message's sequence id (from a message() result or from reading the conversation).

js
await client.xchat.react("44196397", sequenceId, "🔥");

client.xchat.unreact(recipient, messageSequenceId, emoji, opts?)

Remove a reaction you added.

js
await client.xchat.unreact("44196397", sequenceId, "🔥");

client.xchat.edit(recipient, messageSequenceId, newText, opts?)

Edit one of your sent messages.

js
await client.xchat.edit("44196397", sequenceId, "edited text");

client.xchat.markRead(recipient, sequenceId, opts?)

Mark a conversation read up to a sequence id. opts.seenAtMillis overrides the timestamp (defaults to now).

js
await client.xchat.markRead("44196397", sequenceId);

client.xchat.markUnread(recipient, sequenceId, opts?)

Mark a conversation unread from a sequence id.

js
await client.xchat.markUnread("44196397", sequenceId);

client.xchat.deleteMessages(recipient, sequenceIds, opts?)

Delete one or more messages (by sequence id) from your own view of the conversation.

js
await client.xchat.deleteMessages("44196397", [sequenceId]);

opts.forEveryone: true attempts to unsend for all participants (requires a signed delete action).

Full example

js
import Emusks from "emusks";
import { readFileSync, writeFileSync, existsSync } from "node:fs";

const client = new Emusks();
await client.login("your_auth_token");

if (existsSync("xchat-identity.json")) {
  await client.xchat.loadIdentity(JSON.parse(readFileSync("xchat-identity.json", "utf8")));
} else {
  writeFileSync("xchat-identity.json", JSON.stringify(await client.xchat.createIdentity({ pin: "2468" })));
}

if (await client.xchat.canMessage("tiagozip_")) {
  const { sequenceId } = await client.xchat.message("tiagozip_", "I am Charlie Kirk");
  await client.xchat.react("tiagozip_", sequenceId, "✅");
}

not affiliated with X Corp.