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
Appclass from the Rocket.Chat Apps definition library. Your class also has to implement the constructor and optionally the
initializefunction, 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.
app.jsonfile below to understand the structure.
Trueradio button over the Enable development mode.
http://localhost:3000is your local server URL (if you are running in another port, change the
3000to the appropriate port)
usernameis the username of your admin user.
passwordis the password of your admin user.
Appclass. The name of this file is in your
app.jsonfile under the
HelloWorldApp.tsfile. Ignore all the import statements for now. Focus on the main exported class.
IAppInfoobject: This object contains basic information about your app, like the name, the version, description, etc. It is private to the
Appclass but its properties can be accessed via different
ILoggerobject: The logging interface. You can access this object from your child class by using the
IAppAccessorsobject: Object containing all the app accessors. You can access this by using the
getAccessors()method in your child class.
HelloWorldapp does nothing. In this section, we'll make it log
Hello, World!in the Rocket.Chat admin panel.
ILogger. The parent class uses an
ILoggerobject to log stuff to the admin panel. We just need access to that object. Unfortunately, the logger object is private to the
Appclass and so cannot be accessed directly using
getLoggermethod provided by the
Appclass. Simply store the logger in a separate object and then it can be reused any time.
appLoggervariable. Now we can use it to log anything. Add the following line to the constructor.
HelloWorldapp right there. Click on it.
constructor. When you do, click on it.
liftoffslashcommand and it will be called like this by the user inside the chat room:
hello. So you should be able to run
/helloto invoke a function of the app.
Commands, but you are free to choose any other name.
A SlashCommand is an instance of some class type that implements the
ISlashCommandbeing a non-empty interface, the above
HelloWorldCommandclass is incomplete. It must fulfill its promise of conforming to the structure.
HelloWorldCommandclass now must define
string,it is the command name of the command you are to enter after the slash. In this case, the value is
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.
IPersistenceare discussed in a different section.
HelloWorldCommandclass should look like the following now.
IModify.getCreatormethod. In the
executormethod, simply use the
modifyobject to get the creator.
IModifyCreator.startMessagemethod for this.
readobject is going to be useful.
HelloWorldCommand.tsfile looks like:
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.tsfile looks like: