Support Topics Documentation Slack YouTube Blog

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