- Print
- DarkLight
- PDF
Create an App
- Print
- DarkLight
- PDF
In this document, you will learn about the Apps-Engine commands and create a basic app.
Apps-Engine CLI commands
rc-apps
is a command-line interface (CLI) utility that provides commands to rapidly develop a Rocket.Chat application. Initiate rc-apps
in your terminal to view the list of commands that you can execute as needed.
Here is a list of commands that Rocket.Chat Apps-Engine supports:
Command | Description | Example |
---|---|---|
| Displays installation instructions. Note: This command is not supported on Windows. |
|
| Simplifies the process of creating an app. |
|
| Deploys an app to the server. |
|
| Creates boilerplate code files in the current directory for the following:
|
|
| Displays the CLI tool for helping with Rocket.Chat Apps. |
|
| Provides the steps for logging into Rocket.Chat Cloud. |
|
| Revokes the Rocket.Chat Cloud credentials. |
|
| Packages the app for distribution. |
|
| Submits an app to the marketplace for review. |
|
| Monitors app changes and redeploys the modified app to the server. |
|
Create a basic app
Now that you've understood the basic concepts of the Apps-Engine and installed the CLI, let's build our initial app Hello World
.
Make sure that you have the setup environment ready.
Step 1: Execute the create command
To create a new app, in the command line, execute rc-apps create
.
Enter the following app details:
App Name:
Hello World
App Description:
A basic app that prints Hello World!
Author’s Name:
John
Author’s Home Page:
rocketchat.com
Author’s Support Page:
support.rocketchat.com
A folder with the app name is created in the current working directory (in this case, hello-world
). The hello-world
folder contains a simple app that will only compile and be packaged in the dist
folder.
Troubleshooting tip
If you receive the error message 'TypeError: Cannot read properties of undefined [reading 'message']', do not be alarmed. You can disregard this and use the
cd <folder-name>
command to determine if a folder for your application was created.
Step 2: Open the app folder in Visual Studio
Launch Visual Studio and select Open Folder from the sidebar on the left.
Select the app folder that was created in the previous step.
Once the folder has been uploaded, its contents will be displayed in the sidebar.
Step 3: Comprehend the structure of the app
The app manifest file
app.json
contains basic details about the app:
{
"id": "28d63257-94c3-40e8-83eb-9581244598b6",
"version": "0.0.1",
"requiredApiVersion": "^1.4.0",
"iconFile": "icon.png",
"author": {
"name": "John",
"homepage": "rocketchat.com",
"support": "[email protected]"
},
"name": "Hello World",
"nameSlug": "hello-world",
"classFile": "HelloWorldApp.ts",
"description": "A basic app that prints Hello World!"
}
A Rocket.Chat app is a TypeScript project that contains a main file with a class extending the main
App
class from the Apps-Engine. The identity of this file can be found in theclassFile
property of yourapp.json
file. For this example, locate and open theHelloWorldApp.ts
TypeScript file.The following code snippet shows the class in the
HelloWorldApp.ts
file:
export class HelloWorldApp extends App {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}
}
Observe that the class name and filename are identical. This is intentional. You can either use the same name for the class and the file for the application to compile successfully, or export the primary app class by default as shown below:
export default class HelloWorldApp extends App {
// ...
}
For a functioning app, you must define a constructor to access a large number of parent properties. The constructor accepts three arguments:
An
IAppInfo
object: This object contains fundamental information about your application, such as its name, version, description, etc. It is private to theApp
class, but its properties are accessible through multiple GET methods.An
ILogger
object: This object is the interface for logging. ThegetLogger()
method allows access to this object from within a child class.An
IAppAccessors
object: This object contains all app accessors. This can be accessed via thegetAccessors()
method in the child class.
Learn more about the module details from the Rocket.Chat Apps Typescript definition.
Step 4: Implement the app functionality
For this example, the app records "Hello, World!" in the Rocket.Chat administration interface.
To log data, you must first have access to the logger, that is, an object of type ILogger
. The parent class logs data to the administration interface using an ILogger
object. We only require access to this object. Since the logger object is private to the App
class, the this
keyword cannot be used to access it directly.
To resolve this, use the getLogger
method provided by the App
class. You need to store the logger as a separate object that can be reused whenever necessary.
Modify the class in the HelloWorldApp.ts
file as follows:
export class HelloWorldApp extends App {
private readonly appLogger: ILogger
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors)
this.appLogger = this.getLogger()
}
}
We have just stored the accessor for the log file in the appLogger
variable. Now, we can record anything with it. Add the line shown below to the constructor and save the file.
this.appLogger.debug('Hello, World!')
Step 5: Deploy to the server
In the command line, go to the hello-world
app folder that was created in Step 1: Execute the create command. To deploy the app, run:
rc-apps deploy --url <server_url> -u <user> -p <pwd>
Replace
<server_url>
with the URL of your Rocket.Chat workspace.Replace
<user>
and<pwd>
with your username and password, respectively.
After executing this command, your application will be deployed to the server.
To explore alternative authentication options for deploying your app, such as using 2FA codes or personal access tokens, run the rc-apps deploy --help
command.
Packaging your app
Alternatively, you can execute the
rc-apps package
command. This gives you a compressed zip file of your app that you can upload as a private app to your Rocket.Chat server.
Step 6: Test the app
To test your app, you need a Rocket.Chat server running locally on your machine and the credentials of an administrator user.
In older versions of Rocket.Chat, you might need to enable apps development mode for manual installations to be allowed.
To enable apps development mode:
Go to Administration > General > Apps.
Click
True
next to Enable development mode.To run Rocket.Chat in develop mode, see the development environment setup guide.
In this example, the function of the application is to log Hello, World!
to the console. To test the app's functionality, we must examine the app logs.
Follow these steps to examine the logs:
Login to your Rocket.Chat workspace as an admin.
Navigate to the Administration Panel.
Under Apps, select Marketplace.
Select Private Apps from the left-hand menu. You should see the Hello World app.
Click on the three dots icon on the right-hand side of the app. From the menu, click on View Logs.
The App Info page opens on the Logs tab. Scroll down until you see the
"constructor"
expandable section. Select it and you can see the message"Hello, World!"
logged in the console.
Congratulations, you just created your first app — a simple Hello World app!
To learn how to add more functionalities to your app, proceed to the next topic.
Troubleshooting
Failed to resolve module error while deploying the app.
If you get the following errors when deploying the app:
Error: Failed to resolve module: @rocket.chat/ui-kit
Error: Failed to resolve module: @rocket.chat/icons
Run the following commands to install these modules:
npm install @rocket.chat/ui-kit
npm install @rocket.chat/icons
After this, run the deployment command again.