linkfy/Tools-for-Instagram

`getInbox` error: `TypeError: Cannot read property 'timestamp' of undefined`

micalevisk opened this issue ยท 5 comments

When I tried to run this code:

require('tools-for-instagram');

(async () => {
	const ig = await login();
    const inbox = await getInbox(ig);
	console.log(inbox);
})();

I got this error:

Logged in
(node:6884) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'timestamp' of undefined
    at xxx\node_modules\tools-for-instagram\src\getInbox.js:39:73
    at Array.map (<anonymous>)
    at getInbox (xxx\node_modules\tools-for-instagram\src\getInbox.js:29:42)

readByMe: (dm.last_seen_at[Object.keys(dm.last_seen_at)[1]].timestamp == dm.last_permanent_item.timestamp),

Object.keys(dm.last_seen_at)
/*
[ 'a', 'b']
[ 'b', 'c' ]
[ 'd', 'b' ]
[ 'e', 'b' ]
[ 'b', 'f' ]
[ 'b', 'g' ]
[ 'h', 'b' ]
[ 'b' ]
where "b" is my id (`ig.loggedInUser.pk`)
*/

Thanks for the feedback @micalevisk, I am trying to recreate the issue on my account but I don't get the error, I made a little modification to the "getInbox.js" file inside src folder. But I need to test it.
Can you try to replace the "getInbox.js" with the code from this pastebin?
getInbox.js
In this way, we can try to detect the error.

I am trying to recreate the issue on my account but I don't get the error, I made a little modification to the "getInbox.js" file inside src folder.

I guess this happen when you send a DM to yourself or when the destination user never sent you a message. Your version works but now readByMe is null in these scenarios. Also never throw errors.

Thanks for the info! Then I will set the default values to false for the user and true to readByMe to match these cases and release a new version soon.

Done new commit with fixes uploaded, if you have time verify me if it works and I close the commit, thank you!

It's working as expected, ty! ๐Ÿ˜„