Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/definition/metadata/AppMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export enum AppMethod {
EXECUTEPREROOMCREATEMODIFY = 'executePreRoomCreateModify',
CHECKPOSTROOMCREATE = 'checkPostRoomCreate',
EXECUTEPOSTROOMCREATE = 'executePostRoomCreate',
EXECUTEBOTPOSTROOMCREATE = 'executeBotPostRoomCreate',
CHECKPREROOMDELETEPREVENT = 'checkPreRoomDeletePrevent',
EXECUTEPREROOMDELETEPREVENT = 'executePreRoomDeletePrevent',
CHECKPOSTROOMDELETED = 'checkPostRoomDeleted',
Expand Down
15 changes: 15 additions & 0 deletions src/definition/rooms/IPostBotRoomCreate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IHttp, IModify, IPersistence, IRead } from '../accessors';
import { IRoom } from './IRoom';

/** Handler for after a dm room with Bot is created. */
export interface IPostBotRoomCreate {
/**
* Method called *after* the room has been created.
*
* @param room The room which was created
* @param read An accessor to the environment
* @param http An accessor to the outside world
* @param persistence An accessor to the App's persistence
*/
executePostBotRoomCreate(room: IRoom, read: IRead, http: IHttp, persistence: IPersistence, modify: IModify): Promise<void>;
}
26 changes: 26 additions & 0 deletions src/server/managers/AppListenerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,32 @@ export class AppListenerManager {
for (const appId of this.listeners.get(AppInterface.IPostRoomCreate)) {
const app = this.manager.getOneById(appId);

// Check if the dm belongs to the app

if (data.type === RoomType.DIRECT_MESSAGE && data.userIds.length > 1) {
if (app.hasMethod(AppMethod.EXECUTEPOSTMESSAGESENTTOBOT)) {
const reader = this.am.getReader(appId);
const bot = await reader.getUserReader().getAppUser();
if (!bot) {
continue;
}

if (!data.userIds.includes(bot.id)) {
continue;
}

await app.call(
AppMethod.EXECUTEBOTPOSTROOMCREATE,
cfRoom,
this.am.getReader(appId),
this.am.getHttp(appId),
this.am.getPersistence(appId),
this.am.getModifier(appId),
);
}
}

// executePostBotRoomCreate
let continueOn = true;
if (app.hasMethod(AppMethod.CHECKPOSTROOMCREATE)) {
continueOn = (await app.call(AppMethod.CHECKPOSTROOMCREATE, cfRoom, this.am.getReader(appId), this.am.getHttp(appId))) as boolean;
Expand Down