Inbox and Thread represent the Instagram direct message layer in the JxInsta mobile library. Inbox is the top-level container returned by JxInsta.getDirectInbox() — it holds a list of Thread objects and the usernames of inbox participants. Each Thread represents a single conversation and provides methods to send text messages and images, paginate message history, delete the conversation, and mark it as read.
Thread fields
Thread objects are constructed from the threads array inside the inbox JSON response. Most fields are populated when constructing from a full thread JSON object.
The unique thread identifier, sourced from
thread_id in the API response. Used as the key for all thread-level API operations.The username of the other participant in the conversation, sourced from the first element of the
users array.The numeric primary key (
pk) of the recipient user. Used when constructing the recipient_users field for outbound messages.The URL of the recipient’s high-resolution profile picture (
profile_pic_url_hd). May be an empty string if unavailable.A list of message text strings loaded from the
items array at construction time. Each entry corresponds to the text field of one message item. The list is ordered as returned by the API (most recent first).The cursor pointing to the oldest loaded message, sourced from
oldest_cursor. Passed to MessagePaginator to fetch earlier pages of message history.The
item_id of the most recent message in the thread, used by markSeen() to update the read receipt.Thread methods
sendMessage(String message)
Sends a text message to the thread’s recipient. The method generates a unique client_context UUID for deduplication and sends the message via the direct send endpoint.
Thread.java
The text content of the message to send. Must not be null (
@NotNull). Sent as the text field in the signed request body.void
Throws — InstagramException
sendImage(InputStream inputStream, String caption)
Uploads an image and sends it as a direct message to the thread’s recipient. The image is uploaded first to obtain an upload ID (attachment_fbid), then dispatched via the photo send endpoint.
Thread.java
The raw bytes of the image to send. Must not be null (
@NotNull). The stream is consumed during the upload step.A text caption to accompany the image in the message. Must not be null (
@NotNull). Sent as the text field alongside the image attachment.void
Throws — InstagramException (wraps any IOException from the upload step as Reasons.IO)
getMessages()
Returns a MessagePaginator for lazily fetching older pages of message history for this thread. The paginator is seeded with the thread’s oldestCursor to start from where the inbox fetch left off.
Thread.java
MessagePaginator
delete()
Deletes the thread for the authenticated user. The request is sent with should_move_future_requests_to_spam=false, meaning future messages from the same user will not be filtered.
Thread.java
void
Throws — InstagramException
markSeen()
Marks the thread as read up to the most recent message. This method is a no-op if lastItemId is null (i.e., the thread was constructed without message items).
Thread.java
void
Throws — InstagramException
toString()
Returns a string representation of all thread fields, useful for logging and debugging.
Thread.java
Inbox fields
Inbox is returned by JxInsta.getDirectInbox(int maxThreads, int maxMessages). It parses the inbox and users arrays from the raw API response.
The number of threads retrieved in this response, equal to
threads.size(). Derived from the length of the threads JSON array.The list of
Thread objects loaded from the inbox. Each thread includes pre-fetched messages up to the maxMessages limit specified in getDirectInbox.A flat list of usernames of all participants found in the inbox
users array. Complements the per-thread recipient field.Inbox methods
getRequests(int maxThreads, int maxMessages)
Fetches pending message requests (conversations from users you do not follow) from the separate DM requests inbox endpoint.
Inbox.java
The maximum number of request threads to return. Maps to the
limit query parameter.The maximum number of messages to load per request thread. Maps to the
thread_message_limit query parameter.List<Thread>
Throws — InstagramException
getThread(String id, int maxMessage)
Fetches a single thread by its ID, loading up to maxMessage messages. Use this to refresh a thread or to load a thread you already have an ID for without fetching the full inbox.
Inbox.java
The unique thread ID to fetch. Corresponds to
Thread.id.The maximum number of messages to load for this thread. Maps to the
limit query parameter on the thread detail endpoint.Thread
Throws — InstagramException