Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: onUpdate hook for apps #778

Merged
merged 7 commits into from
Jul 11, 2024
Merged

feat: onUpdate hook for apps #778

merged 7 commits into from
Jul 11, 2024

Conversation

KevLehman
Copy link
Contributor

@KevLehman KevLehman commented Jul 3, 2024

What? β›΅

https://rocketchat.atlassian.net/browse/CONN-289
Added hook to be called when an app is updated

Why? πŸ€”

Because why not πŸ€·πŸ½β€β™‚οΈ
Serious: allows apps to do stuff only when an update happens, like sending messages or create cron jobs.

Links 🌎

Related PR to get user on context: RocketChat/Rocket.Chat#32719

PS πŸ‘€

src/server/AppManager.ts Outdated Show resolved Hide resolved
@KevLehman KevLehman requested a review from d-gubert July 3, 2024 16:58
@d-gubert
Copy link
Member

d-gubert commented Jul 3, 2024

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
Copy link
Member

d-gubert commented Jul 11, 2024

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 d-gubert marked this pull request as ready for review July 11, 2024 20:45
src/server/AppManager.ts Outdated Show resolved Hide resolved
@d-gubert d-gubert merged commit c15cfeb into alpha Jul 11, 2024
8 checks passed
@d-gubert d-gubert deleted the feat/onupdate-app branch July 11, 2024 21:16
@d-gubert d-gubert mentioned this pull request Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants