EventChat
The EventChat module in ZDK acts as a bridge between the Chats and Event modules, streamlining the chat experience within a specific event. By serving as this intermediary, it offers users direct access to the chat associated with the current event without any additional complexities. Notably, the EventChat module stands out for its ease of use, ensuring a seamless and intuitive chat experience within events.
Dependencies- core
- user
- websocket
- chats
- event
Initialization
const eventChat = createEventChat({
userModule: user,
webSocketModule: webSocket,
eventModule: event,
chatsModule: chats,
});Actions
sendMessage
Action type(content: string): Promise<IMessageReady>
Sends a text message to the current event chat. The message is marked as ‘loading’ until sent, then ‘ready’ or ‘interrupted’ on success or failure. The content has a character limit - 256.
Parameterscontent- the content of the message to be sent
Returns a promise that resolves with the details of the sent message.
Possible errorsActionCallError- Can not perform this action (sendMessage) while module is not connected with WebSocket.ActionCallError- Cannot send a message to a chat that is loading - wait for joinChat to finish.
updateMessage
Action type(messageId: string, content: string): Promise<IMessageReady>
Modifies the text of a previously sent message in the event chat, seamlessly updating the conversation in real-time.
ParametersmessageId- id of selected message.content- the new content for the message.
Return value Returns a promise that resolves with the details of the updated message.
Possible errorsActionCallError- Can not perform this action (updateMessage) while module is not connected with WebSocket.ActionCallError- Cannot update a message to a chat that is loading - wait for joinChat to finish.ActionCallError- Cannot update not existing a message - a message with this id does not exist in the selected chat.ActionCallError- You can only update a message with status ready.ActionCallError- The message is being deleted. You can not update it in that moment.ActionCallError- The message is being updated. You can not update it in that moment.
deleteMessage
Action type(messageId: string): Promise<IMessage>
Removes a specified message from the event chat, effectively erasing its content from the chat history.
ParametersmessageId- id of selected message.
Return value Returns a promise that resolves with the details of the deleted message.
Possible errorsActionCallError- Can not perform this action (deleteMessage) while module is not connected with WebSocket.ActionCallError- Cannot delete a message to a chat that is loading - wait for joinChat to finish.ActionCallError- Cannot delete not existing a message - a message with this id does not exist in the selected chat.ActionCallError- You can only delete a message with status ready or interrupted.ActionCallError- The message is already being deleted.ActionCallError- The message is being updated. You can not be deleted it in that moment.
resendMessage
Action type(messageId: string): Promise<IMessage>
Description
Initiates additional send attempt for a message in the event chat, ensuring the communication is conveyed.
Parameters
messageId - id of selected message.
Return value Returns a promise that resolves with the details of the resent message.
Possible errorsActionCallError- Can not perform this action (resendMessage) while module is not connected with WebSocket.ActionCallError- Cannot send a message to a chat that is loading - wait for joinChat to finish.ActionCallError- Cannot update not existing a message - a message with this id does not exist in the selected chat.ActionCallError- You can only delete a message with status ready or interrupted.ActionCallError- You can only resend a message that failed to be send.
blockChatMember
Action type
(userId: string, duration: number, reason?: string): Promise<void>
Description This feature restricts a specific user from participating in the chat, preventing them from sending messages or viewing new activity.
ParametersuserId- unique identifier of the chat member who will be subject to the block.duration- time in minutes for which the block will be effective, with a value of 0 indicating a permanent block.reason- explanation or justification for implementing the block on the chat member.
Return value Returns a promise that finish after request sending.
Possible errorsActionCallError- Can not perform this action (blockChatMember) while module is not connected with WebSocket.
unblockChatMember
Action type
(userId: string): Promise<void>
Description This feature reverses a previously set block on a user in the chat, restoring their ability to send messages and view new chat activity.
ParametersuserId- unique identifier of the chat member who will be subject to the unblock.
Return value Returns a promise that finish after request sending.
Possible errorsActionCallError- Can not perform this action (unblockChatMember) while module is not connected with WebSocket.
muteChatMember
Action type
(userId: string, duration: number, reason?: string): Promise<void>
Description This feature temporarily disables a user’s ability to send messages in the chat, while they can still view messages from other participants.
ParametersuserId- unique identifier of the chat member who will be subject to the mute.duration- time in minutes for which the mute will be effective, with a value of 0 indicating a permanent mute.reason- explanation or justification for implementing the mute on the chat member.
Return value Returns a promise that finish after request sending.
Possible errorsActionCallError- Can not perform this action (muteChatMember) while module is not connected with WebSocket.
unmuteChatMember
Action type
(userId: string): Promise<void>
Description This feature restores a previously muted user’s ability to send messages in the chat.
ParametersuserId- unique identifier of the chat member who will be subject to the unmute.
Return value Returns a promise that finish after request sending.
Possible errorsActionCallError- Can not perform this action (unmuteChatMember) while module is not connected with WebSocket.
kickChatMember
Action type
(userId: string, reason?: string): Promise<void>
Description This feature removes a user from the chat, blocking them from sending or seeing messages. However, the user has the option to re-enter the chat anytime afterward.
ParametersuserId- unique identifier of the chat member who will be subject to the kick.reason- explanation or justification for implementing the kick on the chat member.
Return value Returns a promise that finish after request sending.
Possible errorsActionCallError- Can not perform this action (kickChatMember) while module is not connected with WebSocket.
Data (Getters)
eventChatMessages
Getter output type:
IGetter<IMessage[] | undefined
Description This getter provides access to the list of messages in the event chat. If there are no messages, it will return undefined.
eventChatStatus
Getter output type:
IGetter<'loading' | 'ready' | 'reloading' | undefined>
Description This getter provides access to the current status of the event chat.
loading- fetching data about selected chatready- connected and synchronized properlyreloading- connected and synchronized properlyundefined- because of connection lost, the event state can be temporarily desynchronized, this state appear after we are trying to synchronize all the data again
Types
IMessage
export type IMessage = {
sendingStatus: 'ready' | 'loading' | 'interrupted',
deleteStatus: 'idle' | 'loading' | 'interrupted',
updateStatus: 'idle' | 'loading' | 'interrupted',
/**
* Represents the unique identifier for this message.
*/
id: string;
/**
* Represents the unique identifier of the user associated with this message.
*/
userId: string;
/**
* Represents the unique identifier of the chat in which this message exists.
*/
chatId: string;
/**
* Represents the textual content of this message.
*/
content: string;
/**
* Represents a collection of key-value pairs providing additional context or information about this message.
*/
metadata: {
[key: string]: string;
};
/**
* Represents the timestamp indicating when this message was sent.
*/
createTime: bigint;
/**
* Represents the timestamp of the last update associated with this message.
*/
updateTime: bigint;
};