Invites
Invites allow you to add users to a channel with a pending state. The invited user receives a notification and can accept or reject the invite.
Unread counts are not incremented for channels with a pending invite.
Invite Users
// Get a channel
const channel = client.chat.channel("messaging", "general");
await channel.update({ invites: [{ user_id: "nick" }] });await channel.inviteMembers(["nick"]);Accept an Invite
Call acceptInvite to accept a pending invite. You can optionally include a message parameter to post a system message when the user joins (e.g., "Nick joined this channel!").
// initialize the channel
const channel = client.chat.channel("messaging", "awesome-chat");
// accept the invite on behalf of nick, posting a system message
await channel.update({
accept_invite: true,
user_id: "nick",
message: { text: "Nick joined this channel!", user_id: "nick" },
});// initialize the channel
const channel = client.channel("messaging", "awesome-chat");
// accept the invite on behalf of a user
await channel.acceptInvite({ user_id: "nick" });Reject an Invite
Call rejectInvite to decline a pending invite. Client-side calls use the currently connected user. Server-side calls require a user_id parameter.
const channel = client.chat.channel("messaging", "general");
await channel.update({ reject_invite: true, user_id: "rob" });await channel.rejectInvite({ user_id: "rob" });Query Invites by Status
Use queryChannels with the invite filter to retrieve channels based on invite status. Valid values are pending, accepted, and rejected.
Query Accepted Invites
// Query accepted invites for user rob
const invites = await client.chat.queryChannels({
filter_conditions: { invite: "accepted" },
user_id: "rob",
});// query invites for user rob
const invites = await client.queryChannels(
{
invite: "accepted",
},
{},
{ user_id: "rob" },
);Query Rejected Invites
// Query rejected invites for user rob
const invites = await client.chat.queryChannels({
filter_conditions: { invite: "rejected" },
user_id: "rob",
});// query invites for user rob
const rejected = await client.queryChannels(
{
invite: "rejected",
},
{},
{ user_id: "rob" },
);Query Pending Invites
// Query pending invites for user rob
const invites = await client.chat.queryChannels({
filter_conditions: { invite: "pending" },
user_id: "rob",
});// query invites for user rob
const pending = await client.queryChannels(
{
invite: "pending",
},
{},
{ user_id: "rob" },
);