type ObjectKey = string | number | symbol; type EmptyObject = Record; type UnknownObject = Record; type UUID = string; type RequiredAtLeastOne = Pick> & { [K in Keys]-?: Required> & Partial>>; }[Keys]; interface BaseBusEvent { name: string; } interface ListenerOptions { /** * Whether a listener should be invoked at most once after being added. * The default value is false. */ once?: boolean; /** * A function that returns a boolean to determine if the listener should be called. * The guard not set by default. * * @since 5.1.0 */ guard?: (event: Extract) => boolean; /** * An AbortSignal. The listener will be removed when the abort() method of the AbortController which owns the AbortSignal is called. * See [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) for details. * * @since 5.1.0 */ signal?: AbortSignal; } type Listener = (event: Extract) => void | Promise; type AddEventListener = (event: EventName, listener: Listener, options?: ListenerOptions) => void; type RemoveEventListener = (event: EventName, listener: Listener) => void; declare enum ContainerEvent { ModuleRegistered = "MODULE_REGISTERED" } interface ModuleRegisteredEvent extends BaseBusEvent { name: ContainerEvent.ModuleRegistered; token: Token; } type ContainerEvents = ModuleRegisteredEvent; interface Container { readonly key: string; registerModule: (module: ModuleLoader) => void; registerModules: (modules: ModuleLoader[]) => void; getModule(token: Token, required?: false): Module | undefined; getModule(token: Token, required: true): Module; getModuleAsync: (token: Token) => Promise; addEventListener: AddEventListener; removeEventListener: RemoveEventListener; } interface Token { name: string; module?: ModuleType; } interface InitModuleOptions { container: Container; key: string; } interface ModuleLoader { token: Token; options: Options; required: Token[]; setup: (initOptions: InitModuleOptions) => ModuleType; } type ModuleFactory = Options extends EmptyObject ? () => ModuleLoader : (options: Options) => ModuleLoader; interface BaseModule { /** * @hidden */ container: Container; } declare class BaseModuleImpl implements BaseModule { /** * @hidden */ container: Container; /** * @hidden */ constructor(initOptions: InitModuleOptions); } declare global { interface Navigator { getBattery?: () => Promise; } } interface BatteryManager extends EventTarget { level: number; charging: boolean; chargingTime: number; dischargingTime: number; } declare const WEB_SDK_ERROR_SYMBOL: unique symbol; declare class WebSDKError extends Error { /** * @hidden */ [WEB_SDK_ERROR_SYMBOL]?: boolean; /** * Because of using class in different modules (bundled js files) need to override instanceof operator - * different physical instances of the class in different modules should be treated as the same class * @hidden */ static [Symbol.hasInstance](instance: unknown): instance is WebSDKError; } /** * Interface representing the options for updating a message. * @interface */ export type MessageEditOptions = RequiredAtLeastOne<{ /** * New text of the message, up to 5000 characters. If `null` or `undefined`, the message text is not updated. */ text: string | null; /** * New payload of the message. If `null` or `undefined`, the message payload is not updated. */ payload: UnknownObject[] | null; }>; /** * Interface representing a message within a conversation. */ export interface Message { /** * The universally unique identifier (UUID) of the message. */ uuid: UUID; /** * The UUID of the conversation where the message has been posted. */ conversation: UUID; /** * Message sequence number in the conversation. */ sequence: number; /** * The message text. */ text: string; /** * Array of payload objects associated with the message. */ payload: UnknownObject[]; /** * Sends text and payload changes to the cloud. * * Triggers the [Messaging.Events.MessengerEventType.onEditMessage] event for all participants in the conversation * (online users and logged-in clients). * * Throws a [Messaging.Errors.MessengerError] if: * - Both [Messaging.MessageEditOptions.text] and [Messaging.MessageEditOptions.payload] are `null` or `undefined` * - The current does not have permissions to edit their own messages (see [Messaging.ConversationParticipant.canEditMessages]) * - The current does not have permissions to edit messages from other participants (see [Messaging.ConversationParticipant.canEditAllMessages] and [Messaging.ConversationParticipant.isOwner]) * * Returns a promise that resolves with a [Messaging.Events.ConversationMessageEventPayload] object. * * @throws [Messaging.Errors.MessengerError] * * @param options The new text and/or payload for the message. */ edit: (options: MessageEditOptions) => Promise; /** * Deletes the message in the conversation. * * Triggers the [Messaging.Events.MessengerEventType.onRemoveMessage] event for all participants in the conversation * (online users and logged-in clients). * * Throws a [Messaging.Errors.MessengerError] if: * - The current does not have permissions to delete their own messages (see [Messaging.ConversationParticipant.canRemoveMessages]) * - The current does not have permissions to delete messages of other participants (see * [Messaging.ConversationParticipant.canRemoveAllMessages] and [Messaging.ConversationParticipant.isOwner]) * * Returns a promise that resolves with a [Messaging.Events.ConversationMessageEventPayload] object. * * @throws [Messaging.Errors.MessengerError] */ remove: () => Promise; } /** * Interface representing user information. */ export interface User { /** * IM user's ID—the unique ID used to identify users in events and reference in user-related methods. */ imId: number; /** * Voximplant user identifier, for example: 'username@appname.accname'. */ userName: string; /** * Display name of the user, which is specified during user creation via the Voximplant control panel or * the [Management API](/docs/references/httpapi/users#adduser). * * This name is available to all users. */ displayName: string; /** * Whether the user is deleted. */ isDeleted: boolean; /** * Arbitrary open custom data such as description that can be assigned to the user, which accessible and visible to all users. * * The data can be set via the [Messaging.Messenger.editUser] method. */ customData: UnknownObject | null; /** * Arbitrary private custom data such as description that can be assigned to the user, accessible and visible only to the current user. */ privateCustomData: UnknownObject | null; /** * Array of UUIDs identifying conversations the user is actively participating in. * * Only available to the current user and is not accessible to other users. */ conversationList: UUID[] | null; /** * Array of UUIDs for conversations the user previously participated in but is no longer a member of. * * Only accessible to the current user. */ leaveConversationList: UUID[] | null; } /** * @folder Events */ export declare enum MessengerAction { getUser = "getUser", getUsers = "getUsers", editUser = "editUser", subscribe = "subscribe", unsubscribe = "unsubscribe", getSubscriptionList = "getSubscriptionList", setStatus = "setStatus", createConversation = "createConversation", editConversation = "editConversation", joinConversation = "joinConversation", leaveConversation = "leaveConversation", getConversation = "getConversation", getConversations = "getConversations", getPublicConversations = "getPublicConversations", addParticipants = "addParticipants", editParticipants = "editParticipants", removeParticipants = "removeParticipants", sendMessage = "sendMessage", editMessage = "editMessage", removeMessage = "removeMessage", isRead = "isRead", typingMessage = "typingMessage", retransmitEvents = "retransmitEvents" } /** * @hidden */ export declare enum MessengerEventName { onError = "onError", onGetUser = "onGetUser", onEditUser = "onEditUser", onSubscribe = "onSubscribe", onUnsubscribe = "onUnsubscribe", onSetStatus = "onSetStatus", onGetSubscriptionList = "onGetSubscriptionList", onCreateConversation = "onCreateConversation", onEditConversation = "onEditConversation", onGetConversation = "onGetConversation", onGetPublicConversations = "onGetPublicConversations", onRemoveConversation = "onRemoveConversation", onSendMessage = "onSendMessage", onEditMessage = "onEditMessage", onRemoveMessage = "onRemoveMessage", isRead = "isRead", onTyping = "onTyping", onRetransmitEvents = "onRetransmitEvents" } /** * @internal */ export interface InternalMessengerEventPayload { imUserId: number; eventType: MessengerEventName; action: MessengerAction; } /** * @internal */ export interface MessengerEventPayload { /** * IM ID of the user that initiated the event. */ imUserId: number; /** * Action that triggered this event. */ action: MessengerAction; } /** * @folder Events */ export interface UserEventPayload extends MessengerEventPayload { /** * [Messaging.User] instance with user information. */ user: User; } /** * @folder Events */ export interface StatusEventPayload extends MessengerEventPayload { /** * User status. */ isOnline: boolean; } /** * @folder Events */ export interface SubscriptionEventPayload extends MessengerEventPayload { /** * Array of the IM user identifiers of the current (un)subscription. */ users: User["imId"][]; } /** * @folder Events */ export interface ConversationEventPayload extends MessengerEventPayload { /** * [Messaging.Conversation] instance with the conversation details. */ conversation: Conversation; /** * Sequence number of the event. */ sequence: number; /** * UNIX timestamp (seconds) when the event has been dispatched by the cloud. */ timestamp: number; } /** * @folder Events */ export interface ConversationListEventPayload extends MessengerEventPayload { /** * Array of conversations UUIDs. */ conversationUuidList: UUID[]; } /** * @folder Events */ export interface ConversationMessageEventPayload extends MessengerEventPayload { /** * [Messaging.Message] instance with message information. */ message: Message; /** * Sequence number for the event. */ sequence: number; /** * UNIX timestamp (seconds) when the message event has been triggered. */ timestamp: number; } /** * @folder Events */ export interface ConversationServiceEventPayload extends MessengerEventPayload { /** * Conversation UUID associated with the event. */ conversationUuid: UUID; /** * Sequence number of the event that has been marked as read by the user who initiated this event. * * Only available for [Messaging.Events.MessengerEventType.isRead]. */ sequence: number | null; } /** * @folder Events */ export interface RetransmitEventPayload extends MessengerEventPayload { /** * Array of the event payload objects that have been retransmitted. */ eventPayloads: RetransmittableEvents["payload"][]; /** * Event sequence number from which the events have been retransmitted. */ fromSequence: number; /** * Event sequence number to which the events have been retransmitted. */ toSequence: number; } /** * @folder Events */ export type RetransmittableEvents = OnSendMessageEvent | OnEditMessageEvent | OnRemoveMessageEvent | OnCreateConversationEvent | OnEditConversationEvent; /** * @folder Events */ export declare enum MessengerEventType { /** * Triggered as the result of [Messaging.Messenger.editUser] or similar methods from other Voximplant SDKs and * Messaging API. * * Triggered only for the subscribers of the changed user. * * Use the [Messaging.Messenger.subscribe] API to subscribe for user's changes. * * The listener is called with [Messaging.Events.OnEditUserEvent] and a payload. * @cast Messaging.Events.UserEventPayload */ onEditUser = "onEditUser", /** * Triggered as the result of [Messaging.Messenger.subscribe] or similar methods from other Voximplant SDKs and * Messaging API. * * Triggered on all logged in clients of the current user. * * The listener is called with [Messaging.Events.OnSubscribeEvent] and a payload. * @cast Messaging.Events.SubscriptionEventPayload */ onSubscribe = "onSubscribe", /** * Triggered as the result of [Messaging.Messenger.unsubscribe] or similar methods from other Voximplant SDKs * and Messaging API. * * Triggered on all logged in clients of the current user. * * The listener is called with [Messaging.Events.OnUnsubscribeEvent] and a payload. * @cast Messaging.Events.SubscriptionEventPayload */ onUnsubscribe = "onUnsubscribe", /** * Triggered if a user status has been changed via [Messaging.Messenger.setStatus] or similar methods from other * Voximplant SDKs and Messaging API. * * Triggered only for the subscribers of the changed user. * * Use the [Messaging.Messenger.subscribe] API to subscribe for user's changes. * * The listener is called with [Messaging.Events.OnSetStatusEvent] and a payload. * @cast Messaging.Events.StatusEventPayload */ onSetStatus = "onSetStatus", /** * Triggered if a conversation is created via [Messaging.Messenger.createConversation] or similar methods * from other Voximplant SDKs and Messaging API. * * Triggered only for participants that belong to the conversation. * * The listener is called with [Messaging.Events.OnCreateConversationEvent] and a payload. * @cast Messaging.Events.ConversationEventPayload */ onCreateConversation = "onCreateConversation", /** * Triggered if the conversation properties have been modified as the result of: * - [Messaging.Messenger.joinConversation] * - [Messaging.Messenger.leaveConversation] * - [Messaging.Conversation.addParticipants] * - [Messaging.Conversation.removeParticipants] * - [Messaging.Conversation.editParticipants] * - [Messaging.Conversation.edit] * - or similar methods from other Voximplant SDKs and Messaging API * * Triggered only for participants that belong to the conversation. * * The listener is called with [Messaging.Events.OnEditConversationEvent] and a payload. * @cast Messaging.Events.ConversationEventPayload */ onEditConversation = "onEditConversation", /** * Triggered if a conversation has been removed. * * Note that removal is possible only via the Voximplant Messaging API. * * Triggered only for participants that belong to the conversation. * * The listener is called with [Messaging.Events.OnRemoveConversationEvent] and a payload. * @cast Messaging.Events.ConversationEventPayload */ onRemoveConversation = "onRemoveConversation", /** * Triggered if a new message has been sent to a conversation via [Messaging.Conversation.sendMessage] * or similar methods from other Voximplant SDKs and Messaging API. * * Triggered only for participants that belong to the conversation. * * The listener is called with [Messaging.Events.OnSendMessageEvent] and a payload. * @cast Messaging.Events.ConversationMessageEventPayload */ onSendMessage = "onSendMessage", /** * Triggered if a message has been edited via [Messaging.Message.edit] or similar methods from other * Voximplant SDKs and Messaging API. * * Triggered only for participants that belong to the conversation with the changed message. * * The listener is called with [Messaging.Events.OnEditMessageEvent] and a payload. * @cast Messaging.Events.ConversationMessageEventPayload */ onEditMessage = "onEditMessage", /** * Triggered if a message has been removed from a conversation via [Messaging.Message.remove] or similar methods * from other Voximplant SDKs and Messaging API. * * Triggered only for participants that belong to the conversation with the deleted message. * * The listener is called with [Messaging.Events.OnRemoveMessageEvent] and a payload. * @cast Messaging.Events.ConversationMessageEventPayload */ onRemoveMessage = "onRemoveMessage", /** * Triggered for all clients in the conversation as the result of [Messaging.Conversation.markAsRead] or similar * methods from other Voximplant SDKs and Messaging API. * * The listener is called with [Messaging.Events.IsReadMessageEvent] and a payload. * @cast Messaging.Events.ConversationMessageEventPayload */ isRead = "isRead", /** * Triggered when a user is typing in a conversation. * * Typing information is received via [Messaging.Conversation.typing] or similar methods from other Voximplant SDKs * and the Messaging API. * * Event triggers only for participants in the conversation where someone is typing in conversation. * * The listener is called with [Messaging.Events.OnTypingMessageEvent] and a payload. * @cast Messaging.Events.ConversationServiceEventPayload */ onTyping = "onTyping" } /** * @internal */ export interface BaseMessengerEvent extends BaseBusEvent { name: Name; payload: Payload; } /** * @folder Events */ export interface OnEditUserEvent extends BaseMessengerEvent { } /** * @folder Events */ export interface OnSubscribeEvent extends BaseMessengerEvent { } /** * @folder Events */ export interface OnUnsubscribeEvent extends BaseMessengerEvent { } /** * @folder Events */ export interface OnSetStatusEvent extends BaseMessengerEvent { } /** * @folder Events */ export interface OnCreateConversationEvent extends BaseMessengerEvent { } /** * @folder Events */ export interface OnEditConversationEvent extends BaseMessengerEvent { } /** * @folder Events */ export interface OnRemoveConversationEvent extends BaseMessengerEvent { } /** * @folder Events */ export interface OnSendMessageEvent extends BaseMessengerEvent { } /** * @folder Events */ export interface OnEditMessageEvent extends BaseMessengerEvent { } /** * @folder Events */ export interface OnRemoveMessageEvent extends BaseMessengerEvent { } /** * @folder Events */ export interface IsReadMessageEvent extends BaseMessengerEvent { } /** * @folder Events */ export interface OnTypingMessageEvent extends BaseMessengerEvent { } /** * @folder Events */ export type AnyMessengerEvent = OnEditUserEvent | OnSubscribeEvent | OnUnsubscribeEvent | OnSetStatusEvent | OnCreateConversationEvent | OnEditConversationEvent | OnRemoveConversationEvent | OnSendMessageEvent | OnEditMessageEvent | OnRemoveMessageEvent | IsReadMessageEvent | OnTypingMessageEvent; interface ConversationParticipantPermissions { canWrite: boolean; canEditMessages: boolean; canRemoveMessages: boolean; canEditAllMessages: boolean; canRemoveAllMessages: boolean; canManageParticipants: boolean; isOwner: boolean; } /** * Represents a participant in a conversation. * * By default, all participants have the following permissions: * * - Write messages * - Edit their own messages * - Remove their own messages * * The creator of a conversation is, by default: * * - The owner ([Messaging.ConversationParticipant.isOwner] is true) * - Can edit or remove messages of other participants * - Can manage other participants */ export declare class ConversationParticipant implements ConversationParticipantPermissions { /** * The IM user's ID. */ readonly imUserId: number; /** * The sequence number of the event that has been last marked as read via [Messaging.Conversation.markAsRead]. * * Defaults to 0 if no events have been marked as read. */ readonly lastReadEventSequence: number; /** * Whether the participant can send messages to the conversation. * * This permission is granted by default. * * It can be modified only by a user with the [Messaging.ConversationParticipant.canManageParticipants] or * [Messaging.ConversationParticipant.isOwner] permissions. */ canWrite: boolean; /** * Whether the participant can edit their own messages in the conversation. * * This permission is granted by default. * * It can be modified only by a user with the [Messaging.ConversationParticipant.canManageParticipants] or * [Messaging.ConversationParticipant.isOwner] permissions. */ canEditMessages: boolean; /** * Whether the participant can remove their own messages from the conversation. * * This permission is granted by default. * * It can be modified only by a user with the [Messaging.ConversationParticipant.canManageParticipants] or * [Messaging.ConversationParticipant.isOwner] permissions. */ canRemoveMessages: boolean; /** * Whether the user can manage other participants: edit their permissions, or add/remove them from the conversation. * * It can be modified only by a user with the [Messaging.ConversationParticipant.canManageParticipants] or * [Messaging.ConversationParticipant.isOwner] permissions. */ canManageParticipants: boolean; /** * Whether the participant can edit messages posted by other users in the conversation. * * It can be modified only by a user with the [Messaging.ConversationParticipant.canManageParticipants] or * [Messaging.ConversationParticipant.isOwner] permissions. */ canEditAllMessages: boolean; /** * Whether the participant can delete messages posted by other users of the conversation. * * It can be modified only by a user with the [Messaging.ConversationParticipant.canManageParticipants] or * [Messaging.ConversationParticipant.isOwner] permissions. */ canRemoveAllMessages: boolean; /** * Whether the participant is an owner of the conversation. * * A conversation may have multiple owners. Owners can edit conversation settings and have all other permissions. */ isOwner: boolean; /** * Creates a new participant with default permissions. * * @param imId IM user's ID. Can be retrieved from [Messaging.User.imId]. */ constructor(imId: number); } /** * Configuration for new conversations created via the [Messaging.Messenger.createConversation] method. */ export interface ConversationConfig { /** * Conversation participants. * * You can update the list of participants later via the following methods: * * - [Messaging.Conversation.addParticipants] * - [Messaging.Conversation.removeParticipants] */ participants?: ConversationParticipant[]; /** * Conversation title. * * You can change it later via the [Messaging.Conversation.edit] method. */ title?: string; /** * Optional. Whether the conversation is direct. The default value is false. * * A direct conversation is a private conversation established between exactly two users. This is a E2E conversation which is not shared with other users. * Only one direct conversation can exist between the same two users. If one of the users attempts to create a new direct conversation with the same user via the [Messaging.Messenger.createConversation] method, the method returns the UUID of the existing direct conversation. * A direct conversation is always private and never is public or uber. */ isDirect?: boolean; /** * Optional. Whether the conversation is public (isDirect is false) or direct (isDirect is true). The default value is false. * * In public conversations, any user can join via the [Messaging.Messenger.joinConversation] method by specifying the UUID of the conversation they join. * Use the [Messaging.Messenger.getPublicConversations] method to retrieve a list of UUIDs for all public conversations. * * A public conversation cannot be direct. */ isPublicJoin?: boolean; /** * Optional. Whether the conversation is uber. The default value is false. * * In uber conversations, users cannot receive messages sent to the conversation after they leave. * * An uber conversation cannot be direct. */ isUber?: boolean; /** * Custom data associated with the conversation (up to 5 KB). * * You can update the custom data later via the [Messaging.Conversation.edit] method. */ customData?: UnknownObject | null; } /** * Options to configure conversation attributes updates. * @interface */ export type ConversationEditOptions = RequiredAtLeastOne<{ /** * New conversation title. */ title: string | null; /** * Whether joining the conversation is open for all users. * * A public conversation is accessible to anyone and cannot be configured as a direct E2E conversation. */ isPublicJoin: boolean | null; /** * Arbitrary custom data you want to use in the conversation such as description, etc. If you do not need it, set it to `null`. */ customData: UnknownObject | null; }>; /** * @interface * * Options to set message content in the conversation. * * Either `text` or `payload` (or both) should be specified. */ export type ConversationSendMessageOptions = RequiredAtLeastOne<{ /** * Optional. Message text, maximum 5000 characters. Always configure if you do not specify `payload`. */ text: string; /** * Optional. Message payload. Always configure if you do not specify `text`. */ payload: UnknownObject[]; }>; /** * Provides API to manage a conversation. */ export interface Conversation { /** * Universally unique identifier (UUID) of this conversation. */ uuid: UUID; /** * UNIX timestamp (seconds) that specifies the creation time of the conversation. */ createdTime: number; /** * UNIX timestamp (seconds) indicating the last time when either of the following events has been triggered in the conversation: * - [Messaging.Events.MessengerEventType.onCreateConversation] * - [Messaging.Events.MessengerEventType.onEditConversation] * - [Messaging.Events.MessengerEventType.onEditMessage] * - [Messaging.Events.MessengerEventType.onRemoveConversation] * - [Messaging.Events.MessengerEventType.onRemoveMessage] * - [Messaging.Events.MessengerEventType.onSendMessage] */ lastUpdateTime: number; /** * Sequence of the last event in the conversation. */ lastSequence: number; /** * The conversation title. */ title: string; /** * Array of conversation participants, including their permissions. */ participants: ConversationParticipant[]; /** * Whether the conversation is direct or public. * * A direct conversation is a private conversation established between exactly two users. This conversation is not shared with other users. * Only one direct conversation can exist between the same two users. If one of the users attempts to create a new direct conversation with the same user ([Messaging.Messenger.createConversation]), the method returns the UUID of the existing direct conversation. * A direct conversation is always private and never is public or uber. */ isDirect: boolean; /** * Whether the conversation is public. * * In public conversations, any user can join the conversation by specifying the UUID of the conversation they join. * * A public conversation cannot be direct. */ isPublicJoin: boolean; /** * Whether the conversation is uber. * * In uber conversations, users cannot receive messages sent to the conversation after they leave. * * An uber conversation cannot be direct. */ isUber: boolean; /** * Custom data associated with the conversation (up to 5 KB). */ customData: UnknownObject | null; /** * Sends changes made to the conversation to the cloud. Supported changes are: title, public join flag, and custom data. * * The participant has to be the conversation owner for the update to succeed ([Messaging.ConversationParticipant.isOwner] is true). * * You can use the [Messaging.Events.MessengerEventType.onEditConversation] event to notify the participants (online or logged-in) that conversation title, custom data, or public join status have changed. * * Returns a promise that resolves to a [Messaging.Events.ConversationEventPayload] object containing the updated conversation data. * * @throws [Messaging.Errors.MessengerError] * * @param options Conversation changes */ edit: (options: ConversationEditOptions) => Promise; /** * Adds new participants to the conversation. * * This operation is allowed only if: * * - All participants act as users who use the Voximplant developer account or its child accounts * - The current user has permission to manage participants ([Messaging.ConversationParticipant.canManageParticipants] is true) * - The conversation is either public or uber ([Messaging.Conversation.isDirect] is false) * * Duplicate users are ignored. Throws [Messaging.Errors.MessengerError] if any specified user does not exist or is already a participant of the conversation. * * You can use the [Messaging.Events.MessengerEventType.onEditConversation] event to notify the participants (online or logged-in) that a new participant has been added to the conversation. * * Returns a promise that resolves to a [Messaging.Events.ConversationEventPayload] object containing the updated data. * * @throws [Messaging.Errors.MessengerError] * * @param participants Array of participants to add. Should not be empty */ addParticipants: (participants: ConversationParticipant[]) => Promise; /** * Removes participants from the conversation. * * This operation is allowed only if: * * - The current user has permission to manage participants ([Messaging.ConversationParticipant.canManageParticipants] is true) * - The conversation is either public or uber ([Messaging.Conversation.isDirect] is false) * * Duplicate participants are ignored. * * Throws [Messaging.Errors.MessengerError] if any specified user does not exist or is not a participant. * * Note: You can also remove participants that are marked as deleted ([Messaging.User.isDeleted] is true). * * Removed users can later retrieve the UUID of this conversation's via the [Messaging.User.leaveConversationList] method. * * You can use the [Messaging.Events.MessengerEventType.onEditConversation] event to notify the participants (online participants or logged in user clients) that a participant has been removed from the conversation. * * Returns a promise that resolves to a [Messaging.Events.ConversationEventPayload] object containing the updated data. * * @throws [Messaging.Errors.MessengerError] * * @param participants Array of participants to remove. Should not be empty */ removeParticipants: (participants: ConversationParticipant[]) => Promise; /** * Edits the permissions of participants in the conversation. * * This operation is allowed only if the current user has permission to manage participants ([Messaging.ConversationParticipant.canManageParticipants] is true). * * Duplicate participants are ignored. * Throws [Messaging.Errors.MessengerError] if any specified user does not exist or is not a participant. * * You can use the [Messaging.Events.MessengerEventType.onEditConversation] event to notify the participants (online participants or logged in user clients) of permission changes in the conversation. * * Returns a promise that resolves to a [Messaging.Events.ConversationEventPayload] object containing the updated data. * * @throws [Messaging.Errors.MessengerError] * * @param participants Array of participants whose permissions to update. Should not be empty */ editParticipants: (participants: ConversationParticipant[]) => Promise; /** * Sends a message to the conversation. * * This operation is allowed only if participants have write permission ([Messaging.ConversationParticipant.canWrite] is true). * * You can use the [Messaging.Events.MessengerEventType.onSendMessage] event to notify the participants (online participants or logged in user clients) of new messages sent to the conversation. * * Returns a promise whose fulfillment handler receives [Messaging.Events.ConversationMessageEventPayload] object with the updated data. * * @throws [Messaging.Errors.MessengerError] * * @param options Message content */ sendMessage: (options: ConversationSendMessageOptions) => Promise; /** * Marks the event with the specified sequence as read. * * Calling this method with a sequence number updates [Messaging.ConversationParticipant.lastReadEventSequence] to that value, * allowing each participant to track their own read state of messages by retrieving event sequences independently. * * If the sequence number is -1 or 0, all events are marked as unread for this participant, except the event with sequence number 1. * * You can use the [Messaging.Events.MessengerEventType.isRead] event to notify the participants (online participants or logged in user clients) of the read status change for the messages in the conversation. * * Returns a promise that resolves to a [Messaging.Events.ConversationServiceEventPayload] object containing the updated data. * * @throws [Messaging.Errors.MessengerError] * * @param sequence The sequence number of the event to mark as read. Should not exceed the current maximum sequence */ markAsRead: (sequence: number) => Promise; /** * Informs the cloud that the user is typing a message. * * You can use the [Messaging.Events.MessengerEventType.onTyping] event to notify the participants (online participants or logged in user clients) of typing activity in the conversation. * * Returns a promise that resolves to a [Messaging.Events.ConversationServiceEventPayload] object containing the updated data, or `null` if no update is needed. * * @throws [Messaging.Errors.MessengerError] */ typing: () => Promise; /** * Requests a range of events to be retransmitted from the cloud to this client. * * See [Messaging.Events.RetransmittableEvents] type for the events that can be retransmitted. * * This method is used to retrieve message history or obtain missed events after a network failure. * Use the last event sequence received from the cloud and the last sequence saved locally (if any) to set the appropriate event range. * * The maximum number of events per request is 100. Requesting more than 100 events throws [Messaging.Errors.MessengerError]. * * If the current user has left an uber conversation ([Messaging.Conversation.isUber] is true), messages sent in the conversation after their leave and before they re-join are not retransmitted. * * Returns a promise that resolves to a [Messaging.Events.RetransmitEventPayload] object containing the requested events. * * @throws [Messaging.Errors.MessengerError] * * @param eventsFrom The first event in the in the range (inclusive) * @param eventsTo The last event in the range (inclusive) */ retransmitEvents: (eventsFrom: number, eventsTo: number) => Promise; /** * Requests a specified number of events starting from a given sequence to be retransmitted from the cloud to this client. * * See [Messaging.Events.RetransmittableEvents] type for the events that can be retransmitted. * * This method is used to retrieve message history or obtain missed events after a network failure. * Use the last event sequence received from the cloud and the last sequence saved locally (if any) to set the first event in the range. * * The maximum number of events per request is 100. * Requesting more than 100 events throws [Messaging.Errors.MessengerError]. * * If the current user has left an uber conversation ([Messaging.Conversation.isUber] is true), messages sent in the conversation after their leave or before they re-join are not retransmitted. * * The result includes the maximum number of available events for the current user up to the requested count, even if fewer events are available. * * Returns a promise that resolves to a [Messaging.Events.RetransmitEventPayload] object containing the requested events. * * @throws [Messaging.Errors.MessengerError] * * @param eventsFrom The first event in the range (inclusive) * @param count The maximum number of events to retrieve (up to 100) */ retransmitEventsFrom: (eventsFrom: number, count: number) => Promise; /** * Requests up to a specified number of events ending at a given number to be retransmitted from the cloud to this client. * * See [Messaging.Events.RetransmittableEvents] type for the events that can be retransmitted. * * See [Messaging.Events.RetransmittableEvents] type for the complete list of events that can be retransmitted. * * This method is used to retrieve message history or obtain missed events after a network failure. * For the clients, use this method to obtain all events based on the last event sequence received from the cloud and the last sequence saved locally (if any). * * The maximum number of retransmitted events per method call is 100. * Requesting more than 100 events causes [Messaging.Errors.MessengerError]. * * If the current user has left an uber conversation ([Messaging.Conversation.isUber] is true), messages sent in the conversation after their leave or before they rejoin are not retransmitted. * The result includes the maximum number of available events up to the requested count, even if fewer events are available. * * Returns a promise that resolves to a [Messaging.Events.RetransmitEventPayload] object containing the requested events. * * @throws [Messaging.Errors.MessengerError] * * @param eventsTo The last event sequence in the range (inclusive) * @param count The maximum number of events to retrieve (up to 100) */ retransmitEventsTo: (eventsTo: number, count: number) => Promise; } /** * @folder Errors */ export declare enum MessengerErrorCode { Unknown = 0, WrongMessageStructure = 1, UnknownEventName = 2, NotAuthorized = 3, ConversationNotExists = 8, MessageNotExists = 10, MessageDeleted = 11, ACLError = 12, UserAlreadyInParticipants = 13, PublicJoinNotAvailable = 15, ConversationDeleted = 16, UserValidationError = 18, UserNotInParticipants = 19, RequestedObjectsCountInvalid = 21, RequestedObjectsExceedLimit = 22, MessageSizeExceedsLimit = 23, SeqTooBig = 24, UserNotFound = 25, NotificationEventIncorrect = 26, FromGreaterThanTo = 28, ServiceUnavailable = 30, MessagesPerSecondLimit = 32, MessagesPerMinuteLimit = 33, DirectConversationNotPublic = 34, DirectConversationTwoUsersOnly = 35, InvalidEventParameters = 36, DirectConversationAddParticipantNotAllowed = 37, DirectConversationRemoveParticipantNotAllowed = 38, DirectConversationJoinNotAllowed = 39, DirectConversationLeaveNotAllowed = 40, InsufficientEventParameters = 41, Internal = 500, MethodCallsInterval = 10000, InvalidArguments = 10001, ResponseTimeout = 10002, NotLoggedIn = 10003, FailedToProcessResponse = 10004 } /** * @folder Errors * @hideconstructor */ export declare class MessengerError extends WebSDKError { code: MessengerErrorCode; reason?: string; constructor(code: MessengerErrorCode, reason?: string); } /** * @hidden */ export declare class MessengerInternalError extends MessengerError { constructor(reason?: string); } /** * @hidden */ export declare class MessengerNotLoggedInError extends MessengerError { constructor(); } /** * @hidden */ export declare class MessengerResponseTimeoutError extends MessengerError { constructor(); } /** * @hidden */ export declare class MessengerInvalidArgumentsError extends MessengerError { constructor(reason?: string); } /** * @hidden */ export declare class MessengerResponseProcessError extends MessengerError { constructor(reason?: string); } /** * @hidden */ export declare class MessengerFromGreaterThanToError extends MessengerError { constructor(); } /** * User data available for editing. */ export interface EditUserOptions { /** * New custom data. * * If `null`, previously set custom data is left untouched. * * If an empty object, previously set custom data is removed. */ customData?: UnknownObject | null; /** * New private custom data. * * If `null`, previously set private custom data is untouched. * * If an empty object, previously set private custom data is removed. */ privateCustomData?: UnknownObject | null; } /** * @interface * @internal */ export type DocMessengerAddEventListener = (eventName: (typeof MessengerEventType)[keyof typeof MessengerEventType], listener: (event: AnyMessengerEvent) => void | Promise, options: ListenerOptions) => void; /** * @interface * @internal */ export type DocMessengerRemoveEventListener = (eventName: (typeof MessengerEventType)[keyof typeof MessengerEventType], listener: (event: AnyMessengerEvent) => void | Promise) => void; /** * Interface that provides API to control messaging functions. */ export interface Messenger { /** * @reinterpret Messaging.DocMessengerAddEventListener */ addEventListener: AddEventListener; /** * @reinterpret Messaging.DocMessengerRemoveEventListener */ removeEventListener: RemoveEventListener; /** * Gets the Voximplant user identifier for the current user, e.g., 'username@appname.accname'. * * Returns `null` if the user is not logged in. */ getMe: () => string | null; /** * Obtains information about the user specified by the Voximplant username, e.g., 'username@appname.accname'. * * You can request any user linked to the main Voximplant developer account or its child accounts. * * Returns a promise that resolves to a [Messaging.Events.UserEventPayload] object if the operation succeeds. * * @throws [Messaging.Errors.MessengerError] * * @param userName Voximplant user identifier */ getUser: (userName: string) => Promise; /** * Obtains information about the users specified by the list of Voximplant user names. Maximum of 50 users. * * You can request users linked to the main Voximplant developer account or its child accounts. * * Returns a promise that resolves to an array of [Messaging.Events.UserEventPayload] objects if the operation succeeds. The array contains one object per requested user name. * * @throws [Messaging.Errors.MessengerError] * * @param userNames Array of Voximplant user identifiers, e.g., 'username@appname.accname' */ getUsers: (userNames: string[]) => Promise; /** * Obtains information about the user specified by the IM user ID. * * You can request any user linked to the main Voximplant developer account or its child accounts. * * Returns a promise that resolves to a [Messaging.Events.UserEventPayload] object if the operation succeeds. * * @throws [Messaging.Errors.MessengerError] * * @param imId IM user ID */ getUserByImId: (imId: number) => Promise; /** * Obtains information about the users specified by the list of IM user IDs. Maximum of 50 users. * * You can request users linked to the main Voximplant developer account or its child accounts. * * Returns a promise that resolves to an array of [Messaging.Events.UserEventPayload] objects if the operation succeeds. The array contains one object per requested user ID. * * @throws [Messaging.Errors.MessengerError] * * @param imIds Array of IM user IDs */ getUsersByImIds: (imIds: number[]) => Promise; /** * Edits the current user information. * * You can use the [Messaging.Events.MessengerEventType.onEditUser] event to notify the users subscribed to the current user that user information has been updated. * * Returns a promise that resolves to a [Messaging.Events.UserEventPayload] object containing the updated data. * * @throws [Messaging.Errors.MessengerError] * * @param options User data available for editing */ editUser: (options: EditUserOptions) => Promise; /** * Subscribes to information and status changes of the specified users. * * You can subscribe the user to any user linked to the main Voximplant developer account or its child accounts. * * Other logged-in clients of the current user can be informed about the subscription via the [Messaging.Events.MessengerEventType.onSubscribe] event. * * You can use the [Messaging.Events.MessengerEventType.onSubscribe] event to notify other logged-in clients of the current user of the subscription. * The users specified in the `imIds` parameter are not notified of the subscription. * * Returns a promise that resolves to a [Messaging.Events.SubscriptionEventPayload] object. * * @throws [Messaging.Errors.MessengerError] * * @param imIds Array of IM user IDs */ subscribe: (imIds: User["imId"][]) => Promise; /** * Cancels subscription to information and status changes of the specified users. * * You can use the [Messaging.Events.MessengerEventType.onUnsubscribe] event to notify other logged-in clients of the current user that their subscription has been cancelled. * * The users specified in the `imIds` parameter are not notified of the subscription cancellation. * * Returns a promise that resolves to a [Messaging.Events.SubscriptionEventPayload] object. * * @throws [Messaging.Errors.MessengerError] * * @param imIds Array of IM user IDs */ unsubscribe: (imIds: User["imId"][]) => Promise; /** * Cancels all subscriptions to information and status changes. * * You can use the [Messaging.Events.MessengerEventType.onUnsubscribe] event to notify other logged-in clients of the current user that their subscription has been cancelled. * * Other users are not notified of the subscription cancellation. * * Returns a promise that resolves to a [Messaging.Events.SubscriptionEventPayload] object. * * @throws [Messaging.Errors.MessengerError] */ unsubscribeFromAll: () => Promise; /** * Obtains all current subscriptions and returns a list of users to which the current user is subscribed. * * Returns a promise that resolves to a [Messaging.Events.SubscriptionEventPayload] object. * * @throws [Messaging.Errors.MessengerError] */ getSubscriptionList: () => Promise; /** * Sets the current user status. * * You can use the [Messaging.Events.MessengerEventType.onSetStatus] event to notify clients and users subscribed to the current user of the status change for that user. * * Returns a promise that resolves to a [Messaging.Events.StatusEventPayload] object. * * @throws [Messaging.Errors.MessengerError] * * @param online Indicates whether the user is online and available for messaging */ setStatus: (online: boolean) => Promise; /** * Creates a new conversation with extended configuration. * * Other participants in the conversation (online participants and logged-in clients) can be informed about the creation via the [Messaging.Events.MessengerEventType.onCreateConversation] event. * You can use the [Messaging.Events.MessengerEventType.onCreateConversation] event to notify online participants and logged-in clients of the status change for that user. * * Returns a promise that resolves to a [Messaging.Events.ConversationEventPayload] object. * * @throws [Messaging.Errors.MessengerError] * * @param conversationConfig Conversation configuration */ createConversation: (conversationConfig?: ConversationConfig) => Promise; /** * Joins the current user to a conversation specified by its UUID. * * This operation is possible only if: * * - The conversation has been created by a user of the main Voximplant developer account or its child accounts. * - Public join is enabled ([Messaging.Conversation.isPublicJoin] is true). * - The conversation is not a direct conversation ([Messaging.Conversation.isDirect] is false). * * Other participants in the conversation (online participants and logged-in clients) can be informed about the join via the [Messaging.Events.MessengerEventType.onEditConversation] event. * * Returns a promise that resolves to a [Messaging.Events.ConversationEventPayload] object. * * @throws [Messaging.Errors.MessengerError] * * @param uuid Conversation UUID */ joinConversation: (uuid: UUID) => Promise; /** * Makes the current user leave a conversation specified by its UUID. * * This operation is possible only if the conversation is not a direct conversation ([Messaging.Conversation.isDirect] is false). * * After a successful call, the conversation's UUID is added to [Messaging.User.leaveConversationList]. * * Returns a promise that resolves to a [Messaging.Events.ConversationEventPayload] object. * * @throws [Messaging.Errors.MessengerError] * * @param uuid Conversation UUID */ leaveConversation: (uuid: UUID) => Promise; /** * Gets a conversation by its UUID. * * This operation is possible if: * * - The user calling the method is or has been a participant in the conversation. * - The conversation is an available public conversation (see [Messaging.Messenger.getPublicConversations]). * * Returns a promise that resolves to a [Messaging.Events.ConversationEventPayload] object. * * @throws [Messaging.Errors.MessengerError] * * @param uuid Conversation UUID */ getConversation: (uuid: UUID) => Promise; /** * Gets multiple conversations by a list of UUIDs. Maximum 30 conversations. * * This operation is possible if: * * - The user calling the method is or has been a participant in each of the conversations. * - Each conversation is an available public conversation (see [Messaging.Messenger.getPublicConversations]). * * Returns a promise that resolves to an array of [Messaging.Events.ConversationEventPayload] objects. * * @throws [Messaging.Errors.MessengerError] * * @param uuids Array of conversation UUIDs. Maximum 30 conversations. */ getConversations: (uuids: UUID[]) => Promise; /** * Gets all public conversations ([Messaging.Conversation.isPublicJoin] is true). * * This operation returns all public conversation UUIDs created by: * * - The current user. * - Other users of the same [child account](/docs/references/httpapi/accounts#addaccount). * - Users of the main Voximplant developer account. * * Returns a promise that resolves to a [Messaging.Events.ConversationListEventPayload] object. * * @throws [Messaging.Errors.MessengerError] */ getPublicConversations: () => Promise; } declare class MessengerImpl implements Messenger { private readonly login?; private readonly logger?; private readonly signallingProxy; private readonly conversationManger; readonly addEventListener: AddEventListener; readonly removeEventListener: RemoveEventListener; private readonly dispatchEvent; constructor(container: Container); getMe(): string | null; getUserByImId(imId: number): Promise; getUser(userName: string): Promise; getUsersByImIds(imIds: number[]): Promise; getUsers(userNames: string[]): Promise; editUser(options: EditUserOptions): Promise; subscribe(imIds: number[]): Promise; unsubscribe(imIds: number[]): Promise; unsubscribeFromAll(): Promise; getSubscriptionList(): Promise; setStatus(online: boolean): Promise; createConversation(conversationConfig?: ConversationConfig): Promise; joinConversation(uuid: UUID): Promise; leaveConversation(uuid: UUID): Promise; getConversation(uuid: UUID): Promise; getConversations(uuids: UUID[]): Promise; getPublicConversations(): Promise; private dispatchAwaitedMessengerEvent; private dispatchUnawaitedSignallingMessengerEvent; } /** * Entry point to the messaging module. */ export interface Messaging extends BaseModule { /** * Messenger instance exposing messaging functionality. */ messenger: Messenger; } /** * @function */ export declare const MessagingLoader: ModuleFactory; /** * @hidden */ export declare class MessagingImpl extends BaseModuleImpl implements Messaging { readonly messenger: MessengerImpl; } export declare const messagingToken: Token; export {};