I've encountered problems while trying to listen to messages on a GetStream channel.
I want to listen to new messages from a GetStream channel in real-time for subsequent processing. The code snippet throws an error on the line channel.watch(). The error message is: "When using member-based IDs specify at least 2 members."
From what I've read, there are two ways to create or connect to a channel:
- Through its members
- Using the channel's unique identifier
In my case, the channel has already been created by another app previously and the channel has a channelId (i can see it on the getStream dashboard). The _channelId parameter I'm using is the unique channelId. I am sure.
Where is the error? Thanks
exports.listenAndSentimentAnalisysChat = async (_channelId) => {
// userId is like "user_back_client"
const userId = `${config.GETSTREAM_USERID}`;
const serverSideClient = await setGetStreamChatClient();
// Connect as the application-level user (usually a server-side operation)
const adminToken = serverSideClient.createToken(userId);
serverSideClient._setUser(adminToken);
// Initialize the channel you want to get messages from
const channel = serverSideClient.channel("livestream", _channelId);
// Add an event listener for new messages
channel.on('message.new', event => {
console.log(`Received message: ${event.message.text} from ${event.message.user.id}`);
});
// Connect to the channel
await channel.watch();
}
We have a paid subscription, and although I've reached out to support, the response I received was quite vague and did not solve the issue. Additionally, I find the documentation to be lacking and limited.
I I want to receive the messages, but I'm getting an error.