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​
Name | Type | Description | Required |
---|---|---|---|
input | CreateOrUpdateStreamChatChanelInput! | Input data for creating or updating a channel | Yes |
CreateOrUpdateStreamChatChanelInput​
input CreateOrUpdateStreamChatChanelInput {
id: String
name: String!
avatarFilename: String
type: ChatStreamChannelType = Livestream
}
Field | Type | Description | Required | Default |
---|---|---|---|---|
id | String | ID of the channel (required for update) | No | - |
name | String! | Name of the channel | Yes | - |
avatarFilename | String | Filename of the channel avatar | No | - |
type | ChatStreamChannelType | Type of the channel | No | Livestream |
Response​
Returns a boolean indicating whether the operation was successful.
deleteChannels​
Deletes multiple chat channels.
Mutation​
mutation DeleteChannels($input: DeleteStreamChatChanelInput!) {
deleteChannels(input: $input)
}
Arguments​
Name | Type | Description | Required |
---|---|---|---|
input | DeleteStreamChatChanelInput! | Input data for deleting channels | Yes |
DeleteStreamChatChanelInput​
input DeleteStreamChatChanelInput {
cids: [String!]!
}
Field | Type | Description | Required |
---|---|---|---|
cids | [String!]! | Array of channel IDs to delete | Yes |
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​
Name | Type | Description | Required |
---|---|---|---|
input | SendMessageToChannelChanelInput! | Input data for sending a message | Yes |
SendMessageToChannelChanelInput​
input SendMessageToChannelChanelInput {
channelId: String!
text: String!
attachments: [AttachmentInput!]
mentionedUsersIds: [String!]
type: ChatStreamChannelType = Livestream
}
input AttachmentInput {
title: String!
titleLink: String
assetUrl: String!
}
Field | Type | Description | Required | Default |
---|---|---|---|---|
channelId | String! | ID of the channel to send the message to | Yes | - |
text | String! | Text content of the message | Yes | - |
attachments | [AttachmentInput!] | Attachments for the message | No | - |
mentionedUsersIds | [String!] | IDs of users to mention in the message | No | - |
type | ChatStreamChannelType | Type of the channel | No | Livestream |
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​
Name | Type | Description | Required |
---|---|---|---|
input | UpdateUsersChatRoleInput! | Input data for updating a user's chat role | Yes |
UpdateUsersChatRoleInput​
input UpdateUsersChatRoleInput {
userId: String!
role: ChatRole!
}
Field | Type | Description | Required |
---|---|---|---|
userId | String! | ID of the user to update | Yes |
role | ChatRole! | New chat role for the user | Yes |
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 Code | Description | Resolution |
---|---|---|
UNAUTHORIZED | User is not authorized to perform the operation | Ensure the user has the proper CRM role (BO) |
INVALID_ARGUMENTS | Invalid arguments provided | Check the provided arguments against the schema |
FILE_TYPE_NOT_SUPPORTED | Attachment file type not supported | Use 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'],
},
},
});