Skip to content

Commit 01a0f1c

Browse files
committed
adding firstname to message
1 parent 98635d6 commit 01a0f1c

File tree

4 files changed

+731
-6
lines changed

4 files changed

+731
-6
lines changed

.env.example

-2
This file was deleted.

handlers/responseHandler.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ module.exports.handleResponse = async (res) => {
88
const resourceType = await req.resourceType();
99
const resourceURL = await req.url();
1010

11-
if (resourceType === "xhr" && resourceURL === "https://www.facebook.com/api/graphql/") {
11+
if (
12+
resourceType === "xhr" &&
13+
resourceURL === "https://www.facebook.com/api/graphql/"
14+
) {
1215
const json = JSON.parse((await res.buffer()).toString());
16+
console.log("json:", json);
1317

1418
if (json.data.hasOwnProperty("node")) {
1519
let edges = json.data.node.new_members.edges;
20+
console.log("edges:", edges);
1621
edges = edges.map((edge) => {
17-
return { id: edge.node.id, name: edge.node.name, me: `https://www.messenger.com/t/${edge.node.id}` };
22+
return {
23+
id: edge.node.id,
24+
name: edge.node.name,
25+
me: `https://www.messenger.com/t/${edge.node.id}`,
26+
};
1827
});
1928

2029
for (const edge of edges) {

src/sendMessage.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
require("dotenv").config();
33

44
// User Imports
5-
const { launchBrowser, launchPage, sendMessage } = require("../handlers/puppeteerHelper");
5+
const {
6+
launchBrowser,
7+
launchPage,
8+
sendMessage,
9+
} = require("../handlers/puppeteerHelper");
610
const { getRandomInt } = require("../handlers/generalHandler");
711
const { findAll } = require("../handlers/databaseHandler");
812

@@ -31,7 +35,7 @@ const INDIVIDUAL_SENT = "https://m.me/110035443798530";
3135
for (doc of docs) {
3236
console.log(`[✨] Sending Message To ${doc.name}`);
3337
await page.goto(doc.me, { waitUntil: "networkidle0" });
34-
await sendMessage(page, MESSAGE_TO_SENT);
38+
await sendMessage(page, Message(doc.name));
3539
await page.waitFor(getRandomInt(10000, 20001));
3640
}
3741
} else {
@@ -43,3 +47,9 @@ const INDIVIDUAL_SENT = "https://m.me/110035443798530";
4347
await page.waitFor(getRandomInt(10000, 20001));
4448
await browser.close();
4549
})();
50+
51+
const Message = (fullName) => {
52+
const firstname = fullName.split(" ")[0];
53+
console.log("firstname:", firstname);
54+
return `Hi ${firstname}, are you good`;
55+
};

0 commit comments

Comments
 (0)