Class DirectMessageService

Handles interacting with resources related to direct messages

Hierarchy (View Summary)

Constructors

Properties

config: RettiwtConfig

The config object.

Methods

  • Get the full conversation history for a specific conversation, ordered recent to oldest. Use this to load complete message history for a conversation identified from the inbox.

    Parameters

    • conversationId: string

      The ID of the conversation (e.g., "394028042:1645287614").

    • OptionalcursorOrOptions: string | IDMConversationOptions

      Either the oldest event ID from the previous page or decoding options for this call.

    • Optionaloptions: IDMConversationOptions

      Decoding options when a pagination cursor is supplied as the second argument.

    Returns Promise<undefined | Conversation>

    The conversation with full message history, or undefined if not found.

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Fetching a specific conversation
    rettiwt.dm.conversation('394028042:1645287614')
    .then(conversation => {
    if (conversation) {
    console.log(`Conversation with ${conversation.participants.length} participants`);
    console.log(`${conversation.messages.length} messages loaded`);
    }
    })
    .catch(err => {
    console.log(err);
    });
  • Delete a conversation. You will leave the conversation and it will be removed from your inbox.

    Parameters

    • conversationId: string

      The ID of the conversation to delete.

    Returns Promise<void>

    A promise that resolves when the conversation is deleted.

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });
    // Deleting a conversation
    rettiwt.dm.deleteConversation('394028042-1712730991884689408')
    .then(() => {
    console.log('Conversation deleted successfully');
    })
    .catch(err => {
    console.log('Failed to delete conversation:', err);
    });
  • Get your inbox, ordered recent to oldest.

    Parameters

    • Optionalcursor: string

      The cursor to the inbox items to fetch. Is equal to the ID of the last inbox conversation.

    Returns Promise<Inbox>

    The required inbox. Returns initial inbox if no cursor is provided.

    import { Rettiwt } from 'rettiwt-api';

    // Creating a new Rettiwt instance using the given 'API_KEY'
    const rettiwt = new Rettiwt({ apiKey: API_KEY });

    // Fetching the initial DM inbox state
    rettiwt.dm.inbox()
    .then(inbox => {
    console.log(`Found ${inbox.conversations.length} conversations`);
    console.log('First conversation:', inbox.conversations[0]);
    })
    .catch(err => {
    console.log(err);
    });
  • Makes an HTTP request according to the given parameters.

    Type Parameters

    • T = unknown

      The type of the returned response data.

    Parameters

    Returns Promise<AxiosResponse<T, any, {}, any>>

    The raw Axios response.

    import { FetcherService, ResourceType } from 'rettiwt-api';

    // Creating a new FetcherService instance using the given 'API_KEY'
    const fetcher = new FetcherService({ apiKey: API_KEY });

    // Fetching the details of the User with username 'user1'
    fetcher.request(ResourceType.USER_DETAILS_BY_USERNAME, { id: 'user1' })
    .then(res => {
    console.log(res);
    })
    .catch(err => {
    console.log(err);
    });
  • Recover this account's XChat identity with its existing chat PIN.

    Parameters

    • pin: string | Uint8Array<ArrayBufferLike>

      The account's existing XChat PIN as text or UTF-8 bytes.

    Returns Promise<void>

    Requires the optional @xdevplatform/chat-xdk and juicebox-sdk packages. The PIN is passed to the official SDK and is not retained by Rettiwt.

    If authentication is unavailable, recovery metadata is missing, the optional SDK is not installed, or the PIN cannot unlock the account's key backup.