How to listen new group channel message

How to listen for new messages in realtime from channel groups in react uikit v3?
i want to send notification when there are new message from group channel.

i was try using onMessageReceived but it doesnt work in uikit v3. is there any another example solution?

please help, thanks.


[UIKit Version]
@sendbird/uikit-react: “^3.6.2”

Hello @ryan.sirka

Welcome to the Sendbird community!

What is the issues you are facing while using onMessageReceived? Can you please provide more details?

A very basic example is given below

const ChannelListContainer = () => {
  useEffect(() => {
    const channelHandler = new sb.ChannelHandler();
    channelHandler.onMessageReceived = (channel, message) => {
      // Handle new message received event
      console.log('New message received:', message);
      // Send notification to users
      sendNotification(message);
    };
    sb.addChannelHandler('CHANNEL_HANDLER_ID', channelHandler);
    return () => {
      sb.removeChannelHandler('CHANNEL_HANDLER_ID');
    };
  }, []);

  const sendNotification = (message) => {
    // Implement your notification logic here
    // You can use Firebase Cloud Messaging (FCM) or other notification services to send notifications to users
  };

  return (
    <SendbirdProvider
      appId={APP_ID}
      userId={USER_ID}
      nickname="YOUR_NICKNAME"
    >
      <ChannelList />
    </SendBirdProvider>
  );
};

You can customize the notification logic in the sendNotification function according to your requirements and use a suitable notification service to send notifications to users.

Let me know if this helps.