Notifications API (Draft WIP) - lolmaxz/vrc-ts GitHub Wiki

Notifications API Documentation

The Notifications API allows you to interact with notifications within VRChat. This includes retrieving your notifications, accepting friend requests, marking notifications as read, deleting notifications, clearing all notifications, and responding to specific notifications.


Index

  1. listNotifications - Retrieve your notifications.
  2. acceptFriendRequest - Accept a friend request.
  3. markNotificationAsRead - Mark a notification as read.
  4. deleteNotification - Delete a notification.
  5. clearAllNotifications - Clear all notifications.
  6. respondToNotification - Respond to a notification.

Endpoints

1. listNotifications

Retrieve your notifications.

Purpose

Retrieve a list of your current notifications, with options to filter by type, control pagination, and include hidden notifications.

Method Signature

listNotifications(options: {
  type: 'all' | NotificationType;
  n?: number;
  after?: string;
  offset?: number;
  hidden?: boolean;
}): Promise<Notification[]>

Parameters

  • options (object):

    • type (string, required):
      The type of notifications to retrieve. Options include 'all' or specific notification types like 'friendRequest', 'invite', etc.

    • n (number, optional):
      The number of notifications to retrieve. Must be between 1 and 100.

    • after (string, optional):
      A timestamp or special keyword like 'five_minutes_ago' to retrieve notifications after that time.

    • offset (number, optional):
      The number of records to offset from the start. Must be 0 or greater.

    • hidden (boolean, optional):
      If true, includes hidden notifications in the results.

Returns

  • Promise<Notification[]>: A promise that resolves to an array of notification objects.

Example Usage

// Example: Retrieve all notifications
const notifications = await vrchatApi.notificationsApi.listNotifications({
  type: 'all',
  n: 50,
});
console.log(notifications);

// Example: Retrieve friend request notifications
const friendRequests = await vrchatApi.notificationsApi.listNotifications({
  type: 'friendRequest',
  n: 10,
});
console.log(friendRequests);

2. acceptFriendRequest

Accept a friend request.

Purpose

Accept a friend request by providing the notification ID of the friend request. Friend request notifications can be found using listNotifications filtered by type 'friendRequest'.

Method Signature

acceptFriendRequest(options: {
  notificationId: string;
}): Promise<RequestSuccess>

Parameters

  • options (object):

    • notificationId (string, required):
      The ID of the friend request notification to accept.

Returns

  • Promise<RequestSuccess>: A promise that resolves to an object indicating the operation was successful.

Example Usage

// Example: Accept a friend request
const response = await vrchatApi.notificationsApi.acceptFriendRequest({
  notificationId: 'notif_abcdef12-3456-7890-abcd-ef1234567890',
});
console.log(response); // { success: true }

3. markNotificationAsRead

Mark a notification as read.

Purpose

Mark a specific notification as read by its notification ID.

Method Signature

markNotificationAsRead(options: {
  notificationId: string;
}): Promise<Notification>

Parameters

  • options (object):

    • notificationId (string, required):
      The ID of the notification to mark as read.

Returns

  • Promise<Notification>: A promise that resolves to the updated notification object.

Example Usage

// Example: Mark a notification as read
const updatedNotification = await vrchatApi.notificationsApi.markNotificationAsRead({
  notificationId: 'notif_abcdef12-3456-7890-abcd-ef1234567890',
});
console.log(updatedNotification);

4. deleteNotification

Delete a notification.

Purpose

Delete a specific notification by its notification ID.

Method Signature

deleteNotification(options: {
  notificationId: string;
}): Promise<Notification>

Parameters

  • options (object):

    • notificationId (string, required):
      The ID of the notification to delete.

Returns

  • Promise<Notification>: A promise that resolves to the deleted notification object.

Example Usage

// Example: Delete a notification
const deletedNotification = await vrchatApi.notificationsApi.deleteNotification({
  notificationId: 'notif_abcdef12-3456-7890-abcd-ef1234567890',
});
console.log(deletedNotification);

5. clearAllNotifications

Clear all notifications.

Purpose

Delete all notifications from your account.

Method Signature

clearAllNotifications(): Promise<RequestSuccess>

Parameters

  • No parameters

Returns

  • Promise<RequestSuccess>: A promise that resolves to an object indicating the operation was successful.

Example Usage

// Example: Clear all notifications
const response = await vrchatApi.notificationsApi.clearAllNotifications();
console.log(response); // { success: true }

6. respondToNotification

Respond to a notification.

Purpose

Respond to a specific notification, such as group invitations or other actionable notifications. The response can include additional data like a group ID or user ID.

Method Signature

respondToNotification(options: {
  notificationId: string;
  responseType: 'Accept' | 'Reject' | 'Block';
  groupId?: string;
  userId?: string;
}): Promise<string>

Parameters

  • options (object):

    • notificationId (string, required):
      The ID of the notification to respond to.

    • responseType (string, required):
      The type of response. Valid values are 'Accept', 'Reject', or 'Block'.

    • groupId (string, optional):
      The group ID associated with the response, if applicable.

    • userId (string, optional):
      The user ID associated with the response, if applicable.

Returns

  • Promise<string>: A promise that resolves to a message indicating the result of the response.

Example Usage

// Example: Accept a group invitation notification
const responseMessage = await vrchatApi.notificationsApi.respondToNotification({
  notificationId: 'notif_abcdef12-3456-7890-abcd-ef1234567890',
  responseType: 'Accept',
  groupId: 'grp_abcdef12-3456-7890-abcd-ef1234567890',
});
console.log(responseMessage);

// Example: Reject a notification
const rejectResponse = await vrchatApi.notificationsApi.respondToNotification({
  notificationId: 'notif_abcdef12-3456-7890-abcd-ef1234567890',
  responseType: 'Reject',
});
console.log(rejectResponse);

Additional Types and Enums

NotificationType Enum

enum NotificationType {
  FriendRequest = 'friendRequest',
  Invite = 'invite',
  InviteResponse = 'inviteResponse',
  RequestInvite = 'requestInvite',
  Message = 'message',
  RequestInviteResponse = 'requestInviteResponse',
  Votekick = 'votetokick',
}

Notification Object Structure

type Notification = {
  id: string; // NotificationIdType
  senderUserId: string; // UserIdType
  senderUsername?: string; // Deprecated
  type: NotificationType;
  message: string;
  details: string; // Additional details, may require parsing
  receiverUserId?: string; // UserIdType
  seen?: boolean;
  created_at: string;
};

RequestSuccess Type

type RequestSuccess = {
  success: boolean;
};

Endpoints:

  1. listNotifications - Retrieve your notifications.
  2. acceptFriendRequest - Accept a friend request.
  3. markNotificationAsRead - Mark a notification as read.
  4. deleteNotification - Delete a notification.
  5. clearAllNotifications - Clear all notifications.
  6. respondToNotification - Respond to a notification.

⚠️ **GitHub.com Fallback** ⚠️