Skip to content

Instantly share code, notes, and snippets.

@debdutdeb
Created July 20, 2023 18:58
Show Gist options
  • Save debdutdeb/7be6469ff0729fde8cc52ec9773b6a5b to your computer and use it in GitHub Desktop.
Save debdutdeb/7be6469ff0729fde8cc52ec9773b6a5b to your computer and use it in GitHub Desktop.
example app for uploading files
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 { ISlashCommand, SlashCommandContext } from '@rocket.chat/apps-engine/definition/slashcommands';
import { IUser } from '@rocket.chat/apps-engine/definition/users';
export default class UploadApp 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 = "upload"
i18nDescription: string = ""
i18nParamsExample: string = ""
providesPreview: boolean = false
async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): Promise<void> {
const url = "https://www.africau.edu/images/default/sample.pdf"
const res = await http.get(context.getArguments()[0] || url)
if (!res.content) {
return;
}
modify.getCreator().getUploadCreator().uploadBuffer(Buffer.from(res.content, "utf-8"), {
filename: context.getArguments()[1] || 'dummy.pdf',
room: context.getRoom(),
user: (await read.getUserReader().getAppUser()) as IUser
});
}
}))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment