You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got code which, on visiting the "messenger" page for the first time, attempts to create a user and add them to a default list of channels.
I create a token using client.create_token, then attempt to add the user to a few channels.
However, I'm getting the exception
StreamChat::StreamAPIException (StreamChat error code 4: UpdateChannel failed with error: "The following users are involved in channel update operation, but don't exist: [94461a35e0a73734438dba5ba10bbb74]. Please create the user objects before setting up the channel.")
client.create_token returns a 200 success and also returns a token.
The only exception I get is when I consequently try to add the user, using my manually generated user_id, to channels.
This was working yesterday - my code around user creation doesn't seem to have changed.
To Reproduce
Create a user using client.create_token(id) (I'm using id = SecureRandom.hex(16))
Attempt to add user using channel.add_members([id])
Expected behavior
The create_token endpoint should:
create a user if params are valid (which in this case they are); AND
return an error if params are invalid OR the server is experience issues, so error handling can be handled
require"securerandom"classChatsController < ApplicationController# ...defshow# NOTE: I've checked this ENV vars are set correctlyif(ENV["STREAM_API_KEY"] && ENV["STREAM_API_SECRET"]).present?ifcurrent_user.stream_user_id.nil?@stream_user_id=SecureRandom.hex(16)# NOTE: the line below fails silently@stream_user_token=StreamChatClient.create_stream_user(id: @stream_user_id)current_user.update!(stream_user_id: @stream_user_id,stream_user_token: @stream_user_token)else@stream_user_id=current_user.stream_user_id@stream_user_token=current_user.stream_user_tokenendadd_current_user_to_channelselse# ...endendprivatedefadd_current_user_to_channels[{type: "messaging",id: "general"},{type: "messaging",id: "feedback-and-requests"},{type: "messaging",id: "bugs"},].eachdo |channel|
channel=StreamChatClient.get_channel(type: channel[:type],channel_id: channel[:id],)unlessStreamChatClient.channel_include?(channel: channel,user_id: current_user.stream_user_id)StreamChatClient.add_member(channel: channel,user_id: current_user.stream_user_id)endendendend
My StreamChatClient class:
require "stream-chat"
class StreamChatClient
def self.add_member(channel:, user_id:)
channel.add_members([user_id])
end
def self.channel_include?(channel:, user_id:)
members = channel.query_members()["members"]
members.map{ |member| member["user_id"] }.include?(user_id)
end
def self.get_channel(type:, channel_id:)
client.channel(type, channel_id: channel_id)
end
def self.create_stream_user(id:)
client.create_token(id)
end
private
def self.client
StreamChat::Client.new(
api_key=ENV["STREAM_API_KEY"],
api_secret=ENV["STREAM_API_SECRET"]
)
end
end
The text was updated successfully, but these errors were encountered:
@jahseng-lee I expect you need to first have a WS connection established before you try to send requests. This issue is related to the ruby client. Could you please re-create it in the ruby client repo if the requests fail despite existing WS connection?
The problem doesn't seem to be a failed connection - I'm able to query channel members fine milliseconds before the create_user call fails.
Do you have someone actively looking at the Ruby client? I'm looking to tidy stuff up and launch a product soon and if I can't get Stream working with Ruby + React, I may need to look at an alternative...
Describe the bug
I've got code which, on visiting the "messenger" page for the first time, attempts to create a user and add them to a default list of channels.
I create a token using
client.create_token
, then attempt to add the user to a few channels.However, I'm getting the exception
client.create_token
returns a200
success and also returns a token.The only exception I get is when I consequently try to add the user, using my manually generated
user_id
, to channels.This was working yesterday - my code around user creation doesn't seem to have changed.
To Reproduce
client.create_token(id)
(I'm usingid = SecureRandom.hex(16)
)channel.add_members([id])
Expected behavior
The
create_token
endpoint should:Package version
stream-chat-react: 10.14.0
stream-chat-css: 3.13.0
Desktop (please complete the following information):
OS: MacOS Ventura 13.2
Browser: Chrome
Version: 118.0.5993.70
Additional context
My
StreamChatClient
class:The text was updated successfully, but these errors were encountered: