RocketChat is an
application interface for server methods and message stream subscriptions. Using this package, third party apps can control and query a Rocket.Chat server instance, via REST APIs.
Designed especially for chat automation, this library makes it easy for application developers to provide the best solutions and experience for their community.
This library facilitates communication among colleagues, students, clients, organizations, and others by offering public and private channels (groups) as well as one-on-one conversations. It allows you to manage users, visitors, public channels, and private groups. The RocketChat Library's features enable us to build a powerful and flexible communication platform.
RocketChat library, is quite beneficial in the development of apps that we use on a regular basis. It is highly useful for everyday use because we need chat platforms like this for communication, whether it's within organizations or with friends. Some of the typical use cases are mentioned below:
- Chat Application use case:
This use case makes it easy to click on a created / joined channel to see previously posted messages or send new ones. This can be achieved using the postMessageChat API. Here the messages are differentiated into 2 colors, one color for messages sent by you and another color for messages sent by others.
This section of the document lists the features of RocketChat which makes the library easy and useful for communication. REST APIs of RocketChat are grouped into the following categories:
-
Channel Endpoints: These are REST APIs related to public channel. It can be used for creating a channel, leaving a channel, retrieving the history of channel , archiving/Unarchiving the channel etc.
-
Group Endpoints: These endpoints include REST APIs of private channel/group. It is Used for creating a private channel or leaving a private channel. It also supports other functionalities like groupCreate, groupinvite, groupLeave and groupList etc
-
Visitor endpoints: These are REST APIs associated with the Livechat visitor. They are used for visitor registration, deleting visitor, retrieving the visitor info and setting the status of the visitor.
-
Users endpoints: These are user related APIs that provide functionality like creating users with admin rights, listing all users, deleting users and retrieving user information etc.
-
Authentication Endpoints: These are the APIs related to login and logout of the users. It generates an authentication token at the time of login and also takes care of invalidating the token at the time of logout.
For using rocketchat module in sample application, add rocketchat library in project root directory and include the below dependency in entry package.json.
{
"dependencies": {
"rocketchat_ohos": "file:../rocketchat_ohos"
}
}
This section will guide us in understanding how to use the library in Harmony app development project.
import {RestAPI} from 'rocketchat_ohos';
"reqPermissions": [
{
"name": "ohos.permission.INTERNET",
"reason": "Api call",
"usedScene": {
"ability": [
"com.openharmony.rocketchat.MainAbility"
],
"when": "always"
}
}
]
Below is the list of APIs which are supported:
Feature | API | Information |
---|---|---|
Livechat - Page Visited Endpoint | pageVisited(pageData) | pageVisited - To Send Visitor navigation history |
Livechat - Visitors Endpoints |
|
|
Channels Endpoints |
|
|
Groups Endpoints |
|
|
Settings Endpoints | publicSettings(query) | publicSettings - Lists all public settings |
Users Endpoints |
|
|
Authentication Endpoints |
|
|
In this section, we can have a look at some of the examples where the APIs of this library is put to use and the results which we can achieve.
Example 1
In this example, we can see login functionality.
TextInput({ placeholder: 'Username/email' }) ... .onChange((value: string) => { this.userName = value }) TextInput({ placeholder: 'Password' }) ... .onChange((value: string) => { this.userPassword = value }) restAPI = new RestAPI("https://open.rocket.chat/api/v1/", this.userName,this.userPassword); restAPI.login().then(function (data) { console.info("onClickLogin data:" + JSON.stringify(data)); authToken = data.data.authToken; userId = data.data.userId; that.showToast("Login Successful"); }).catch(function (error) { that.showToast("Error :" + error); console.info("onClickLogin error:" + error); }); |
Example 2
In this example, we can see groupCreate functionality.
let groupName = "Squad" var readOnly = false; let filtered_Ulist = ["Vicky", "Mathew", "Rachel"] restAPI.groupCreate (groupName,filtered_Ulist,readOnly). then(function (data) { console.info("restApiSample groupCreate data:" + JSON.stringify(data)); groupID = data.group._id; console.info('groupCreate data:' + JSON.stringify(data)); console.info('groupCreate groupID:' + groupID); that.showToast("Success - group Created" + JSON.stringify(data)); }).catch(function (error) { that.showToast("Error :" + error); console.info("groupCreate error:" + error); }); |
Example 3
In this example, we can see listChannel functionality.
restAPI.listChannel().then(function (data) { console.info("listChannel data:" + JSON.stringify(data)); that.showToast("Success"); }).catch(function (error) { that.showToast("Error :" + error); console.info("listChannel error:" + error); }); |
RocketChat is a simple-to-use yet very powerful communication platform. The performance of the library is very good even when it works on one of the latest operating systems in the world, which is HarmonyOS!
-
For more exciting libraries to develop your app, peep into third-party-components at
OpenHarmony-TPC -
To know more about the development work happening on harmony application layer, and even be part of the exciting stuff, watch this space of Application Library Engineering Group