Last active
November 11, 2021 14:12
-
-
Save gregblake/63a3e62c3f67ee2cdb0200af3d8d5926 to your computer and use it in GitHub Desktop.
Creating a Direct Message Using the Matrix JS SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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