dilame / instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.
MIT License
5.93k stars 1.14k forks source link

On FBNS message, automatically accept the DM request and reply to the user #1051

Open Androz2091 opened 4 years ago

Androz2091 commented 4 years ago

General Question

Read the Notes and fill out the form. Switch to Preview for reading.

Notes

Your issue will be closed if you violate any rule below.

Form

Put an [x] if you meet the condition, else leave [ ].

Question

A specific question, so it's understandable to anyone. You may add pictures.

YOUR QUESTION HERE

So, I'm making an Instagram chatbot. When a user sends 'hello' to the user, it replies 'hello!'. It works perfectly.

But sometimes, the bot account doesn't know a new user account and it throws the following error: IgExactUserNotFoundError: User with exact username not found.

This error comes from the code which try to reply to the user. And it happens when the bot receive a "DM Request". By looking for a few hours, I could find the solution myself, but the problem is that I can't reproduce the bug, since I need a new instagram account for each test (else it won't trigger a dm request). So I was wondering if you'd know how to do that:

I don't know if that's possible and if so, I very much hope you know how, @Nerixyz... 🙏🙏

Nerixyz commented 4 years ago

when a message is received from the FBNS client, detect if it's a real message or if it's blocked by a DM request.

I guess the DM is then pending. There's no real direct/info request so you'll have to look at the feed like this:

const {thread: {pending}} = await this.ig.feed.directThread({thread_id: id, oldest_cursor: undefined}).request();
console.log(pending);

This is how you know if it's pending. Then you can call ig.directThread.approve(id) to accept the request. Note: ig.feed.directThread({}) is very useful when dealing with threads. I'm also using it here to get basic informations about the thread.

Androz2091 commented 4 years ago

Thank you very much! I can't test at the moment as I don't have a second Instagram account but I hope it will work :)