rc-apps create
, give it some details and a new folder will be created inside the current working directory with a basic app that does nothing but will compile and be packaged in the dist
folder.HelloWorld
.App
class from the Rocket.Chat Apps definition library. Your class also has to implement the constructor and optionally the initialize
function, for more details on those check the App definition documentation.app.json
, contains basic information about the app. You can check the app-schema.json file for all the detailed information and fields allowed in the app description file.HelloWorld
app's app.json
file below to understand the structure. True
radio button over the Enable development mode.http://localhost:3000
is your local server URL (if you are running in another port, change the 3000
to the appropriate port)username
is the username of your admin user.password
is the password of your admin user.--update
flag isn't strictly necessary for updating an existing App, you can just run the deploy
command without it.App
class. The name of this file is in your app.json
file under the classFile
property.HelloWorldApp.ts
.HelloWorldApp.ts
file. Ignore all the import statements for now. Focus on the main exported class.IAppInfo
object: This object contains basic information about your app, like the name, the version, description, etc. It is private to the App
class but its properties can be accessed via different get
methods.ILogger
object: The logging interface. You can access this object from your child class by using the getLogger()
method.IAppAccessors
object: Object containing all the app accessors. You can access this by using the getAccessors()
method in your child class.HelloWorld
app does nothing. In this section, we'll make it log Hello, World!
in the Rocket.Chat admin panel.ILogger
. The parent class uses an ILogger
object to log stuff to the admin panel. We just need access to that object. Unfortunately, the logger object is private to the App
class and so cannot be accessed directly using this
.getLogger
method provided by the App
class. Simply store the logger in a separate object and then it can be reused any time.appLogger
variable. Now we can use it to log anything. Add the following line to the constructor.Administration
panel.Apps
.HelloWorld
app right there. Click on it.constructor
. When you do, click on it.liftoff
slashcommand and it will be called like this by the user inside the chat room:hello
. So you should be able to run /hello
to invoke a function of the app.Commands
, but you are free to choose any other name.HelloWorldCommand.ts
.A SlashCommand is an instance of some class type that implements theISlashCommand
interface.
interface Person { name: string; }
Person
interface must have a property of type string
called name
. If it doesn't, the file won't compile.ISlashCommand
being a non-empty interface, the above HelloWorldCommand
class is incomplete. It must fulfill its promise of conforming to the structure.HelloWorldCommand
class now must definecommand
string,
it is the command name of the command you are to enter after the slash. In this case, the value is hello
.i18nDescription
i18n
string.i18nParamsExample
i18n
string.providesPreview
executor
ISlashCommand
interface.SlashCommandContext
→ An Object containing information about the context around which the command was run. E.g. the user executing the command, the room where the command was executed, command parameters, etc.IRead
→ This is an object that provides read-only access to the current environment. E.g. room details, user details, app settings, etc.IModify
→ An Object that gives you the ability to modify the environment, or actions that change the environment in some way. E.g. sending a message, creating a room, deleting a room, etc.IHttp
andIPersistence
are discussed in a different section.
HelloWorldCommand
class should look like the following now.IModifyCreator
.IModify.getCreator
method. In the executor
method, simply use the modify
object to get the creator.IModifyCreator.startMessage
method for this.IRead
or in executor
, the read
object is going to be useful.'Hello, World!'
IModifyCreator.finish
method.HelloWorldCommand.ts
file looks like:App.extendConfiguration
method.IConfigurationExtend
. This object is what we'll have to use to 'extend' our app's configurations.HelloWorldCommand
, but that's just the class, or the template or design of the final object, which is the actual slashcommand.HelloWorldApp.ts
file looks like: