RocketChat / Rocket.Chat.Apps-engine

The Rocket.Chat Apps engine and definitions.
https://rocketchat.github.io/Rocket.Chat.Apps-engine/
MIT License
114 stars 119 forks source link

feat: `onUpdate` hook for apps #778

Closed KevLehman closed 5 days ago

KevLehman commented 1 week ago

What? :boat:

https://rocketchat.atlassian.net/browse/CONN-289 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:

d-gubert commented 1 week ago

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 commented 5 days ago

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);
    }
}