
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
chatsasa-react-sdk
Advanced tools
Welcome to the ChatSasa React SDK documentation. This guide will help you get started with integrating the ChatSasa SDK into your React application to enable chat functionalities.
Before you can start using the ChatSasa SDK, you need to complete the following steps:
App ID.App ID and Chat API Token securely, as these will be used to initialize the SDK.To install the ChatSasa SDK, run the following command:
npm install chatsasa-react-sdk
or
yarn add chatsasa-react-sdk
Initialize the ChatSasa SDK in your application. Here’s an example of how to do it:
import ChatSasa from "chatsasa-react-sdk";
const chatSDK = new ChatSasa({
appId: "YOUR_APP_ID",
chatApiToken: "YOUR_CHAT_API_TOKEN",
});
To fetch the user profile, use the `fetchUserProfile` method:
chatSDK
.fetchUserProfile()
.then((profile) => console.log(profile))
.catch((err) => console.error(err));
To fetch all channels, use the `fetchAllChannels` method:
chatSDK
.fetchAllChannels()
.then(({ channels }) => console.log(channels))
.catch((err) => console.error(err));
To send a message, use the `sendMessage` method:
chatSDK
.sendMessage(channelId, userId, "Hello, World!")
.then((message) => console.log(message))
.catch((err) => console.error(err));
To fetch messages in a channel, use the `fetchMessages` method:
chatSDK
.fetchMessages(channelId)
.then((messages) => console.log(messages))
.catch((err) => console.error(err));
To delete a message, use the `deleteMessage` method:
chatSDK
.deleteMessage(messageId, channelId)
.then(() => console.log("Message deleted"))
.catch((err) => console.error(err));
To mark a message as read, use the `markMessageRead` method:
chatSDK
.markMessageRead(messageId, channelId)
.then(() => console.log("Message marked as read"))
.catch((err) => console.error(err));
To mark a message as delivered, use the `markMessageDelivered` method:
chatSDK
.markMessageDelivered(messageId, channelId)
.then(() => console.log("Message marked as delivered"))
.catch((err) => console.error(err));
To fetch available emoji reactions, use the `fetchEmojiReactions` method:
chatSDK
.fetchEmojiReactions()
.then((data) => console.log(data.emojiReactions))
.catch((err) => console.error(err));
To post a reaction to a message, use the `postMessageReaction` method:
chatSDK
.postMessageReaction(messageId, channelId, emojiId, userId)
.then(() => console.log("Reaction posted"))
.catch((err) => console.error(err));
To delete a reaction from a message, use the `deleteMessageReaction` method:
chatSDK
.deleteMessageReaction(reactionId, messageId, userId)
.then(() => console.log("Reaction deleted"))
.catch((err) => console.error(err));
To fetch all users, use the `fetchUsers` method:
chatSDK
.fetchUsers()
.then((data) => console.log(data.users))
.catch((err) => console.error(err));
To connect to the real-time service, use the `connect` method:
chatSDK.connect();
To disconnect from the real-time service, use the `disconnect` method:
chatSDK.disconnect();
To subscribe to real-time events, use the `on` method:
chatSDK.on("new_message", (data) => {
console.log("New message:", data);
});
chatSDK.on("typing", (data) => {
console.log("Typing event:", data);
});
chatSDK.on("reaction_created", (data) => {
console.log("Reaction event:", data);
});
chatSDK.on("message_updated", (data) => {
console.log("Message update:", data);
});
chatSDK.on("message_delete", (data) => {
console.log("Message delete:", data);
});
To unsubscribe from real-time events, use the `off` method:
chatSDK.off("new_message", callback);
chatSDK.off("typing", callback);
chatSDK.off("reaction_created", callback);
chatSDK.off("message_updated", callback);
chatSDK.off("message_delete", callback);
Here is a basic example of how to use the SDK in a React component:
import React, { useEffect, useState } from 'react';
import ChatSasa, { User, Channel, Attachment } from 'chatsasa-react-sdk';
const chatSDK = new ChatSasa({
appId: 'YOUR_APP_ID',
chatApiToken: 'YOUR_CHAT_API_TOKEN',
});
function App() {
const [profile, setProfile] = useState<User | null>(null);
const [channels, setChannels] = useState<Channel[]>([]);
const [currentChannel, setCurrentChannel] = useState<Channel | null>(null);
const [loadingChannels, setLoadingChannels] = useState<boolean>(true);
useEffect(() => {
chatSDK.fetchUserProfile()
.then(profile => setProfile(profile))
.catch(err => console.error(err));
}, []);
useEffect(() => {
if (profile?.userId) {
chatSDK.fetchAllChannels()
.then(({ channels }) => {
setChannels(channels);
setLoadingChannels(false);
})
.catch(err => console.error(err));
}
}, [profile?.userId]);
useEffect(() => {
chatSDK.connect();
const handleNewMessage = ({ channel, message }) => {
console.log('New message:', channel, message);
};
const handleTyping = ({ channel, typingEvent, user }) => {
console.log('Typing event:', channel, typingEvent, user);
};
const handleReaction = ({ channel, reaction }) => {
console.log('Reaction event:', channel, reaction);
};
const handleMessageUpdate = ({ channel, message }) => {
console.log('Message update:', channel, message);
};
const handleMessageDelete = ({ channel, messageId }) => {
console.log('Message delete:', channel, messageId);
};
chatSDK.on('new_message', handleNewMessage);
chatSDK.on('typing', handleTyping);
chatSDK.on('reaction_created', handleReaction);
chatSDK.on('message_update', handleMessageUpdate);
chatSDK.on('message_delete', handleMessageDelete);
return () => {
chatSDK.off('new_message', handleNewMessage);
chatSDK.off('typing', handleTyping);
chatSDK.off('reaction_created', handleReaction);
chatSDK.off('message_update', handleMessageUpdate);
chatSDK.off('message_delete', handleMessageDelete);
chatSDK.disconnect();
};
}, [profile?.userId]);
const handleSendMessage = (message: string, attachments: Attachment[]) => {
if (currentChannel && profile?.userId) {
chatSDK.sendMessage(currentChannel.channelId, profile.userId, message, attachments)
.then(({ message }) => {
setChannels(prevChannels => {
const updatedChannels = prevChannels.map(channel =>
channel.channelId === currentChannel.channelId ? {
...channel,
lastMessage: {
...channel.lastMessage,
message: message.message,
createdAt: message.createdAt,
},
unreadMessagesCount: 0, // Reset unread count for the current channel
} : channel
);
return updatedChannels;
});
})
.catch(err => console.error(err));
}
};
return (
<div className="App">
<header className="App-header">
<h1>Chat Application</h1>
{loadingChannels ? (
<p>Loading channels...</p>
) : (
channels.map(channel => (
<div key={channel.channelId} onClick={() => setCurrentChannel(channel)}>
{channel.name}
</div>
))
)}
</header>
</div>
);
}
export default App;
You have successfully set up the ChatSasa SDK in your React application. For more details on available methods and customization options, refer to the official ChatSasa Documentation.
For any issues or further assistance, please contact our support team at support@chatsasa.com.
Happy Coding!
FAQs
A chat SDK for React applications
We found that chatsasa-react-sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.