Nerixyz / instagram_mqtt

Realtime and Push Notification (FBNS) support for the instagram-private-api
MIT License
252 stars 50 forks source link

Skip patch event notification #71

Closed realrecordzLab closed 3 years ago

realrecordzLab commented 3 years ago

Using the message event, is possible to skip notifications about patch events? Is there any code example?

I'm trying with this code but not sure if will work as expected:

    ig.realtime.on('message', (message) => { 
       if(  message.event === 'patch' ){
          return;
       }
       ....
    });

Is there any documentations about the events that are provided with message object? How is the correct way to get informations about the thread and the users that is emitting the patch event?

Nerixyz commented 3 years ago

Is there any documentations about the events that are provided with message object?

Besides the types there's no documentation.

How is the correct way to get informations about the thread and the users that is emitting the patch event?

You get a thread id which can be used to look up informations about a thread. In a real application you'd probably cache the thread infos.

not sure if will work as expected:

If you don't want to handle the patch event, then it's fine.

realrecordzLab commented 3 years ago

Found a solution to get the thread info after searching in the issues.

    ig.realtime.on('message', async (data) => { 
        const thread = await ig.feed.directThread({thread_id: data.message.thread_id}).request();
        console.log(thread);
    });

With this code I'm able to get thread info but the problem is that I will also get messages I send to the other user. Is there any field that I can use to get only messages that are sent to me from the other user?

Nerixyz commented 3 years ago

Is there any field that I can use to get only messages that are sent to me from the other user?

    ig.realtime.on('message', async ({message}) => { 
        if(message.user_id.toString() === ig.state.cookieUserId) return;
        console.log(message);
    });

Found a solution to get the thread info after searching in the issues.

Be careful. This will always request the thread from instagram. The app doesn't do that. You should cache the thread.

realrecordzLab commented 3 years ago

Is there any field that I can use to get only messages that are sent to me from the other user?

    ig.realtime.on('message', async ({message}) => { 
        if(message.user_id.toString() === ig.state.cookieUserId) return;
        console.log(message);
    });

Found a solution to get the thread info after searching in the issues.

Be careful. This will always request the thread from instagram. The app doesn't do that. You should cache the thread.

At the moment I'm requesting the thread only for new messages when received. Maybe a solution can be to store each thread_id into an array? I'm confused about caching implementation in my CLI script