ВОЙТИ

Conversation

Class that may be used to manage a conversation.

Methods

addParticipants

addParticipants(participants: Array<ConversationParticipant>): Promise<ConversationEvent|ErrorEvent>

Add new participants to the conversation.

It's possible only on the following conditions:

Duplicated users are ignored. The promise will be rejected with ErrorEvent if at least one user does not exist or already belongs to the conversation.

Other parties of the conversation (online participants and logged in clients) can be informed about adding participants via the MessengerEventTypes.EditConversation event.

Parameters

  • participants:

    Array<ConversationParticipant>

    Array of ConversationParticipant to be added to the conversation. Should not be null or empty array

Returns

editParticipants

editParticipants(participants: Array<ConversationParticipant>): Promise<ConversationEvent|ErrorEvent>

Edit participants' permissions. It's possible only if the current user can manage other participants (ConversationParticipant.canManageParticipants is true).

Duplicated users are ignored. The list of participants must contain all participants. Other parties of the conversation (online participants and logged in clients) can be informed about editing participants via the MessengerEventTypes.EditConversation event.

Parameters

  • participants:

    Array<ConversationParticipant>

    Array of ConversationParticipant to be edited in the conversation. Should not be null or empty array

Returns

markAsRead

markAsRead(sequence: number): Promise<ConversationServiceEvent|ErrorEvent>

Mark the event with the specified sequence as read.

A method call with the specified sequence makes the ConversationParticipant.lastReadEventSequence return this sequence, i.e., such sequences can be get for each participant separately.

If the sequence parameter specified less than 1, the method will mark all the events as unread (for this participant) except the event with the sequence equals to '1'.

Other parties of the conversation (online participants and logged in clients) can be informed about marking events as read via the MessengerEventTypes.Read event.

Parameters

  • sequence:

    number

    Sequence number of the event in the conversation to be marked as read. Shouldn't be greater than currently possible.

Returns

removeParticipants

removeParticipants(participants: Array<ConversationParticipant>): Promise<ConversationEvent|ErrorEvent>

Remove participants from the conversation. It's possible only on two conditions:

Duplicated users are ignored. The promise will be rejected with ErrorEvent if at least one user:

  • does not exist
  • is already removed

Note that you can remove participants that are marked as deleted (User.isDeleted is true).

The removed participants can later get this conversation's UUID via the User.leaveConversationList.

Other parties of the conversation (online participants and logged in clients) can be informed about removing participants via the MessengerEventTypes.EditConversation event.

Parameters

  • participants:

    Array<ConversationParticipant>

    Array of ConversationParticipant to be removed from the conversation. Should not be null or empty array

Returns

retransmitEvents

retransmitEvents(from: number, to: number): Promise<RetransmitEvent|ErrorEvent>

Request events in the specified sequence range to be sent from the cloud to this client.

Only ConversationEvent and MessageEvent events can be retransmitted; any other events can't be retransmitted.

The method is used to get history or missed events in case of network disconnect. Client should use this method to request all events based on the last event sequence received from the cloud and last event sequence saved locally (if any).

The maximum amount of retransmitted events per method call is 100. The promise will be rejected with ErrorEvent if more than 100 events are requested.

If the current user quits a Conversation.uber conversation, messages that are posted during the user's absence will not be retransmitted later.

Parameters

  • from:

    number

    First event in range sequence, inclusive

  • to:

    number

    Last event in sequence range, inclusive

Returns

retransmitEventsFrom

retransmitEventsFrom(from: number, count: number): Promise<RetransmitEvent|ErrorEvent>

Request a number of events starting with the specified sequence to be sent from the cloud to this client.

Only ConversationEvent and MessageEvent events can be retransmitted; any other events can't be retransmitted.

The method is used to get history or missed events in case of network disconnect. Client should use this method to request all events based on the last event sequence received from the cloud and last event sequence saved locally (if any).

The maximum amount of retransmitted events per method call is 100. The promise will be rejected with ErrorEvent if more than 100 events are requested.

If the current user quits a Conversation.uber conversation, messages that are posted during the user's absence will not be retransmitted later.

The result contains maximum available events for the current user even if it's less than the specified count value.

Parameters

  • from:

    number

    First event in sequence range, inclusive

  • count:

    number

    Number of events

Returns

retransmitEventsTo

retransmitEventsTo(to: number, count: number): Promise<RetransmitEvent|ErrorEvent>

Request a number of events up to the specified sequence to be sent from the cloud to this client.

Only ConversationEvent and MessageEvent events can be retransmitted; any other events can't be retransmitted.

The method is used to get history or missed events in case of network disconnect. Client should use this method to request all events based on the last event sequence received from the cloud and last event sequence saved locally (if any).

The maximum amount of retransmitted events per method call is 100. The promise will be rejected with ErrorEvent if more than 100 events are requested.

If the current user quits a Conversation.uber conversation, messages that are posted during the user's absence will not be retransmitted later.

The result contains maximum available events for the current user even if it's less than the specified count value.

Parameters

  • to:

    number

    Last event in sequence range, inclusive

  • count:

    number

    Number of events

Returns

sendMessage

sendMessage(text: string, payload: Array<object>): Promise<MessageEvent|ErrorEvent>

Send a message to the conversation.

Sending messages is available only for participants that have write permissions (ConversationParticipant.canWrite is true).

Other parties of the conversation (online participants and logged in clients) can be informed about sending messages to the conversation via the MessengerEventTypes.SendMessage event.

To be informed about sending messages while being offline, participants can subscribe to the MessengerNotification.SendMessage messenger push notification.

Parameters

  • text:

    string

    Message text, maximum 5000 characters

  • payload:

    Array<object>
    OPTIONAL

    Message payload

Returns

setCustomData

setCustomData(customData: object): void

Set the JS object custom data. Note that setting this property does not send changes to the server. Use the Conversation.update to send all changes at once.

Parameters

  • customData:

    object

    New custom data of the conversation

setPublicJoin

setPublicJoin(publicJoin: boolean): void

Set the public join flag. Note that setting this property does not send changes to the server. Use the Conversation.update to send all changes at once.

Parameters

  • publicJoin:

    boolean

setTitle

setTitle(title: string): void

Set the conversation title. Note that setting this property does not send changes to the server. Use the Conversation.update to send all changes at once.

Parameters

  • title:

    string

typing

typing(): Promise<ConversationServiceEvent|ErrorEvent>

Inform the cloud that the user is typing some text.

The promise will be rejected with ErrorEvent for the method calls within 10s interval from the last call cause.

Other parties of the conversation (online participants and logged in clients) can be informed about typing via the MessengerEventTypes.Typing event.

Returns

update

update(): Promise<ConversationEvent|ErrorEvent>

Send conversation changes to the cloud. The sent changes are: title, public join flag and custom data.

Successful update will happen if a participant is the owner (ConversationParticipant.owner is true).

Other parties of the conversation (online participants and logged in clients) can be informed about changing the title or custom data and enabling/disabling public join via the MessengerEventTypes.EditConversation event.

Returns

Properties

createdTime

UNIX timestamp (seconds) that specifies the time of the conversation creation.

customData

JavaScript object with custom data, up to 5kb.

Note that setting this property does not send changes to the server. Use the Conversation.update to send all changes at once.

direct

Check if the conversation is direct.

A direct conversation can't be uber and/or public.

There can be only 2 participants in a direct conversation which is unique and the only one for these participants. There can't be more than 1 direct conversation for the same 2 users.

If one of these users tries to create a new direct conversation with the same participant via Messenger.createConversation, the method will return the UUID of the already existing direct conversation.

lastSequence

Sequence of the last event in the conversation.

lastUpdateTime

UNIX timestamp (seconds) that specifies the time when one of ConversationEvent or MessageEvent was the last provoked event in this conversation.

participants

Array of participants alongside with their permissions.

publicJoin

Check if a conversation is public or not. If true, anyone can join the conversation by UUID.

A public conversation can't be direct.

Note that setting this property does not send changes to the server. Use the Conversation.update to send all changes at once.

title

Th current conversation title.

Note that setting this property does not send changes to the server. Use the Conversation.update to send all changes at once.

uber

Check if the conversation is uber or not.

A uber conversation can't be direct.

Users in a uber conversation will not be able to retrieve messages that were posted to the conversation after they quit.

uuid

Universally unique identifier (UUID) of this conversation.