Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/sendDirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { IModify,IRead } from "@rocket.chat/apps-engine/definition/accessors";
import { IRoom } from "@rocket.chat/apps-engine/definition/rooms";
import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands";


export async function sendDirect(
context: SlashCommandContext,
read: IRead,
modify: IModify,
message: string
): Promise<void> {
const messageStructure = modify.getCreator().startMessage();
const sender = context.getSender(); // get the sender from context
// get the appUser username
const appUser = await read.getUserReader().getAppUser();
if (!appUser) {
throw new Error("Something went wrong getting App User!");
}
// lets use a function we created to get or create direct room
let room = (await this.getOrCreateDirectRoom(read, modify, [
sender.username,
appUser.username,
])) as IRoom;
messageStructure.setRoom(room).setText(message); // set the text message
await modify.getCreator().finish(messageStructure); // sends the message in the room.
}