Rocket.Chat.Apps-engine icon indicating copy to clipboard operation
Rocket.Chat.Apps-engine copied to clipboard

feat: `onUpdate` hook for apps

Open KevLehman opened this issue 1 year ago • 1 comments

What? :boat:

Added hook to be called when an app is updated

Why? :thinking:

Because why not 🤷🏽‍♂️ Serious: allows apps to do stuff only when an update happens, like sending messages or create cron jobs.

Links :earth_americas:

Related PR to get user on context: https://github.com/RocketChat/Rocket.Chat/pull/32719

PS :eyes:

KevLehman avatar Jul 03 '24 13:07 KevLehman

Thanks for this!

I just think we're missing here the signature for the method in the App class, like the onInstall event here for example. Regarding contextual information about the event, I'd say it would be cool to know the user who triggered the update and maybe what the previous version was? I'm open to ideas :)

d-gubert avatar Jul 03 '24 17:07 d-gubert

Example usage:

export class ExampleApp extends App {
    public async onUpdate(context: IAppUpdateContext, read: IRead, http: IHttp, persistence: IPersistence, modify: IModify): Promise<void> {
        console.log("Hello from update", context);

        const message = modify.getCreator().startMessage();

        const room = await read.getRoomReader().getById("GENERAL");

        if (!room) {
            throw new Error('oh no');
        }

        message.setText("Hello, thank you for updating!").setRoom(room);

        await modify.getCreator().finish(message);
    }
}

d-gubert avatar Jul 11 '24 20:07 d-gubert