ChatClient class

The client to do chat operations

Constructors

ChatClient(string, CommunicationTokenCredential, ChatClientOptions)

Creates an instance of the ChatClient for a given resource and user.

Methods

createChatThread(CreateChatThreadRequest, CreateChatThreadOptions)

Creates a chat thread. Returns thread client with the id of the created thread.

deleteChatThread(string, OperationOptions)

Deletes a chat thread.

getChatThreadClient(string)

Returns ChatThreadClient with the specific thread id.

listChatThreads(RestListChatThreadsOptions)

Gets the list of chat threads of a user.

off("chatMessageDeleted", (e: ChatMessageDeletedEvent) => void)

Unsubscribe from chatMessageDeleted.

off("chatMessageEdited", (e: ChatMessageEditedEvent) => void)

Unsubscribe from chatMessageEdited.

off("chatMessageReceived", (e: ChatMessageReceivedEvent) => void)

Unsubscribe from chatMessageReceived.

off("chatThreadCreated", (e: ChatThreadCreatedEvent) => void)

Unsubscribe from chatThreadCreated.

off("chatThreadDeleted", (e: ChatThreadDeletedEvent) => void)

Unsubscribe from chatThreadDeleted.

off("chatThreadPropertiesUpdated", (e: ChatThreadPropertiesUpdatedEvent) => void)

Unsubscribe from chatThreadPropertiesUpdated.

off("participantsAdded", (e: ParticipantsAddedEvent) => void)

Unsubscribe from participantsAdded.

off("participantsRemoved", (e: ParticipantsRemovedEvent) => void)

Unsubscribe from participantsRemoved.

off("readReceiptReceived", (e: ReadReceiptReceivedEvent) => void)

Unsubscribe from readReceiptReceived.

off("typingIndicatorReceived", (e: TypingIndicatorReceivedEvent) => void)

Unsubscribe from typingIndicatorReceived.

on("chatMessageDeleted", (e: ChatMessageDeletedEvent) => void)

Subscribe function for chatMessageDeleted. The initial sender will also receive this event.

on("chatMessageEdited", (e: ChatMessageEditedEvent) => void)

Subscribe function for chatMessageEdited. The initial sender will also receive this event.

on("chatMessageReceived", (e: ChatMessageReceivedEvent) => void)

Subscribe function for chatMessageReceived. The initial sender will also receive this event. You need to call startRealtimeNotifications before subscribing to any event.

on("chatThreadCreated", (e: ChatThreadCreatedEvent) => void)

Subscribe function for chatThreadCreated.

on("chatThreadDeleted", (e: ChatThreadDeletedEvent) => void)

Subscribe function for chatThreadDeleted.

on("chatThreadPropertiesUpdated", (e: ChatThreadPropertiesUpdatedEvent) => void)

Subscribe function for chatThreadPropertiesUpdated.

on("participantsAdded", (e: ParticipantsAddedEvent) => void)

Subscribe function for participantsAdded.

on("participantsRemoved", (e: ParticipantsRemovedEvent) => void)

Subscribe function for participantsRemoved.

on("readReceiptReceived", (e: ReadReceiptReceivedEvent) => void)

Subscribe function for readReceiptReceived.

on("realTimeNotificationConnected", () => void)

Subscribe function for realTimeNotificationConnected.

on("realTimeNotificationDisconnected", () => void)

Subscribe function for realTimeNotificationDisconnected.

on("typingIndicatorReceived", (e: TypingIndicatorReceivedEvent) => void)

Subscribe function for typingIndicatorReceived. The initial sender will also receive this event.

startRealtimeNotifications()

Start receiving realtime notifications. Call this function before subscribing to any event.

stopRealtimeNotifications()

Stop receiving realtime notifications. This function would unsubscribe to all events.

Constructor Details

ChatClient(string, CommunicationTokenCredential, ChatClientOptions)

Creates an instance of the ChatClient for a given resource and user.

new ChatClient(endpoint: string, credential: CommunicationTokenCredential, options?: ChatClientOptions)

Parameters

endpoint

string

The url of the Communication Services resource.

credential
CommunicationTokenCredential

The token credential. Use AzureCommunicationTokenCredential from @azure/communication-common to create a credential.

options
ChatClientOptions

Additional client options.

Method Details

createChatThread(CreateChatThreadRequest, CreateChatThreadOptions)

Creates a chat thread. Returns thread client with the id of the created thread.

function createChatThread(request: CreateChatThreadRequest, options?: CreateChatThreadOptions): Promise<CreateChatThreadResult>

Parameters

request
CreateChatThreadRequest

Request for creating a chat thread.

options
CreateChatThreadOptions

Operation options.

Returns

deleteChatThread(string, OperationOptions)

Deletes a chat thread.

function deleteChatThread(threadId: string, options?: OperationOptions): Promise<void>

Parameters

threadId

string

The ID of the thread to delete.

options
OperationOptions

Operation options.

Returns

Promise<void>

getChatThreadClient(string)

Returns ChatThreadClient with the specific thread id.

function getChatThreadClient(threadId: string): ChatThreadClient

Parameters

threadId

string

Thread ID for the ChatThreadClient

Returns

listChatThreads(RestListChatThreadsOptions)

Gets the list of chat threads of a user.

function listChatThreads(options?: RestListChatThreadsOptions): PagedAsyncIterableIterator<ChatThreadItem, ChatThreadItem[], PageSettings>

Parameters

options
RestListChatThreadsOptions

List chat threads options.

Returns

off("chatMessageDeleted", (e: ChatMessageDeletedEvent) => void)

Unsubscribe from chatMessageDeleted.

function off(event: "chatMessageDeleted", listener: (e: ChatMessageDeletedEvent) => void)

Parameters

event

"chatMessageDeleted"

The ChatMessageDeletedEvent.

listener

(e: ChatMessageDeletedEvent) => void

The listener to handle the event.

off("chatMessageEdited", (e: ChatMessageEditedEvent) => void)

Unsubscribe from chatMessageEdited.

function off(event: "chatMessageEdited", listener: (e: ChatMessageEditedEvent) => void)

Parameters

event

"chatMessageEdited"

The ChatMessageEditedEvent.

listener

(e: ChatMessageEditedEvent) => void

The listener to handle the event.

off("chatMessageReceived", (e: ChatMessageReceivedEvent) => void)

Unsubscribe from chatMessageReceived.

function off(event: "chatMessageReceived", listener: (e: ChatMessageReceivedEvent) => void)

Parameters

event

"chatMessageReceived"

The ChatMessageReceivedEvent.

listener

(e: ChatMessageReceivedEvent) => void

The listener to handle the event.

off("chatThreadCreated", (e: ChatThreadCreatedEvent) => void)

Unsubscribe from chatThreadCreated.

function off(event: "chatThreadCreated", listener: (e: ChatThreadCreatedEvent) => void)

Parameters

event

"chatThreadCreated"

The ChatThreadCreatedEvent.

listener

(e: ChatThreadCreatedEvent) => void

The listener to handle the event.

off("chatThreadDeleted", (e: ChatThreadDeletedEvent) => void)

Unsubscribe from chatThreadDeleted.

function off(event: "chatThreadDeleted", listener: (e: ChatThreadDeletedEvent) => void)

Parameters

event

"chatThreadDeleted"

The ChatThreadDeletedEvent.

listener

(e: ChatThreadDeletedEvent) => void

The listener to handle the event.

off("chatThreadPropertiesUpdated", (e: ChatThreadPropertiesUpdatedEvent) => void)

Unsubscribe from chatThreadPropertiesUpdated.

function off(event: "chatThreadPropertiesUpdated", listener: (e: ChatThreadPropertiesUpdatedEvent) => void)

Parameters

event

"chatThreadPropertiesUpdated"

The ChatThreadPropertiesUpdatedEvent.

listener

(e: ChatThreadPropertiesUpdatedEvent) => void

The listener to handle the event.

off("participantsAdded", (e: ParticipantsAddedEvent) => void)

Unsubscribe from participantsAdded.

function off(event: "participantsAdded", listener: (e: ParticipantsAddedEvent) => void)

Parameters

event

"participantsAdded"

The ParticipantsAddedEvent.

listener

(e: ParticipantsAddedEvent) => void

The listener to handle the event.

off("participantsRemoved", (e: ParticipantsRemovedEvent) => void)

Unsubscribe from participantsRemoved.

function off(event: "participantsRemoved", listener: (e: ParticipantsRemovedEvent) => void)

Parameters

event

"participantsRemoved"

The ParticipantsRemovedEvent.

listener

(e: ParticipantsRemovedEvent) => void

The listener to handle the event.

off("readReceiptReceived", (e: ReadReceiptReceivedEvent) => void)

Unsubscribe from readReceiptReceived.

function off(event: "readReceiptReceived", listener: (e: ReadReceiptReceivedEvent) => void)

Parameters

event

"readReceiptReceived"

The ReadReceiptReceivedEvent.

listener

(e: ReadReceiptReceivedEvent) => void

The listener to handle the event.

off("typingIndicatorReceived", (e: TypingIndicatorReceivedEvent) => void)

Unsubscribe from typingIndicatorReceived.

function off(event: "typingIndicatorReceived", listener: (e: TypingIndicatorReceivedEvent) => void)

Parameters

event

"typingIndicatorReceived"

The TypingIndicatorReceivedEvent.

listener

(e: TypingIndicatorReceivedEvent) => void

The listener to handle the event.

on("chatMessageDeleted", (e: ChatMessageDeletedEvent) => void)

Subscribe function for chatMessageDeleted. The initial sender will also receive this event.

function on(event: "chatMessageDeleted", listener: (e: ChatMessageDeletedEvent) => void)

Parameters

event

"chatMessageDeleted"

The ChatMessageDeletedEvent.

listener

(e: ChatMessageDeletedEvent) => void

The listener to handle the event.

on("chatMessageEdited", (e: ChatMessageEditedEvent) => void)

Subscribe function for chatMessageEdited. The initial sender will also receive this event.

function on(event: "chatMessageEdited", listener: (e: ChatMessageEditedEvent) => void)

Parameters

event

"chatMessageEdited"

The ChatMessageEditedEvent.

listener

(e: ChatMessageEditedEvent) => void

The listener to handle the event.

on("chatMessageReceived", (e: ChatMessageReceivedEvent) => void)

Subscribe function for chatMessageReceived. The initial sender will also receive this event. You need to call startRealtimeNotifications before subscribing to any event.

function on(event: "chatMessageReceived", listener: (e: ChatMessageReceivedEvent) => void)

Parameters

event

"chatMessageReceived"

The ChatMessageReceivedEvent.

listener

(e: ChatMessageReceivedEvent) => void

The listener to handle the event.

on("chatThreadCreated", (e: ChatThreadCreatedEvent) => void)

Subscribe function for chatThreadCreated.

function on(event: "chatThreadCreated", listener: (e: ChatThreadCreatedEvent) => void)

Parameters

event

"chatThreadCreated"

The ChatThreadCreatedEvent.

listener

(e: ChatThreadCreatedEvent) => void

The listener to handle the event.

on("chatThreadDeleted", (e: ChatThreadDeletedEvent) => void)

Subscribe function for chatThreadDeleted.

function on(event: "chatThreadDeleted", listener: (e: ChatThreadDeletedEvent) => void)

Parameters

event

"chatThreadDeleted"

The ChatThreadDeletedEvent.

listener

(e: ChatThreadDeletedEvent) => void

The listener to handle the event.

on("chatThreadPropertiesUpdated", (e: ChatThreadPropertiesUpdatedEvent) => void)

Subscribe function for chatThreadPropertiesUpdated.

function on(event: "chatThreadPropertiesUpdated", listener: (e: ChatThreadPropertiesUpdatedEvent) => void)

Parameters

event

"chatThreadPropertiesUpdated"

The ChatThreadPropertiesUpdatedEvent.

listener

(e: ChatThreadPropertiesUpdatedEvent) => void

The listener to handle the event.

on("participantsAdded", (e: ParticipantsAddedEvent) => void)

Subscribe function for participantsAdded.

function on(event: "participantsAdded", listener: (e: ParticipantsAddedEvent) => void)

Parameters

event

"participantsAdded"

The ParticipantsAddedEvent.

listener

(e: ParticipantsAddedEvent) => void

The listener to handle the event.

on("participantsRemoved", (e: ParticipantsRemovedEvent) => void)

Subscribe function for participantsRemoved.

function on(event: "participantsRemoved", listener: (e: ParticipantsRemovedEvent) => void)

Parameters

event

"participantsRemoved"

The ParticipantsRemovedEvent.

listener

(e: ParticipantsRemovedEvent) => void

The listener to handle the event.

on("readReceiptReceived", (e: ReadReceiptReceivedEvent) => void)

Subscribe function for readReceiptReceived.

function on(event: "readReceiptReceived", listener: (e: ReadReceiptReceivedEvent) => void)

Parameters

event

"readReceiptReceived"

The ReadReceiptReceivedEvent.

listener

(e: ReadReceiptReceivedEvent) => void

The listener to handle the event.

on("realTimeNotificationConnected", () => void)

Subscribe function for realTimeNotificationConnected.

function on(event: "realTimeNotificationConnected", listener: () => void)

Parameters

event

"realTimeNotificationConnected"

The realTimeNotificationConnected Event

listener

() => void

The listener to handle the event.

on("realTimeNotificationDisconnected", () => void)

Subscribe function for realTimeNotificationDisconnected.

function on(event: "realTimeNotificationDisconnected", listener: () => void)

Parameters

event

"realTimeNotificationDisconnected"

The realTimeNotificationDisconnected Event

listener

() => void

The listener to handle the event.

on("typingIndicatorReceived", (e: TypingIndicatorReceivedEvent) => void)

Subscribe function for typingIndicatorReceived. The initial sender will also receive this event.

function on(event: "typingIndicatorReceived", listener: (e: TypingIndicatorReceivedEvent) => void)

Parameters

event

"typingIndicatorReceived"

The TypingIndicatorReceivedEvent.

listener

(e: TypingIndicatorReceivedEvent) => void

The listener to handle the event.

startRealtimeNotifications()

Start receiving realtime notifications. Call this function before subscribing to any event.

function startRealtimeNotifications(): Promise<void>

Returns

Promise<void>

stopRealtimeNotifications()

Stop receiving realtime notifications. This function would unsubscribe to all events.

function stopRealtimeNotifications(): Promise<void>

Returns

Promise<void>