How to create channels if channel doesn't exist when subscribing?

Hi,

I’m trying to implement a function that detects if a messaging channel exist(create if doesn’t exist) before subscribing. It seems that if channel doesn’t exist yet, after subscribe attempt channel.isJoined returns false.
Is there a way to check if a messaging channel exist?
Is there a way to create a messaging channel without publishing a message?

Thanks,

Hi Mian,

Could you please help me understand how you organize your channels? I mean when a program subscribes to a channel, it “assumes” it is there, even though it might not be - but how does the program decide what channel to subscribe to?

Regards,
Mark

Hi Mark,

In short I’m trying to implement a feature that when user go to certain gps location, they can join a location chatroom, and create the chat room(or report to business logic to create it) if it doesn’t already exist(in case that if the user is the first to enter, or if channel gets deleted accidentally by me on server etc…).

For example, if you go into one apartment building, you can join the building chatroom.

I could create a channel one by one manually beforehand on the web interface, and so far it’s been working well, but I would definitely prefer a programmatic way so I can automate the process.

Thanks,
Mian

Hi @Mian_Wei

If you call isJoined() immediately after channel creation you will get false because it needs some time to establish the connection for this subscription. You can call channel.addConnectListener() to get response when the user is joined the channel.

As I understand, @Mian_Wei, you want to check if chat room exists and if it’s not, create it. But I don’t see the reason for this because our backend do this for you. Once the user is subscribed to the channel and send a message, we check if the channel already exists and if it’s not, create the chat room.

Best Regards,
Maksym

Thank you, I solved this by sending a message if subscription fails, and then subscribe again

Hi @Mian_Wei,
I probably have to develop the same function which user can create himself a chanel.
Would you please tell me how to create a new chanel programmatically?
I meant that the users of application can create themself any chanel as they want.

Many thanks,

Hello @Minh_Tuan_Vu,

For the future, I’d like to ask you to create new topics for your questions, this one was already closed.

According to your question - please, take a look at this API.
The channel with the channelName you’ve passed into the subscribe() method should automatically create the corresponding channel if it doesn’t exist.

Regards,
Olha

Many thank @olhadanylova and I noted the new topic too

1 Like