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";
}
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
threadIdoruserIdand it works nicely :)
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:
You must provide either
threadIdoruserIdand it works nicely :)