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.
npm install @tridentity/tri-com-be-sdkThe 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.
First, install the SDK in your project:
``bash`
npm install --save @tridentity/tri-com-be-sdk
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:
`javascript`
const client = new TriCommunicationClient({
url: "TRI_COMMUNICATION_URL",
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
});
- Ensure that your clientId and clientSecret is kept secure and not shared publicly.
- Always handle network and server errors when using the SDK.
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.
---
Registers a user on the Tri Communication platform.
##### Method
`typescript`
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
`javascript`
const user = await client.addUser("John Doe", TriCommunicationRolePrefix.USER);
console.log(user.userId); // Outputs the registered userId
---
Fetches the signature for a user from the Tri Communication platform.
##### Method
`typescript`
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
`javascript`
const signature = await sdk.getUserSignature("66f13078f1501545550abcce");
console.log(signature); // Outputs the user's signature
---
Sends a notification to a single user on the Tri Communication platform.
##### Method
`typescript`
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
`javascript
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 notification
`
---
Sends a notification to multiple users on the Tri Communication platform.
##### Method
`typescript`
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
`javascript
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 notifications
`
---
- Ensure all toAccount or toAccounts IDs are valid and registered on the Tri Communication platform.notiBody` field can contain any data structure that your application supports for notifications.
- The
- Handle potential errors, such as network issues or invalid inputs, when calling these methods.
For more details or support, please contact the Tri Communication development team.