Links

App Development Lifecycle

Now that we know how to create Rocket.Chat apps and extend their functionalities, let's learn about the lifecycle of the apps. For Rocket.Chat apps, app lifecycle refers to the processes involved in enabling an app and the phases it may undergo. The app goes through the lifecycle phases during runtime in a Rocket.Chat server.
To add an app to a Rocket.Chat workspace, you must either download it from our Marketplace or manually upload it to the server. Once an app is introduced to Rocket.Chat, it goes through several phases.
Apart from the typical app development phases such as the design, QA, and release phases, additional Rocket.Chat-specific phases include:
  • App Logging
  • App Deployment
  • App Installation
  • App Testing
In the Rocket.Chat UI, two statuses are displayed for apps, enabled and disabled. In the Logs section of an app, you can see additional statuses and their details which give developers an insight into the app's lifecycle phases. You can control various aspects of the app's lifecycle using the extendable methods from the App class. Let's learn about these methods that represent the various states of a functioning app:
Constructed: The app has just been created or instantiated. There is little an app can do at this point.
Initialize: During this phase, the app is initialized. Here, the app can obtain configuration from the Apps-Engine, register objects, and extend functionality. It indicates that the app's initialize() function was invoked and returned true. This enables the app to govern its internal initialization procedure and override the default one.
async initialize(configurationExtend: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise<void>
  • extendConfiguration: This method is executed as part of the app's default initialization procedure. The configuration accessor enables the app to provide robust functionality such as API Endpoints and Slash Commands using the configuration accessor.
async extendConfiguration(configuration: IConfigurationExtend, environment: IEnvironmentRead): Promise<void>
Enable: The app will be enabled if the app parameters are configured correctly. This method is executed during the app's activation process. If it returns false, the Apps-Engine stops the enabling process and unloads the app's resources configured during initialization.
  • Auto_enabled: the app’s onEnable() function is called, returns true, and the app is enabled automatically (at system startup).
  • Manually_enabled: the app’s onEnable() function is called, returns true, and the app is enabled by the user (such as installing a new app).
async onEnable (environment: IEnvironmentRead, configurationModify: IConfigurationModify): Promise<boolean>
Disable: The app can be disabled, either automatically in response to a system interaction or manually through the marketplace. For instance - when Community workspaces have limitations, the apps will be disabled automatically depending on the limit on the number of apps that can be installed per workspace. If the app is a subscription app, it will be disabled when the subscription expires.
async onDisable(configurationModify: IConfigurationModify): Promise<void>
Several additional app phases associated with disable are as follows:
App Phase
Description
compiler_error_disabled
An error occurred while attempting to compile the app, which rendered it inoperable. Attempts to re-enable it will fail, as it requires an update.
invalid_license_disabled
The app was disabled because its license was invalid.
invalid_installation_disabled
The app was disabled due to an invalid installation or signature validation.
error_disable
The app was disabled due to an unrecoverable error.
manually_disabled
A user manually disabled the application.
invalid_settings_disabled
The app was disabled due to invalid configuration settings.
Install: This is only when the application is manually uploaded as a private app or installed through the marketplace. It only occurs once during installation. After installation, you can send messages to the admin notifying them about the availability of the app or send configuration steps and instructions on how to get started to the user who is installing the app.
async onInstall(context: IAppInstallationContext, read: IRead, http: IHttp, persistence: IPersistence, modify: IModify): Promise<void>
Uninstall: This phase occurs when a user manually uninstalls an app. This is not feasible to occur automatically. Upon uninstallation, you can use this status to perform housekeeping, notify the server or an external service, or send a message to the user.
public async onUninstall(context: IAppUninstallationContext, read: IRead, http: IHttp, persistence: IPersistence, modify: IModify): Promise<void>
SettingUpdated: For instance, the settings for an app can include tokens to authenticate with third-party services. When a change is made to such settings, the app can respond accordingly. The onSettingUpdated method is executed when an administrator modifies a setting provided by the app via the App Administration Page. This occurs following the update of a configuration. You can now retrieve the modified value.
async onSettingUpdated(setting: ISetting, configurationModify: IConfigurationModify, read: IRead, http: IHttp): Promise<void>
PreSettingUpdate: This retrieves a modified parameter's before and after values. For example, if the user modifies a server URL, the app can attempt to connect to the new server to perform validations or seamlessly react to the change.
async onPreSettingUpdate(context: ISettingUpdateContext, configurationModify: IConfigurationModify, read: IRead, http: IHttp): Promise<ISetting>
We have now taken a look at the various states of an app and the methods that represent them. With these methods, you can perform different actions for the states of the apps.
Last modified 1mo ago
Rocket.Chat versions receive support for six months after release.