chat_app_abc_demo 0.1.8 chat_app_abc_demo: ^0.1.8 copied to clipboard
This handbook aims to be the one-stop-shop for all sdk documentation.
Welcome to ChatLib with socket.io #
This documentation provides an overview of the Chat
, Network
class and its methods.
Table of Contents #
Methods #
Default api response #
{
"data": "response api", // response all api
"success": true, // status api true: success, false : have error
}
Error definition #
header status
:- 200: success
- 400: bad request
- 401: Unauthorized
- 404: Not Found
- 500, 501: Server Error
response error
:
{
"error": {
"code": "string", // code error
"message": "string", // message
"details": "string", // detail error
"data": {
"additionalProp1": "string", // It cannot determined
"additionalProp2": "string",
"additionalProp3": "string"
},
"validationErrors": [
{
"message": "string",
"members": [
"string"
]
}
]
}
}
Chat
Method | Description |
---|---|
connect | Create connections |
disconnet | Stop connections |
sendMessage | send message with group |
updateMessage | update message with group |
receiveMessage | Listens for incoming mes |
receiveDeleteMessage | Listens for incoming mes delete |
setMessageSeenStatus | Sets the "message seen" |
sendMessage
Listens for incoming chat messages and invokes a callback function when a new message is received.
chat.sendMessage(
{
message: "", // message sent
attachments: [
{
name: "", // name file
desciption: "",
id: "", // id attachments (send id = null or '')
url: "", // url file
typeAttachment: 1, // - video = 1, // - audio = 2// - image = 3// - file = 4 // - other = 5
sizeByte: 0,
durationSeconds: 0,
revoke: 1, // 1 revoke for sender, 2 revoke for all group
},
],
forwardFromRoomId: "",
mentionIds: [], // list userId mention
type: 0, //type message list in here:
// - text = 0
// - audio = 1
// - file = 2
// - sticker = 3
// - gallery = 4
// - video = 5
quoteMessageId: "", // message quote id
forwardMessageId: "", // message forward id
},
id
);
ListRoomChat
Listens for incoming chat messages and invokes a callback function when a new message is received.
chat.receiveMessage(message => {
});
// response in socket message
{
"attachments": [], // list file
"forwardFromMessageId": "", // id message forward
"forwardFromRoomId": "", // id room message forward
"mentionIds": [], // list userId mention
"message": "Test",
"messageId": "", // id message
"quoteFromMessageId": "", // id message for quote
"roomId": "", // room id
"senderId": "", //userid sender
"senderProfile": {
"avatar": "", // url avatar
"displayname": "", // name
"id": "", // userid sender
"username": "" // username
},
"timeSend": "2023-09-28T09:10:46.783Z",
"type": 0 //type message list in here:
// - text = 0
// - audio = 1
// - file = 2
// - sticker = 3
// - gallery = 4
// - video = 5
}
note: Before using it, you have to initialize the data retrieval function. #
import {
ChatUser,
Chat,
InitChatSocket,
InitChatMagement,
} from "chat-app-demo-abc";
// auth config
const chatUser = InitChatUser(url, token);
or;
const chatUser = new ChatUser(url, token);
// auth message reader
const apiMessage = InitMessageReader(url, token);
or;
const apiMessage = new MessageReader(url, token);
// chat management
const apiManage = new ChatMagement("url_chat_manager", token);
or;
const apiManage = InitChatMagement("url_chat_manager", token);
// chat management
const chat = new InitChatSocket("url_chat_soket", token);
or;
const chat = ChatSocket("url_chat_socket", token);
- Except for the login function, you need to pass the token for all other functions.
- authUrl, messageReaderUrl, ChatManageUrl: You only need to pass one of the three. Use the cluster's URL you're using.
Auth
Method | Params | Description |
---|---|---|
Login | userName:String, passWord: string | get token using to conect chat |
Login
const result = await ChatUser.login(param);
// param request
{
"userName": "string", //email account login
"passWord": "string", // password
"pushToken": "string"// pushtoken is device token in firebase
}
//response
{
"access_token": "", // token access chat (you can using jwt_decode access_token to get info user)
"refresh_token": ""
"expires_in": 0, // expires time
"token_type": "Bearer", // type Authorization
"scope": "Auth offline_access"
}
// this way to get info user
import jwt_decode from "jwt-decode";
var infoUser = jwt_decode(access_token);
note: if you need get info user ex: useId, name... you have to instal jwt-decode to decode access_token then you have it
register
const result = await ChatUser.register(param);
// param request
{
"username": "string",
"email": "string",
"phoneNumber": "string",
"gender": 0,
"avatar": "string", // url avatar (optional)
"dateOfBirth": "2023-10-06T02:43:24.154Z",
"password": "string",
"image": { // optional
"fileId": "string", // file id get from api upload(optional)
"fileName": "string", // name file (optional)
"extension": "string", // extension file
"fileUrl": "string", // url file
"contentType": "string"
},
"isAdmin": false // status is admin default false
}
//response
{
"userId": "string", // user id
"access_token": "", // token access chat (you can using jwt_decode access_token to get info user)
"refresh_token": ""
"expires_in": 0, // expires time
"token_type": "Bearer", // type Authorization
"scope": "Auth offline_access"
}
// this way to get info user
import jwt_decode from "jwt-decode";
var infoUser = jwt_decode(access_token);
listUserContactAdd
find list user by contact(phone)
const param = ["09xxx", "08xxx"];
const result = await chatUser.listUserContactAdd(param);
//response
[
{
id: "3fa85f64-5717-4562-b3fc-2c963f66afa6", // userId
name: "string", // name
avatar: "string", // url avatar
email: "string", // email user
phoneNumber: "string", // phone user
gender: 0, // gender 0: male, 1: female
dateOfBirth: "2023-10-06T02:46:24.015Z",
isFriend: true, // status is friend
distance: 0, // distance(km)
},
];
searchFriends
find friends
const result = await chatUser.searchFriends(param);
// param request
{
"groupId": "string",
"filters": "string", // string search
"phoneNumber": "string",
"sorting": "ASC",
"skip": 0,
"take": 10,
}
//response
{
"items": [
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", // userId
"name": "string", // name
"avatar": "string", // url avatar
"email": "string", // email user
"phoneNumber": "string", // phone user
"gender": 0, // gender 0: male, 1: female
"dateOfBirth": "2023-10-06T02:46:24.015Z",
"isFriend": true, // status is friend
"distance": 0 // distance(km)
}
],
"pageSize": 0,
"totalCount": 0
}
userDoAction
User action(add friend, unfriend, block , unblock)
const result = await chatUser.userDoAction(param);
// param request
{
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",// userid user
"actionType": 0 // 0: add friend, 1: unfriend, 2: block , 3 unblock
}
}
//response
{
"success":true
}
listFriends
const result = await chatUser.listFriends(param);
// param request
{
"groupId": "string",
"filters": "string", // string search
"phoneNumber": "string",
"sorting": "ASC",
"skip": 0,
"take": 10,
}
//response
{
"items": [
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", // userId
"name": "string", // name
"avatar": "string", // url avatar
"email": "string", // email user
"phoneNumber": "string", // phone user
"gender": 0, // gender 0: male, 1: female
"dateOfBirth": "2023-10-06T02:46:24.015Z",
"isFriend": true, // status is friend
"distance": 0 // distance(km)
}
],
"pageSize": 0,
"totalCount": 0
}
Message management
ListRoomChat
Retrieves a list of chat rooms in which a user has participated.
const param = { userId: "", skip: 0, take: 20 };
const result = await apiManage.ListRoomChat(param);
// param request
{
"userId": "string", // userId (can be null default get by token)
"groupName":"", // name group
"tagFilter": null, // number 1,2,3
"skip": 0, // point start record
"take": 0// The number of records retrieved
}
// response
{
"items": [
{
"id": "string", //id room chat
"createdOn": "2023-09-28T07:35:34.233Z",
"name": "string", // name room chat
"typeOfGroup": 0, // type group: 0: group, 1: direct, 2: support
"topic": "string", // topic group(canbe null)
"description": "string", // desc group (can be null)
"image": "string", // url image room
"ownerId": "string", // id user owner group
"participantCount": 0, // total participant
"lastMessage": {
"id": "string", // id message
"message": "string",
"userId": "string", // userid send send
"userName": "string", // name sender
"fullName": "string", // full name sender
"nickName": "string", //
"avatar": "string",// url avata
"time": "2023-09-28T07:35:34.233Z",
"attachments": [
{
"name": "string", // name file
"desciption": "string", //
"id": "string", // id attachments
"url": "string", // url file
"urlPreView": "string",
"typeAttachment": 1, // // - video = 1, // - audio = 2// - image = 3// - file = 4 // - other = 5
"messageId": "string",
"sizeByte": 0, // size file
"durationSeconds": 0,
"revoke": 1 // 1 revoke for sender, 2 revoke for all group
}
],
"type": 0,
"isEdited": true,// status edit
"lastEditTime": "2023-09-28T07:35:34.233Z",
"isDeleted": true // status delete
},
"participantInfo": { // Only available for one-on-one chats This is information about the remaining person in the room
"userId": "string", // userId
"userName": "string", // username
"fullName": "string", // fullname
"nickName": "string", // nickname
"avatar": "string", // url avata
"onlineStatus": 0, //status online 0 offline, 1 online
},
"hasUnreadMessage": true, // status unread message
"unreadCount": 0,// total message unread
"isFavorite": true, // status favorite
"tags": [
"string"
], // list tags group
"notifyStatus": true, // status get notification
"leaveGroupHistories": [
{
"participant": "string", // userid leave group
"timeLeave": "2023-09-28T07:35:34.233Z"
}
]
}
],
"totalCount": 0
}
searchRoomChat
Searches for chat rooms based on specified criteria.
const result = await apiManage.searchRoomChat(param);
// param request
{
"roomType":"", // 0,1,2
"filter": '', // string filter
"skip": 0, // point start record
"take": 0// The number of records retrieved
}
//response
{
"items": [
{
"id": "string",// id room
"name": "string", // name room
"roomType": 0, // type room default =0 (group)
"topic": "string",
"image": "string", // url
"participants": [
"string"
],
"participantCount": 0 // total participant
}
],
"totalCount": 0
}
getTotalUnread
Searches for chat rooms based on specified criteria.
const result = await apiManage.getTotalUnread();
// response
{"DIRECT": 0, "GROUP": 0, "SUPPORT": 0} // total message unread by type group
groupParticipants
Searches for chat rooms based on specified criteria.
const result = await apiManage.groupParticipants(groupId, param);
// param request
{
"skip": 0, // point start record
"take": 0// The number of records retrieved
}
// response
{
"items": [
{
"userId": "string", // userid
"userName": "string", // username account
"surName": "string", // surname
"name": "string", // name user
"nickName": "string", // nickname
"avatar": "string", // url avata
"onlineStatus": 0, // status online
"isAdmin": true. // status roler
}
],
"totalCount": 0
}
getInfoRoomChat
Searches for chat rooms based on specified criteria.
const result = await apiManage.getInfoRoomChat(groupId);
// param request
groupId: "" // id group chat
// response
{
"id": "string", // id group chat
"createdOn": "2023-09-28T08:28:16.072Z",
"name": "string", // name group
"roomType": 0, //deprecated
"typeOfGroup": 0, // type of group default 0 , 0: group, 1: direct, 2: support
"topic": "string",
"description": "string", // desc room
"image": "string", // url room
"ownerId": "string", // id owner
"participants": [
"string"
],
"participantCount": 0,
"lastMessage": {
"id": "string",
"message": "string",
"userId": "string",
"userName": "string",
"fullName": "string",
"nickName": "string",
"avatar": "string",
"time": "2023-09-28T08:28:16.072Z",
"attachments": [
{
"name": "string",
"desciption": "string",
"id": "string",
"url": "string",
"urlPreView": "string",
"typeAttachment": 1,
"messageId": "string",
"sizeByte": 0,
"durationSeconds": 0,
"revoke": 1
}
],
"type": 0,
"isEdited": true,
"lastEditTime": "2023-09-28T08:28:16.072Z",
"isDeleted": true
},
"participantInfo": {
"userId": "string",
"userName": "string",
"fullName": "string",
"nickName": "string",
"avatar": "string",
"onlineStatus": 0
},
"unreadCount": 0,
"hasUnreadMessage": true, // status unread message. true have message unread
"isLinkEnabled": true,
"inviteLinkKey": "string", // url invite
"labelAllows": [
"string"
],
"statusAllows": [
"string"
], // list status allows
"sexAllows": [
"string"
], // list sex allows
"maxAgeAllow": 0, // age max allow
"minAgeAllow": 0, // age min allow
"isPrivate": true, // status prive
"localtionAllows": [
"string"
], // list location allow
"isAdminApprove": true // status who can approve join
}
createRoomChat
Searches for chat rooms based on specified criteria.
const result = await apiManage.createRoomChat(param);
// param request
{
"name": "string", // name group
"roomType": 0, // deprecated
"typeOfGroup": 0, // type group 0.1.2, default 0
"topic": "string",
"description": "string",
"image": "string", // url image group
"ownerId": "string", // id user owner group
"participants": [
"string"
], // list userid
"tags": [
"string"
],
"sendDefaultMessage": true, //status send default message
"defaultMessageContent": "string" // message default
}
// response
{
"id": "string", // id group chat
}
updateInfoRoom
Searches for chat rooms based on specified criteria.
const result = await apiManage.updateInfoRoom(param);
// param request
{
"name": "string",
"topic": "string",
"description": "string",
"image": "string"
}
// response
// method put success: 200 in header status
// error
deleteChatRoom
Searches for chat rooms based on specified criteria.
const result = await apiManage.deleteChatRoom(roomId);
// param request
"roomId":'' // room id
// response
// method delete success: 200 in header status
// error
joinChatGroup
Searches for chat rooms based on specified criteria.
const result = await apiManage.joinChatGroup(groupId, userId);
// param request
{
"groupId": "string",
"userId": "string"
}
// response
// success: 200 in header status
inviteChatGroup
Searches for chat rooms based on specified criteria.
const result = await apiManage.inviteChatGroup(param);
// param request
{
"groupId": "string", // id room
"userId": [
"string"
] // list userId invite
}
// response
// success: 200 in header status
inviteChatGroup
Searches for chat rooms based on specified criteria.
const result = await apiManage.removeUserChatGroup(param);
// param request
{
"groupId": "string",
"userId": "string"
}
// response
// success: 200 in header status
Message reader management
chatHistory
Retrieves the chat history of a group.
const param = { userId: "", skip: 0, take: 20 };
const result = await apiMessage.chatHistory(roomid, param);
// param request
{
"before":"", //
"after": '', //messageid after
"isPined":null, //boolean, true message pined
"skip": 0, // point start record
"take": 0// The number of records retrieved
}
//response
{
"skip": 0,
"take": 0,
"messages": [
{
"id": "", // id message
"messageContentRaw": "",// content message
"message": "string",// content message
"timeSend": "2023-09-28T09:08:34.878Z",
"senderId": "string", // userId sender
"roomId": "string", // room id
"mentionsIds": [
"string" // list userid
],
"receiperId": "string", //
"reactions": [
{
"reactorId": "string",
"reactCode": "string"
}
],
"attachments": [
{
"name": "string",
"desciption": "string",
"id": "string",
"url": "string",
"urlPreView": "string",
"typeAttachment": 1,
"messageId": "string",
"sizeByte": 0,
"durationSeconds": 0,
"revoke": 1
}
],
"type": 0, /// - text = 0
/// - audio = 1
/// - file = 2
/// - sticker = 3
/// - gallery = 4
/// - video = 5
"revokeEnum": 1,
"isDeleted": true,
"isEdited": true,
"lastEditTime": "2023-09-28T09:08:34.878Z",
"countValue": 0,
"isSave": true, // status save
"isPined": true, // status pinner
"isPinedById": "string",
"lastPinedTime": "2023-09-28T09:08:34.878Z"
}
],
"users": [
{
"id": "string",
"avatar": "string",
"roles": [
"string"
],
"username": "string",
"nickName": "string",
"displayName": "string",
"defautlStatus": 0,
"isOnline": true
}
],
"lastReadMessageId": "string",// message read lastest
"userSendLastRead": "string",
"lastReadMessageTimeSend": "2023-09-28T09:08:34.878Z"
}
lastMessageUserGroup
#
Retrieves the last read message of a user in a group.
const result = await apiMessage.lastMessageUserGroup(param);
// param request
{
"roomId":"", // Id of group
"userId": '', //Id of user to check
}
// response
{
"lastReadMessageId": "string", // id mess last read
"userSendLastRead": "string",// userid last read mes
"lastReadMessageTimeSend": "2023-09-28T09:38:52.883Z"
}
historyAttachment
Retrieves the history of attachments in a group.
const result = await apiMessage.historyAttachment(roomId, param);
// param request
{
"before":"", //
"after": '', //messageid after
"types": [], // - VIDEO = 1,AUDIO = 2,IMAGE = 3,FILE = 4,OTHER = 5
"skip": 0, // point start record
"take": 0// The number of records retrieved
}
// response
{
"skip": 0,
"take": 0,
"messages": [
{
"id": "string",
"messageContentRaw": "string",
"message": "string",
"timeSend": "2023-09-28T09:39:43.708Z",
"senderId": "string",
"roomId": "string",
"mentionsIds": [
"string"
],
"receiperId": "string",
"reactions": [
{
"reactorId": "string",
"reactCode": "string"
}
],
"attachments": [
{
"name": "string",
"desciption": "string",
"id": "string",
"url": "string",
"urlPreView": "string",
"typeAttachment": 1,
"messageId": "string",
"sizeByte": 0,
"durationSeconds": 0,
"revoke": 1
}
],
"type": 0,
"revokeEnum": 1,
"isDeleted": true,
"isEdited": true,
"lastEditTime": "2023-09-28T09:39:43.708Z",
"countValue": 0,
"isSave": true,
"isPined": true,
}]
}
searchMessegeInGroup
Retrieves the history of message in a group.
const result = await apiMessage.searchMessegeInGroup(roomId, param);
// param request
{
"textSearch": '', // text search
"skip": 0, // point start record
"take": 0// The number of records retrieved
}
// response
{
"messageId": "string", // id message
"message": "string", // message
"textSearch": "string",
"messageIds": [
"string"
], //list message id
"messages": [
{
"id": "string",
"messageContentRaw": "string",
"message": "string",
"timeSend": "2023-09-28T09:56:34.615Z",
"senderId": "string",
"roomId": "string",
"mentionsIds": [
"string"
],
"receiperId": "string",
"reactions": [
{
"reactorId": "string",
"reactCode": "string"
}
],
"attachments": [
{
"name": "string",
"desciption": "string",
"id": "string",
"url": "string",
"urlPreView": "string",
"typeAttachment": 1,
"messageId": "string",
"sizeByte": 0,
"durationSeconds": 0,
"revoke": 1
}
],
"type": 0,
"revokeEnum": 1,
"isDeleted": true,
"isEdited": true,
"lastEditTime": "2023-09-28T09:56:34.615Z",
"countValue": 0,
"isSave": true,
"isPined": true,
"isPinedById": "string",
"lastPinedTime": "2023-09-28T09:56:34.615Z"
}
],
"users": [
{
"id": "string",
"avatar": "string",
"roles": [
"string"
],
"username": "string",
"nickName": "string",
"displayName": "string",
"defautlStatus": 0,
"isOnline": true
}
],
"skip": 0,
"take": 0,
"totalCountFinded": 0
}
getHistoryAroundMessage
Retrieves the history of attachments in a group.
const result = await api.getHistoryAroundMessage(param);
// param request
{
"roomId": '', // roomid search
"messageId": '', // messageid
"take": 10 // The number of records retrieved: default 10
}
// response
{
"messageId": "string",
"takeOffset": 0,
"messages": [ //Similar to the description defined above
{
"id": "string",
"messageContentRaw": "string",
"message": "string",
"timeSend": "2023-10-05T06:59:31.990Z",
"senderId": "string",
"roomId": "string",
"mentionsIds": [
"string"
],
"receiperId": "string",
"reactions": [
{
"reactorId": "string",
"reactCode": "string"
}
],
"attachments": [
{
"name": "string",
"desciption": "string",
"id": "string",
"url": "string",
"urlPreView": "string",
"typeAttachment": 1,
"messageId": "string",
"sizeByte": 0,
"durationSeconds": 0,
"revoke": 1
}
],
"type": 0,
"revokeEnum": 1,
"isDeleted": true,
"isEdited": true,
"lastEditTime": "2023-10-05T06:59:31.990Z",
"countValue": 0,
"isSave": true,
"isPined": true,
"isPinedById": "string",
"lastPinedTime": "2023-10-05T06:59:31.990Z"
}
],
"users": [
{
"id": "string",
"avatar": "string",
"roles": [
"string"
],
"username": "string",
"nickName": "string",
"displayName": "string",
"defautlStatus": 0,
"isOnline": true
}
]
}
getLastMessagePined
Retrieves the history of attachments in a group.
const result = await api.getLastMessagePined(roomid);
// param request
// path : roomid
// response
{
"messages": [ // Similar to the description defined above
{
"id": "string",
"messageContentRaw": "string",
"message": "string",
"timeSend": "2023-10-05T06:58:45.318Z",
"senderId": "string",
"roomId": "string",
"mentionsIds": [
"string"
],
"receiperId": "string",
"reactions": [
{
"reactorId": "string",
"reactCode": "string"
}
],
"attachments": [
{
"name": "string",
"desciption": "string",
"id": "string",
"url": "string",
"urlPreView": "string",
"typeAttachment": 1,
"messageId": "string",
"sizeByte": 0,
"durationSeconds": 0,
"revoke": 1
}
],
"type": 0,
"revokeEnum": 1,
"isDeleted": true,
"isEdited": true,
"lastEditTime": "2023-10-05T06:58:45.318Z",
"countValue": 0,
"isSave": true,
"isPined": true,
"isPinedById": "string",
"lastPinedTime": "2023-10-05T06:58:45.318Z"
}
],
"users": [
{
"id": "string",
"avatar": "string",
"roles": [
"string"
],
"username": "string",
"nickName": "string",
"displayName": "string",
"defautlStatus": 0,
"isOnline": true
}
],
"total": 0
}
Optional
if you don't have server saved files(audio, image, gift, video) you can using this server for that
const formData = new FormData(form);
const result = await ChatUser.upload("url_server_upload", formData);
Usage #
Connect and receive
import { ChatSocket } from "chat-app-demo-abc";
const ChatScreen = () => {
const chat = new ChatSocket("url_socket", token);
useEffect(() => {
chat.connect();
chat.receiveMessage((message) => {
//
});
return () => {
chat.disconnect();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const sendMessage = () => {
const param = {
message: "text test",
attachments: [],
forwardFromRoomId: "",
mentionIds: [],
type: 0,
quoteMessageId: "",
forwardMessageId: "",
};
chat.sendMessage(param, id);
};
};
login
const api = InitChatAuth({
authUrl: "",
token: "",
});
const handelLogin = useCallback(async () => {
const result = await api.Login({
passWord: "paasword",
userName: "username",
});
setToken(result.access_token);
}, [api]);