how to create a direct message
neversuspend opened this issue · comments
const messageBuilder = modify.getCreator().startMessage()
.setSender(sender)
.setText(body)
.setRoom(room);
I can send a message to room
How can I send a message to a user (direct message)
Thanks.
Example code
const user2 = context.getSender();
const user1 = await read.getUserReader().getAppUser() as IUser;
let room = await read
.getRoomReader()
.getDirectByUsernames([user1.username, user2.username]);
if (!room) {
const rid = await modify
.getCreator()
.finish(
modify
.getCreator()
.startRoom()
.setCreator(user1)
.setType(RoomType.DIRECT_MESSAGE)
.setMembersToBeAddedByUsernames([user2.username]),
);
room = (await read.getRoomReader().getById(rid)) as IRoom;
}
// room is now your direct message room
Closing this issue since not a but.
Thank you very much!