@ipscape/chat-client-js
Version:
ipSCAPE chat client SDK
104 lines (103 loc) • 3.72 kB
TypeScript
import { EventEmitter } from 'events';
import { ChatMessage, ChatMessageReadReceipt, ChatMessageType, ChatParticipant, SendChatMessageResult } from '@azure/communication-chat';
declare class ChatClient extends EventEmitter {
private acsChatClient;
/**
* Creates new chat client instance
* @constructor
* @param config
*/
constructor(config: ChatClient.ConfigPayload);
/**
* Send chat message
* @param payload
*/
sendMessage(payload: ChatClient.ChatMessagePayload): Promise<SendChatMessageResult>;
/**
* Send typing notification
* @param payload
*/
sendTypingNotification(payload: ChatClient.TypingNotificationPayload): Promise<boolean>;
/**
* Send read receipt for a message
* @param payload
*/
sendReadReceipt(payload: ChatClient.ReadReceiptPayload): Promise<void>;
/**
* Gets a list of read receipt from a thread identified by threadId. Returns the list of the messages.
* @param payload
*/
listReadReceipts(payload: ChatClient.ListReadReceiptPayload): Promise<ChatMessageReadReceipt[]>;
/**
* Gets the participants of the thread identified by threadId. Returns the lists of the participants.
* @param payload
*/
listParticipants(payload: ChatClient.ListParticipantsPayload): Promise<ChatParticipant[]>;
/**
* Stop receiving realtime notifications. This function would unsubscribe to all events.
*/
stopRealtimeNotifications(): Promise<void>;
/**
* Removes participant from the thread identified by threadId.
*/
removeParticipant(payload: ChatClient.RemoveParticipantPayload): Promise<void>;
/**
* Gets a list of message from a thread identified by threadId. Returns the list of the messages.
*/
listMessages(payload: ChatClient.ListMessagesPayload): Promise<ChatMessage[]>;
/**
* Start receiving realtime notifications. Call this function before subscribing to any event.
*/
startRealtimeNotifications(): Promise<void>;
}
declare namespace ChatClient {
type ConfigPayload = {
endpointUrl: string;
token: string;
};
type ChatMessagePayload = {
threadId: string;
message: string;
metadata: Record<string, any>;
senderDisplayName: string;
type?: ChatMessageType;
};
type TypingNotificationPayload = {
threadId: string;
senderDisplayName: string;
};
type ReadReceiptPayload = {
threadId: string;
messageId: string;
};
type ListReadReceiptPayload = {
threadId: string;
};
type ListParticipantsPayload = {
threadId: string;
};
type RemoveParticipantPayload = {
communicationUserId: string;
threadId: string;
};
type ListMessagesPayload = {
maxPageSize?: number;
startTime?: string;
threadId: string;
};
enum Events {
CHAT_MESSAGE_RECEIVED = "chatMessageReceived",
CHAT_MESSAGE_EDITED = "chatMessageEdited",
CHAT_MESSAGE_DELETED = "chatMessageDeleted",
CHAT_TYPING_INDICATOR_RECEIVED = "typingIndicatorReceived",
CHAT_READ_RECEIPT_RECEIVED = "readReceiptReceived",
CHAT_THREAD_CREATED = "chatThreadCreated",
CHAT_THREAD_DELETED = "chatThreadDeleted",
CHAT_THREAD_PROPERTIES_UPDATED = "chatThreadPropertiesUpdated",
CHAT_PARTICIPANTS_ADDED = "participantsAdded",
CHAT_PARTICIPANTS_REMOVED = "participantsRemoved",
CHAT_REAL_TIME_NOTIFICATION_CONNECTED = "realTimeNotificationConnected",
CHAT_REAL_TIME_NOTIFICATION_DISCONNECTED = "realTimeNotificationDisconnected"
}
}
export default ChatClient;