Understanding the App Lifecycle


Rocket.Chat Apps are fundamentally different from what you may be used to on other platforms, and that is because they actually run inside a Rocket.Chat server. We use the Node.js VM module to achieve this. This makes it possible for Rocket.Chat users to keep all their data inside their own structure, as the server does not need to send data to an externally hosted service that provides extra functionalities.
For an App to be added to a Rocket.Chat workspace, it needs to be installed in the server either by downloading the package via our Marketplace or by manually uploading the package to said workspace.
These are the steps the Apps-Engine takes to load a Rocket.Chat App:
  • Unpackage the App (zip file) and compile the TypeScript code;
  • Create a sandbox which will provide context for the App's code;
  • Instantiate the App's main class;
  • Initialize the App - App.initialize
  • Enable the App - App.onEnable

Lifecycle Methods

The App class has some methods that can be extended in order to provide some control over various aspects of the App's lifecycle.
Each one of the methods listed below is executed for every instance of the App. This means that they will be executed more than once if Rocket.Chat is running in HA mode (once per instance in the cluster)


public async initialize(configurationExtend: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise<void> {
initialize method allows the App to control its internal initialization process, overriding the default one.


protected async extendConfiguration(configuration: IConfigurationExtend, environment: IEnvironmentRead): Promise<void> {
extendConfiguration method is executed as part of the default initialization process of the App. It enables the App to provide robust functionalities such as API Endpoints or Slash Commands using the configuration accessor.


public async onEnable(environment: IEnvironmentRead, configurationModify: IConfigurationModify): Promise<boolean> {
This method is executed during the enabling process of the App. If it returns false, the Apps-Engine halts the enabling process and unloads the App's resources configured during initialization.


public async onDisable(configurationModify: IConfigurationModify): Promise<void> {
onEnable method is executed during the disabling process of the App. It doesn't allow the App to prevent the disabling from happening.


public async onSettingUpdated(setting: ISetting, configurationModify: IConfigurationModify, read: IRead, http: IHttp): Promise<void> {
onSettingUpdated method is executed after a setting provided by the App is updated by an admin in the App Administration Page. See Settings (coming soon) for more information on how to manage App settings.