Overview
Channels are project-scoped realtime rooms. Applications can create them from trusted backend code, so a channel does not need to be manually created in the dashboard first.
A good integration normally:
1. lists or looks up existing channels,
2. creates the channel only when needed,
3. stores or uses the slug returned by PulseGrid,
4. lets clients connect only to channels allowed by their client token.
This supports dynamic rooms such as order-1042, support-case-88 or team-finance without hardcoding every room in advance.
Setup
JavaScript:
- pg.channels.all() returns the project's channel list.
- pg.channels.create(...) creates a channel.
- pg.channel(slug) returns a helper for that channel.
Python:
- pg.channels.all() returns the project's channel list.
- pg.channels.create(...) creates a channel.
- pg.channel(slug) returns a helper for that channel.
Recommended pattern: search the list for the business room you want; if it does not exist, create it and use the returned channel slug.
Code example
const channels = await pg.channels.all();
let room = channels.find(c => c.slug === "order-1042");
if (!room) {
const created = await pg.channels.create({
name: "Order 1042",
channelType: "private",
description: "Live order room",
persistEvents: true,
retentionDays: 30,
});
room = created.data.channel;
}
const channel = pg.channel(room.slug);
channels = pg.channels.all()
room = next((c for c in channels if c.get("slug") == "order-1042"), None)
if room is None:
created = pg.channels.create(
name="Order 1042",
channel_type="private",
description="Live order room",
persist_events=True,
retention_days=30,
)
room = created["data"]["channel"]
channel = pg.channel(room["slug"])
Notes
Do not assume a slug before creation if your application allows arbitrary names. Use the response returned by PulseGrid.
Channel creation is a trusted operation. Public frontend code should normally receive an already-authorized channel slug plus a short-lived client token from your backend.