ChannelListElement reference.
Basic usage
- React
- Vanilla JS
- Swift
"use client";
import { useEffect, useState } from "react";
import { WhopElements, Chat, ChannelListElement, ChatElement } from "@whop/elements-react";
import { loadWhop } from "@whop/elements";
const REFRESH_INTERVAL = 45 * 60 * 1000;
async function fetchToken() {
const res = await fetch("https://your-server.com/api/chat/token", { method: "POST" });
const data = await res.json();
return data.token;
}
export function ChannelListView() {
const [accessToken, setAccessToken] = useState<string | null>(null);
useEffect(() => {
let ignore = false;
async function refreshToken() {
const token = await fetchToken();
if (!ignore) {
setAccessToken(token);
}
}
refreshToken();
const interval = setInterval(refreshToken, REFRESH_INTERVAL);
return () => {
ignore = true;
clearInterval(interval);
};
}, []);
if (!accessToken) return null;
return (
<WhopElements elements={loadWhop()}>
<Chat accessToken={accessToken}>
<div style={{ display: "flex", height: "100dvh" }}>
<ChannelListElement style={{ height: "100%", width: "400px" }} />
<ChatElement style={{ height: "100%", flex: 1 }} />
</div>
</Chat>
</WhopElements>
);
}
<div style="display: flex; height: 100vh">
<div id="chat-channelList" style="height: 100%; width: 400px"></div>
<div id="chat-chat" style="height: 100%; flex: 1"></div>
</div>
<script src="https://cdn.whop.com/elements/amber/elements.js" data-whop-elements></script>
<script type="module">
const REFRESH_INTERVAL = 45 * 60 * 1000;
async function fetchToken() {
const res = await fetch("https://your-server.com/api/chat/token", { method: "POST" });
const data = await res.json();
return data.token;
}
const chat = window.WhopElements().chat.create({
accessToken: await fetchToken(),
});
chat.create("channelList").mount("#chat-channelList");
chat.create("chat").mount("#chat-chat");
setInterval(async () => {
chat.update({ accessToken: await fetchToken() });
}, REFRESH_INTERVAL);
</script>
struct MessagesView: View {
@State private var selectedChannel: DMChannel?
var body: some View {
WhopDMsListView(
onEvent: { event in
switch event {
case let .channelSelected(channel):
selectedChannel = channel
}
}
)
.navigationDestination(item: $selectedChannel) { channel in
WhopChatView(
channelId: channel.id,
style: .imessage
)
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(channel.name)
}
}
}
Account scoping
Filter the channel list to only show conversations belonging to a specific account by passing anaccountId. To create a DM from your server, call Create Channel with kind set to private. Pass the same account ID as account_id so the DM appears in the scoped list.
- React
- Vanilla JS
- Swift
<Chat accessToken={accessToken} accountId="biz_xxxx">
{/* elements */}
</Chat>
const chat = window.WhopElements().chat.create({
accessToken,
accountId: "biz_xxxx",
});
WhopDMsListView(
companyId: "biz_xxxx",
onEvent: { event in
switch event {
case let .channelSelected(channel):
selectedChannel = channel
}
}
)
Event handling
Pass an event callback to listen for channel selections.- React
- Vanilla JS
- Swift
| Event | Payload | Description |
|---|---|---|
onChannelChange | { channelId: string, focusMessageId?: string } | Emitted when the active channel changes |
<Chat
accessToken={accessToken}
onChannelChange={({ channelId }) => {
console.log("Channel selected:", channelId);
}}
>
<ChannelListElement />
</Chat>
| Event | Payload | Description |
|---|---|---|
onChannelChange | { channelId: string, focusMessageId?: string } | Emitted when the active channel changes |
const chat = window.WhopElements().chat.create({
accessToken,
onChannelChange: ({ channelId }) => {
console.log("Channel selected:", channelId);
},
});
| Event | Detail | Description |
|---|---|---|
.channelSelected | channel: DMChannel | Emitted when the user taps a channel |
WhopDMsListView(
onEvent: { event in
switch event {
case let .channelSelected(channel):
selectedChannel = channel
}
}
)
.navigationDestination(item: $selectedChannel) { channel in
WhopChatView(
channelId: channel.id,
style: .imessage
)
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(channel.name)
}

