Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

Direct Messaging

Rahil edited this page Apr 14, 2026 · 5 revisions

This guide shows how to use Direct Messages (DMs) with JxInsta’s mobile API (com.jxinsta.mobile.endpoints.direct).
The web module does not support direct messaging as of now

🔑 Setup

Always start with an auth token:

JxInsta insta = JxInsta.getInstance(AUTH_TOKEN);

⚠️ Methods may throw InstagramException — handle errors properly.


📥 Fetch Inbox

var inbox = insta.getDirectInbox(10, 5); // maxThreads, maxMessages
System.out.println("total threads: " + inbox.totalThreads);
inbox.threads.forEach(t -> System.out.println("thread id: " + t.id + " recipient: " + t.recipient));

📂 Read a Thread

String threadId = inbox.threads.get(0).id;
var thread = inbox.getThread(threadId, 20); // fetch messages
var paginator = thread.getMessages();

while (paginator.hasNext()) {
    var page = paginator.next();
    page.forEach(msg -> System.out.println(msg));
}

✏️ Send a Text

thread.sendMessage("Hello from JxInsta!");

🖼️ Send an Image

try (InputStream in = new FileInputStream("photo.jpg")) {
    thread.sendImage(in, "Caption for image");
}

👀 Mark as Seen

thread.markSeen();

🗑️ Delete / Hide a Thread

thread.delete();

📬 DM Requests (Pending)

var requests = inbox.getRequests(5, 5);
System.out.println("pending requests: " + requests.size());

💡 Tips

  • Thread objects include: id, recipient, recipientId, displayPicture, messages, lastItemId.
  • MessagePaginator helps scroll back through older messages.
  • sendImage first uploads the picture, then attaches it.
  • markSeen requires a valid lastItemId.

✨ With these basics, you can fetch inboxes, read threads, send messages, and manage DMs easily!

Clone this wiki locally