Skip to content

Interface: DirectApi ​

Direct messages: the inbox, a thread's messages, and sending.

Methods ​

addUsers() ​

ts
addUsers(threadId, userIds): Promise<void>;

Adds people to a group thread.

Parameters ​

ParameterType
threadIdstring
userIdsreadonly string[]

Returns ​

Promise<void>


approve() ​

ts
approve(threadId): Promise<void>;

Accepts a message request, moving it to the inbox.

Parameters ​

ParameterType
threadIdstring

Returns ​

Promise<void>


createGroup() ​

ts
createGroup(userIds, title?): Promise<string>;

Creates a group thread and returns its id.

Parameters ​

ParameterType
userIdsreadonly string[]
title?string

Returns ​

Promise<string>


deleteMessage() ​

ts
deleteMessage(threadId, itemId): Promise<void>;

Deletes one of the account's own messages for everyone in the thread.

Parameters ​

ParameterType
threadIdstring
itemIdstring

Returns ​

Promise<void>


findThread() ​

ts
findThread(userIds): Promise<
  | {
[key: string]: unknown;
  is_group?: boolean;
  items?: object[];
  last_activity_at?: string;
  last_permanent_item?: {
   [key: string]: unknown;
     item_id?: string;
     item_type?: string;
     text?: string;
     timestamp?: string;
     user_id?: string;
  };
  thread_id?: string;
  thread_title?: string;
  users?: object[];
}
| undefined>;

The existing thread with exactly these people, if there is one.

Parameters ​

ParameterType
userIdsreadonly string[]

Returns ​

Promise< | { [key: string]: unknown; is_group?: boolean; items?: object[]; last_activity_at?: string; last_permanent_item?: { [key: string]: unknown; item_id?: string; item_type?: string; text?: string; timestamp?: string; user_id?: string; }; thread_id?: string; thread_title?: string; users?: object[]; } | undefined>


hide() ​

ts
hide(threadId, options?): Promise<void>;

Declines a message request.

Parameters ​

ParameterType
threadIdstring
options?HideThreadOptions

Returns ​

Promise<void>


inbox() ​

ts
inbox(options?): Promise<Page<{
[key: string]: unknown;
  is_group?: boolean;
  items?: object[];
  last_activity_at?: string;
  last_permanent_item?: {
   [key: string]: unknown;
     item_id?: string;
     item_type?: string;
     text?: string;
     timestamp?: string;
     user_id?: string;
  };
  thread_id?: string;
  thread_title?: string;
  users?: object[];
}>>;

One page of the inbox threads.

Parameters ​

ParameterType
options?CursorOptions

Returns ​

Promise<Page<{ [key: string]: unknown; is_group?: boolean; items?: object[]; last_activity_at?: string; last_permanent_item?: { [key: string]: unknown; item_id?: string; item_type?: string; text?: string; timestamp?: string; user_id?: string; }; thread_id?: string; thread_title?: string; users?: object[]; }>>


markSeen() ​

ts
markSeen(threadId, itemId): Promise<void>;

Marks a thread as seen up to a message.

Parameters ​

ParameterType
threadIdstring
itemIdstring

Returns ​

Promise<void>


mute() ​

ts
mute(threadId): Promise<void>;

Mutes the notifications of a thread.

Parameters ​

ParameterType
threadIdstring

Returns ​

Promise<void>


paginateInbox() ​

ts
paginateInbox(): AsyncGenerator<{
[key: string]: unknown;
  is_group?: boolean;
  items?: object[];
  last_activity_at?: string;
  last_permanent_item?: {
   [key: string]: unknown;
     item_id?: string;
     item_type?: string;
     text?: string;
     timestamp?: string;
     user_id?: string;
  };
  thread_id?: string;
  thread_title?: string;
  users?: object[];
}>;

Walks the inbox threads, one at a time across pages.

Returns ​

AsyncGenerator<{ [key: string]: unknown; is_group?: boolean; items?: object[]; last_activity_at?: string; last_permanent_item?: { [key: string]: unknown; item_id?: string; item_type?: string; text?: string; timestamp?: string; user_id?: string; }; thread_id?: string; thread_title?: string; users?: object[]; }>


paginatePending() ​

ts
paginatePending(): AsyncGenerator<{
[key: string]: unknown;
  is_group?: boolean;
  items?: object[];
  last_activity_at?: string;
  last_permanent_item?: {
   [key: string]: unknown;
     item_id?: string;
     item_type?: string;
     text?: string;
     timestamp?: string;
     user_id?: string;
  };
  thread_id?: string;
  thread_title?: string;
  users?: object[];
}>;

Walks the message requests.

Returns ​

AsyncGenerator<{ [key: string]: unknown; is_group?: boolean; items?: object[]; last_activity_at?: string; last_permanent_item?: { [key: string]: unknown; item_id?: string; item_type?: string; text?: string; timestamp?: string; user_id?: string; }; thread_id?: string; thread_title?: string; users?: object[]; }>


paginateSpam() ​

ts
paginateSpam(): AsyncGenerator<{
[key: string]: unknown;
  is_group?: boolean;
  items?: object[];
  last_activity_at?: string;
  last_permanent_item?: {
   [key: string]: unknown;
     item_id?: string;
     item_type?: string;
     text?: string;
     timestamp?: string;
     user_id?: string;
  };
  thread_id?: string;
  thread_title?: string;
  users?: object[];
}>;

Walks the hidden requests.

Returns ​

AsyncGenerator<{ [key: string]: unknown; is_group?: boolean; items?: object[]; last_activity_at?: string; last_permanent_item?: { [key: string]: unknown; item_id?: string; item_type?: string; text?: string; timestamp?: string; user_id?: string; }; thread_id?: string; thread_title?: string; users?: object[]; }>


paginateThread() ​

ts
paginateThread(threadId): AsyncGenerator<{
[key: string]: unknown;
  item_id?: string;
  item_type?: string;
  text?: string;
  timestamp?: string;
  user_id?: string;
}>;

Walks a thread's messages, newest first.

Parameters ​

ParameterType
threadIdstring

Returns ​

AsyncGenerator<{ [key: string]: unknown; item_id?: string; item_type?: string; text?: string; timestamp?: string; user_id?: string; }>


pending() ​

ts
pending(options?): Promise<Page<{
[key: string]: unknown;
  is_group?: boolean;
  items?: object[];
  last_activity_at?: string;
  last_permanent_item?: {
   [key: string]: unknown;
     item_id?: string;
     item_type?: string;
     text?: string;
     timestamp?: string;
     user_id?: string;
  };
  thread_id?: string;
  thread_title?: string;
  users?: object[];
}>>;

One page of the message requests.

Parameters ​

ParameterType
options?CursorOptions

Returns ​

Promise<Page<{ [key: string]: unknown; is_group?: boolean; items?: object[]; last_activity_at?: string; last_permanent_item?: { [key: string]: unknown; item_id?: string; item_type?: string; text?: string; timestamp?: string; user_id?: string; }; thread_id?: string; thread_title?: string; users?: object[]; }>>


react() ​

ts
react(
   threadId, 
   itemId, 
   options?
): Promise<void>;

Reacts to a message with an emoji, or removes the reaction.

Parameters ​

ParameterType
threadIdstring
itemIdstring
options?ReactionOptions

Returns ​

Promise<void>


searchRecipients() ​

ts
searchRecipients(query, mode?): Promise<object[]>;

The people the account can message who match a query, ranked.

Parameters ​

ParameterType
querystring
mode?RecipientSearchMode

Returns ​

Promise<object[]>


ts
sendLink(text, target): Promise<{
[key: string]: unknown;
  item_id?: string;
  thread_id?: string;
  timestamp?: string;
}>;

Sends a message with a link, which the app shows with a preview.

Parameters ​

ParameterType
textstring
targetSendTarget

Returns ​

Promise<{ [key: string]: unknown; item_id?: string; thread_id?: string; timestamp?: string; }>


sendPhoto() ​

ts
sendPhoto(jpeg, target): Promise<{
[key: string]: unknown;
  item_id?: string;
  thread_id?: string;
  timestamp?: string;
}>;

Sends a JPEG photo in a thread or to users.

Parameters ​

ParameterType
jpegUint8Array
targetSendTarget

Returns ​

Promise<{ [key: string]: unknown; item_id?: string; thread_id?: string; timestamp?: string; }>


sendText() ​

ts
sendText(text, target): Promise<{
[key: string]: unknown;
  item_id?: string;
  thread_id?: string;
  timestamp?: string;
}>;

Sends a text message to a thread or to users.

Parameters ​

ParameterType
textstring
targetSendTarget

Returns ​

Promise<{ [key: string]: unknown; item_id?: string; thread_id?: string; timestamp?: string; }>


sendVideo() ​

ts
sendVideo(mp4, target): Promise<{
[key: string]: unknown;
  item_id?: string;
  thread_id?: string;
  timestamp?: string;
}>;

Sends an MP4 video (H.264 + AAC) into a thread or the thread with the given users.

Parameters ​

ParameterType
mp4Uint8Array
targetSendTarget

Returns ​

Promise<{ [key: string]: unknown; item_id?: string; thread_id?: string; timestamp?: string; }>


sendVoice() ​

ts
sendVoice(
   m4a, 
   target, 
   options?
): Promise<{
[key: string]: unknown;
  item_id?: string;
  thread_id?: string;
  timestamp?: string;
}>;

Sends a voice message: an AAC clip in an MP4 container (.m4a).

Parameters ​

ParameterType
m4aUint8Array
targetSendTarget
options?VoiceOptions

Returns ​

Promise<{ [key: string]: unknown; item_id?: string; thread_id?: string; timestamp?: string; }>


setTitle() ​

ts
setTitle(threadId, title): Promise<void>;

Renames a group thread.

Parameters ​

ParameterType
threadIdstring
titlestring

Returns ​

Promise<void>


shareMedia() ​

ts
shareMedia(
   mediaId, 
   target, 
   options?
): Promise<{
[key: string]: unknown;
  item_id?: string;
  thread_id?: string;
  timestamp?: string;
}>;

Shares a post in a thread or with users.

Parameters ​

ParameterType
mediaIdstring
targetSendTarget
options?ShareMediaOptions

Returns ​

Promise<{ [key: string]: unknown; item_id?: string; thread_id?: string; timestamp?: string; }>


shareProfile() ​

ts
shareProfile(userId, target): Promise<{
[key: string]: unknown;
  item_id?: string;
  thread_id?: string;
  timestamp?: string;
}>;

Shares a user's profile in a thread or with users.

Parameters ​

ParameterType
userIdstring
targetSendTarget

Returns ​

Promise<{ [key: string]: unknown; item_id?: string; thread_id?: string; timestamp?: string; }>


shareStory() ​

ts
shareStory(storyId, target): Promise<{
[key: string]: unknown;
  item_id?: string;
  thread_id?: string;
  timestamp?: string;
}>;

Shares a story, by its full id (pk_ownerPk), into a thread or to users.

Parameters ​

ParameterType
storyIdstring
targetSendTarget

Returns ​

Promise<{ [key: string]: unknown; item_id?: string; thread_id?: string; timestamp?: string; }>


spam() ​

ts
spam(options?): Promise<Page<{
[key: string]: unknown;
  is_group?: boolean;
  items?: object[];
  last_activity_at?: string;
  last_permanent_item?: {
   [key: string]: unknown;
     item_id?: string;
     item_type?: string;
     text?: string;
     timestamp?: string;
     user_id?: string;
  };
  thread_id?: string;
  thread_title?: string;
  users?: object[];
}>>;

One page of the hidden requests.

Parameters ​

ParameterType
options?CursorOptions

Returns ​

Promise<Page<{ [key: string]: unknown; is_group?: boolean; items?: object[]; last_activity_at?: string; last_permanent_item?: { [key: string]: unknown; item_id?: string; item_type?: string; text?: string; timestamp?: string; user_id?: string; }; thread_id?: string; thread_title?: string; users?: object[]; }>>


thread() ​

ts
thread(threadId, options?): Promise<Page<{
[key: string]: unknown;
  item_id?: string;
  item_type?: string;
  text?: string;
  timestamp?: string;
  user_id?: string;
}>>;

One page of a thread's messages, newest first.

Parameters ​

ParameterType
threadIdstring
options?CursorOptions

Returns ​

Promise<Page<{ [key: string]: unknown; item_id?: string; item_type?: string; text?: string; timestamp?: string; user_id?: string; }>>


unmute() ​

ts
unmute(threadId): Promise<void>;

Turns the notifications of a thread back on.

Parameters ​

ParameterType
threadIdstring

Returns ​

Promise<void>

MIT License. Not affiliated with, endorsed or sponsored by Meta or Instagram.