Last active
July 12, 2023 08:55
-
-
Save debdutdeb/a3c9f715ee3778acb6654cc79bb76a00 to your computer and use it in GitHub Desktop.
https://open.rocket.chat/channel/rocketchat-apps?msg=vuAxxx92rSZn4xEjP, https://github.com/RocketChat/Rocket.Chat.Apps-engine/issues/648
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
import { | |
IAppAccessors, | |
IConfigurationExtend, | |
IEnvironmentRead, | |
IHttp, | |
ILogger, | |
IModify, | |
IPersistence, | |
IRead, | |
} from '@rocket.chat/apps-engine/definition/accessors'; | |
import { App } from '@rocket.chat/apps-engine/definition/App'; | |
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata'; | |
import { IPreRoomCreateModify, IRoom, RoomType } from '@rocket.chat/apps-engine/definition/rooms'; | |
import { ISlashCommand, SlashCommandContext } from '@rocket.chat/apps-engine/definition/slashcommands'; | |
import { IUser } from '@rocket.chat/apps-engine/definition/users'; | |
export class NabhagApp extends App { | |
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) { | |
super(info, logger, accessors); | |
} | |
protected async extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise<void> { | |
await configuration.slashCommands.provideSlashCommand(new (class _ implements ISlashCommand { | |
command = "do" | |
i18nDescription: string = "" | |
i18nParamsExample: string = "" | |
providesPreview: boolean = false | |
async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): Promise<void> { | |
const usernames = [((await read.getUserReader().getAppUser()) as IUser).username, context.getSender().username] | |
const room = await read.getRoomReader().getDirectByUsernames(usernames) | |
await this.send(context.getRoom(), JSON.stringify(room), modify, read) | |
if (room) { | |
return | |
} | |
const id = await modify.getCreator().finish(modify.getCreator().startRoom({ | |
type: RoomType.DIRECT_MESSAGE, | |
creator: context.getSender(), | |
} as IRoom).setMembersToBeAddedByUsernames(usernames)) | |
const direct = await read.getRoomReader().getById(id) | |
await this.send(context.getRoom(), JSON.stringify(direct), modify, read) | |
} | |
async send(room: IRoom, message: string, modify: IModify, read: IRead) { | |
await modify.getCreator().finish(modify.getCreator().startMessage({ | |
sender: await read.getUserReader().getAppUser() as IUser, | |
room, | |
text: message, | |
})) | |
} | |
})) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment