Good afternoon! I need to write a method that should provide all messages from the instagram chat, but I get the first 10 messages, and not everything as I need.
You can see the source code below:
async getMessages(userId: number, threadId: string) {
let allMessages = [];
let cursor = null;
do {
const thread = await this.ig.feed.directThread({ thread_id: threadId, oldest_cursor: cursor }).items();
allMessages = allMessages.concat(thread);
cursor = this.ig.feed.directThread({ thread_id: threadId, oldest_cursor: cursor }).cursor;
} while (cursor !== null);
const messages = allMessages.map(message => ({
messageId: message.item_id,
userId: message.user_id,
text: message.text,
cursor: message.next_cursor,
timestamp: message.timestamp,
}));
return messages;
}
I use the private-instagram-api as a library.
I expect to receive all messages, not the first 10
New contributor
Никита Горшков is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.