Instagram-private-api: How can I get ThreadID from a user who is not in my feed.directInbox()

Created on 27 Sep 2019  路  2Comments  路  Source: dilame/instagram-private-api

How can I get ThreadID from a user who is not in my feed.directInbox ()?

Or put another way, how can I send a message to a person who has never sent me a message before?

This is my actual code, that works perfect, but only in people who are already in my inbox

async function replyDirectMessage(ig, thread, message){ 
    let prepareThreadForAwnsering = await ig.entity.directThread(thread.threadId);
    let broadcastText = await prepareThreadForAwnsering.broadcastText(message);
    return broadcastText.item_id ? "message_sent" : "something_went_wrong";
}

Most helpful comment

I wrote a wrapper for working with all Instagram functions simulating a user, this is the function I use for sending text messages:

const sendMessage = async ({ threadId, userId }, messageContent) => {
    let threadEntity = null;

    if (threadId) {
      threadEntity = ig.entity.directThread(threadId);
    } else if (userId) {
      threadEntity = ig.entity.directThread([userId.toString()]);
    }

    if (!threadEntity) {
      throw new Error('No valid threadEntity was able to be created!');
    }

    return threadEntity.broadcastText(messageContent);
};

You must provide either threadId or userId and it works nicely :)

All 2 comments

I wrote a wrapper for working with all Instagram functions simulating a user, this is the function I use for sending text messages:

const sendMessage = async ({ threadId, userId }, messageContent) => {
    let threadEntity = null;

    if (threadId) {
      threadEntity = ig.entity.directThread(threadId);
    } else if (userId) {
      threadEntity = ig.entity.directThread([userId.toString()]);
    }

    if (!threadEntity) {
      throw new Error('No valid threadEntity was able to be created!');
    }

    return threadEntity.broadcastText(messageContent);
};

You must provide either threadId or userId and it works nicely :)

That piece of code works perfectly, thank you very much.

I wrote a wrapper for working with all Instagram functions simulating a user, this is the function I use for sending text messages:

const sendMessage = async ({ threadId, userId }, messageContent) => {
    let threadEntity = null;

    if (threadId) {
      threadEntity = ig.entity.directThread(threadId);
    } else if (userId) {
      threadEntity = ig.entity.directThread([userId.toString()]);
    }

    if (!threadEntity) {
      throw new Error('No valid threadEntity was able to be created!');
    }

    return threadEntity.broadcastText(messageContent);
};

You must provide either threadId or userId and it works nicely :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jcagz96 picture jcagz96  路  3Comments

serg2801 picture serg2801  路  4Comments

Radzhab picture Radzhab  路  3Comments

acollazo25 picture acollazo25  路  4Comments

kvcpr picture kvcpr  路  4Comments