Skip to main content

Chat Management Operations

This section documents the GraphQL operations available for managing chat functionality in the CRM system.

Queries​

allChannels​

Retrieves a list of all chat channels in the system.

Query​

query AllChannels {
allChannels {
id
cid
type
name
avatar
}
}

Arguments​

None

Response​

Returns an array of ChatStreamChannelsBoResponse objects containing chat channel data.

{
"data": {
"allChannels": [
{
"id": "announcements",
"cid": "livestream:announcements",
"type": "livestream",
"name": "Announcements",
"avatar": "https://example.com/images/announcement-avatar.png"
},
{
"id": "support",
"cid": "livestream:support",
"type": "livestream",
"name": "Support Channel",
"avatar": null
}
]
}
}

Mutations​

createOrUpdateChannel​

Creates a new chat channel or updates an existing one.

Mutation​

mutation CreateOrUpdateChannel($input: CreateOrUpdateStreamChatChanelInput!) {
createOrUpdateChannel(input: $input)
}

Arguments​

NameTypeDescriptionRequired
inputCreateOrUpdateStreamChatChanelInput!Input data for creating or updating a channelYes

CreateOrUpdateStreamChatChanelInput​

input CreateOrUpdateStreamChatChanelInput {
id: String
name: String!
avatarFilename: String
type: ChatStreamChannelType = Livestream
}
FieldTypeDescriptionRequiredDefault
idStringID of the channel (required for update)No-
nameString!Name of the channelYes-
avatarFilenameStringFilename of the channel avatarNo-
typeChatStreamChannelTypeType of the channelNoLivestream

Response​

Returns a boolean indicating whether the operation was successful.

deleteChannels​

Deletes multiple chat channels.

Mutation​

mutation DeleteChannels($input: DeleteStreamChatChanelInput!) {
deleteChannels(input: $input)
}

Arguments​

NameTypeDescriptionRequired
inputDeleteStreamChatChanelInput!Input data for deleting channelsYes

DeleteStreamChatChanelInput​

input DeleteStreamChatChanelInput {
cids: [String!]!
}
FieldTypeDescriptionRequired
cids[String!]!Array of channel IDs to deleteYes

Response​

Returns a boolean indicating whether the operation was successful.

sendMessageToChannel​

Sends a message to a specified chat channel.

Mutation​

mutation SendMessageToChannel($input: SendMessageToChannelChanelInput!) {
sendMessageToChannel(input: $input)
}

Arguments​

NameTypeDescriptionRequired
inputSendMessageToChannelChanelInput!Input data for sending a messageYes

SendMessageToChannelChanelInput​

input SendMessageToChannelChanelInput {
channelId: String!
text: String!
attachments: [AttachmentInput!]
mentionedUsersIds: [String!]
type: ChatStreamChannelType = Livestream
}

input AttachmentInput {
title: String!
titleLink: String
assetUrl: String!
}
FieldTypeDescriptionRequiredDefault
channelIdString!ID of the channel to send the message toYes-
textString!Text content of the messageYes-
attachments[AttachmentInput!]Attachments for the messageNo-
mentionedUsersIds[String!]IDs of users to mention in the messageNo-
typeChatStreamChannelTypeType of the channelNoLivestream

Response​

Returns a boolean indicating whether the operation was successful.

setRoleToUsersOnChat​

Updates a user's role in the chat system.

Mutation​

mutation SetRoleToUsersOnChat($input: UpdateUsersChatRoleInput!) {
setRoleToUsersOnChat(input: $input)
}

Arguments​

NameTypeDescriptionRequired
inputUpdateUsersChatRoleInput!Input data for updating a user's chat roleYes

UpdateUsersChatRoleInput​

input UpdateUsersChatRoleInput {
userId: String!
role: ChatRole!
}
FieldTypeDescriptionRequired
userIdString!ID of the user to updateYes
roleChatRole!New chat role for the userYes

Response​

Returns a boolean indicating whether the operation was successful.

Enums​

ChatStreamChannelType​

enum ChatStreamChannelType {
Livestream
Messaging
Team
Gaming
Commerce
}

ChatRole​

enum ChatRole {
USER
ADMIN
MODERATOR
}

Error Handling​

Common Errors​

Error CodeDescriptionResolution
UNAUTHORIZEDUser is not authorized to perform the operationEnsure the user has the proper CRM role (BO)
INVALID_ARGUMENTSInvalid arguments providedCheck the provided arguments against the schema
FILE_TYPE_NOT_SUPPORTEDAttachment file type not supportedUse only supported file types (png, jpg/jpeg, mp4, avi, mov, flv)

Example Error Response​

{
"errors": [
{
"message": "File does not support. You must use .png or .jpg/jpeg or .mp4 or .avi or .mov or .flv",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": ["sendMessageToChannel"],
"extensions": {
"code": "FILE_TYPE_NOT_SUPPORTED"
}
}
],
"data": {
"sendMessageToChannel": null
}
}

Usage Examples​

Creating a New Chat Channel​

const CREATE_CHANNEL = gql`
mutation CreateChannel($input: CreateOrUpdateStreamChatChanelInput!) {
createOrUpdateChannel(input: $input)
}
`;

// Example usage
const [createChannel] = useMutation(CREATE_CHANNEL);
createChannel({
variables: {
input: {
name: 'Announcements',
avatarFilename: 'announcement-avatar.png',
type: 'Livestream',
},
},
});

Sending a Message to a Channel​

const SEND_MESSAGE = gql`
mutation SendMessage($input: SendMessageToChannelChanelInput!) {
sendMessageToChannel(input: $input)
}
`;

// Example usage
const [sendMessage] = useMutation(SEND_MESSAGE);
sendMessage({
variables: {
input: {
channelId: 'announcements',
text: 'Important announcement for all users!',
attachments: [
{
title: 'Event Image',
assetUrl: 'https://example.com/images/event.jpg',
},
],
mentionedUsersIds: ['user1', 'user2'],
},
},
});