Initial Commit
This commit is contained in:
+11
-11
@@ -1,11 +1,12 @@
|
||||
import { test } from '@playwright/test';
|
||||
import path from 'path';
|
||||
|
||||
test.use({ storageState: '/home/pwuser/ig-session.json' });
|
||||
test.use({ storageState: path.resolve(__dirname, '.auth', 'ig-session.json') });
|
||||
|
||||
test('inspect non-text message shapes', async ({ page }) => {
|
||||
test('inspect IMAGES message shape', async ({ page }) => {
|
||||
test.setTimeout(120_000);
|
||||
|
||||
const interesting = [];
|
||||
const found = [];
|
||||
|
||||
page.on('response', async (response) => {
|
||||
const url = response.url();
|
||||
@@ -17,10 +18,8 @@ test('inspect non-text message shapes', async ({ page }) => {
|
||||
const t = json?.data?.get_slide_thread_nullable?.as_ig_direct_thread;
|
||||
if (!t) return;
|
||||
for (const edge of t.slide_messages?.edges || []) {
|
||||
const node = edge.node;
|
||||
const hasReactions = (node.reactions?.length || 0) > 0 || (node.msg_reactions?.length || 0) > 0;
|
||||
if (node.content_type !== 'TEXT' || hasReactions || node.replied_to_message) {
|
||||
interesting.push({ thread: t.thread_title, node });
|
||||
if (edge.node?.content_type === 'IMAGES') {
|
||||
found.push(edge.node);
|
||||
}
|
||||
}
|
||||
} catch (e) { /* skip */ }
|
||||
@@ -29,13 +28,14 @@ test('inspect non-text message shapes', async ({ page }) => {
|
||||
await page.goto('https://www.instagram.com/direct/inbox/');
|
||||
await page.waitForTimeout(6000);
|
||||
|
||||
const threadHrefs = await page.$$eval('a[href*="/direct/t/"]', els =>
|
||||
[...new Set(els.map(el => el.getAttribute('href')))]);
|
||||
const threadHrefs = await page.$$eval('a[href*="/direct/t/"]', (els) => [
|
||||
...new Set(els.map((el) => el.getAttribute('href'))),
|
||||
]);
|
||||
|
||||
for (const href of threadHrefs) {
|
||||
await page.goto(`https://www.instagram.com${href}`);
|
||||
await page.waitForTimeout(3500);
|
||||
}
|
||||
|
||||
console.log('[INTERESTING MESSAGES]', JSON.stringify(interesting, null, 2));
|
||||
});
|
||||
console.log('[IMAGES MESSAGES]', JSON.stringify(found, null, 2));
|
||||
});
|
||||
|
||||
@@ -61,6 +61,18 @@ function extractShare(node) {
|
||||
};
|
||||
}
|
||||
|
||||
// A raw photo/video message has content_type 'IMAGES' with one or more
|
||||
// attachments (Instagram allows sending several photos in a single message).
|
||||
function extractAttachments(node) {
|
||||
const attachments = node.content?.attachments;
|
||||
if (!attachments?.length) return null;
|
||||
return attachments.map((a) => ({
|
||||
url: a.attachment_cdn_url || a.preview_cdn_url || null,
|
||||
width: a.preview_width || null,
|
||||
height: a.preview_height || null,
|
||||
})).filter((a) => a.url);
|
||||
}
|
||||
|
||||
function extractMessage(node, thread, fbidLookup) {
|
||||
const senderDict = node.sender?.user_dict;
|
||||
const resolved = senderDict
|
||||
@@ -85,6 +97,7 @@ function extractMessage(node, thread, fbidLookup) {
|
||||
text: node.text_body || node.content?.text_body || null,
|
||||
timestamp_ms: node.timestamp_ms ? Number(node.timestamp_ms) : null,
|
||||
share: extractShare(node),
|
||||
attachments: extractAttachments(node),
|
||||
reactions: reactions.length ? reactions : null,
|
||||
replied_to_id: node.replied_to_message_id || null,
|
||||
replied_to_text: node.replied_to_message?.text_body || null,
|
||||
|
||||
Reference in New Issue
Block a user