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-1712730991884689408").

    • Optionalcursor: string

      The cursor for pagination. Is equal to the ID of the last message from previous batch.

    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-1712730991884689408')
    .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<T>

    The raw data response received.

    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);
    });