@tridentity/tri-com-be-sdk
v1.0.4
Published
The Tri Communication SDK is a tool designed to integrate with the Tri Communication Service, providing key communication functionalities such as sending messages, notifications, creating chat rooms, and user authentication.
Downloads
32
Readme
Tridentity Communication Service SDK
The Tri Communication SDK is a tool designed to integrate with the Tri Communication Service, providing key communication functionalities such as sending messages, notifications, creating chat rooms, and user authentication.
Installation
First, install the SDK in your project:
npm install --save @tridentity/tri-com-be-sdkInitialization
To initialize, provide the API baseURL, clientId, and clientSecret.
- For testing, use Staging URL:
https://communication-service.stag.tribox.me - For production, use Production URL:
const client = new TriCommunicationClient({
url: "TRI_COMMUNICATION_URL",
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
});Notes
- Ensure that your
clientIdandclientSecretis kept secure and not shared publicly. - Always handle network and server errors when using the SDK.
Tri Communication SDK API Methods
Below is the documentation for key methods in the Tri Communication SDK. These methods allow you to interact with the Tri Communication platform, such as registering users, retrieving user signatures, and sending notifications.
addUser
Registers a user on the Tri Communication platform.
Method
async addUser(name: string, prefix: TriCommunicationRolePrefix): Promise<{ userId: string, message: string }>Parameters
| Parameter | Type | Required | Description |
| --------- | ---------------------------- | -------- | ------------------------------------------------------------------------- |
| name | string | Yes | The name of the user to register. |
| prefix | TriCommunicationRolePrefix | Yes | A role prefix to categorize the user (e.g., "admin", "user", "merchant"). |
Returns
A promise that resolves to an object containing the userId of the registered user.
Example Usage
const user = await client.addUser("John Doe", TriCommunicationRolePrefix.USER);
console.log(user.userId); // Outputs the registered userIdgetUserSignature
Fetches the signature for a user from the Tri Communication platform.
Method
async getUserSignature(triCommunicationUserId: string): Promise<{ signature: string }>Parameters
| Parameter | Type | Required | Description |
| ------------------------ | -------- | -------- | ---------------------------------------- |
| triCommunicationUserId | string | Yes | The ID of the user on Tri Communication. |
Returns
A promise that resolves to an object containing the signature of the user.
Example Usage
const signature = await sdk.getUserSignature("66f13078f1501545550abcce");
console.log(signature); // Outputs the user's signaturesendNotification
Sends a notification to a single user on the Tri Communication platform.
Method
async sendNotification(body: ISendNotiToUser): Promise<{ status: string }>Parameters
| Parameter | Type | Required | Description |
| --------- | ----------------- | -------- | ------------------------------------------- |
| body | ISendNotiToUser | Yes | An object containing the notification data. |
ISendNotiToUser Interface
| Field | Type | Required | Description |
| ----------- | -------- | -------- | ------------------------------------------------------ |
| toAccount | string | Yes | The account ID of the user receiving the notification. |
| notiBody | any | Yes | The content of the notification message. |
Returns
A promise that resolves to an object containing the status of the operation.
Example Usage
const notification = {
toAccount: "66f13078f1501545550abcce",
notiBody: { title: "New Message", content: "You have a new message." },
};
const response = await sdk.sendNotification(notification);
console.log(response.status); // Outputs the status of the notificationsendNotificationToMultipleUsers
Sends a notification to multiple users on the Tri Communication platform.
Method
async sendNotificationToMultipleUsers(body: ISendNotiToUserToMultipleUsers): Promise<{ status: string }>Parameters
| Parameter | Type | Required | Description |
| --------- | -------------------------------- | -------- | ------------------------------------------- |
| body | ISendNotiToUserToMultipleUsers | Yes | An object containing the notification data. |
ISendNotiToUserToMultipleUsers Interface
| Field | Type | Required | Description |
| ------------ | ---------- | -------- | ---------------------------------------------------- |
| toAccounts | string[] | Yes | An array of account IDs to receive the notification. |
| notiBody | any | Yes | The content of the notification message. |
Returns
A promise that resolves to an object containing the status of the operation.
Example Usage
const notifications = {
toAccounts: ["user_12345", "user_67890", "user_11223"],
notiBody: {
title: "System Update",
content: "Scheduled maintenance at 12:00 AM.",
},
};
const response = await sdk.sendNotificationToMultipleUsers(notifications);
console.log(response.status); // Outputs the status of the notificationsNotes
- Ensure all
toAccountortoAccountsIDs are valid and registered on the Tri Communication platform. - The
notiBodyfield can contain any data structure that your application supports for notifications. - Handle potential errors, such as network issues or invalid inputs, when calling these methods.
Contact
For more details or support, please contact the Tri Communication development team.
