Skip to content

Instantly share code, notes, and snippets.

@gregblake
Last active November 11, 2021 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregblake/63a3e62c3f67ee2cdb0200af3d8d5926 to your computer and use it in GitHub Desktop.
Save gregblake/63a3e62c3f67ee2cdb0200af3d8d5926 to your computer and use it in GitHub Desktop.
Creating a Direct Message Using the Matrix JS SDK
const createRoom = (userIdForNewDM) => {
enum Preset {
PrivateChat = "private_chat",
TrustedPrivateChat = "trusted_private_chat",
PublicChat = "public_chat",
}
enum Visibility {
Public = "public",
Private = "private",
}
const options = {
preset: Preset["TrustedPrivateChat"],
visibility: Visibility["Private"],
invite: [userIdForNewDM],
is_direct: true,
initial_state: [
{
type: "m.room.guest_access",
state_key: "",
content: { guest_access: "can_join" },
},
],
};
const room = client.createRoom(options);
return room;
};
createRoom(userIdForNewDM)
.then((room) => {
history.push(`/${room.room_id}`);
handleCloseModal();
})
.catch((error) => alert(`Error: ${error}`));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment