getMemberState

View as Markdown

getMemberState

  • getMemberState(params): Promise<\{ channels: Record<string, ChatChannelState> \}>

Returns the states of a member in the specified channels.

Parameters

params
objectRequired

Object containing the parameters of the method.

channels
string | string[]

Channels for which to get the state.

memberId
stringRequired

ID of the member for which to get the state.

Returns

Promise<{ channels: Record<string, ChatChannelState> }>

A promise that resolves to an object containing the states of the member in the specified channels.

Example

In this example, we fetch the state of the member User1 in the channel channel1 and print it to the console.

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const chatClient = client.chat;
6
7let usesId = 'User1'; // Assumes a member with this id already exists and has joined the channel.
8
9const s = await chatClient.getMemberState({
10 channels: "channel1", // or a list of channels like: ["channel1", "channel2"]
11 memberId: usesId
12});
13
14console.log(`The state of ${usesId} is: ${JSON.stringify(s.channels.channel1.state, null, 2)}`);