-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (74 loc) · 2.49 KB
/
Copy pathindex.js
File metadata and controls
77 lines (74 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const {
default: makeWaSocket,
useMultiFileAuthState,
makeInMemoryStore,
} = require("@whiskeysockets/baileys");
const boom = require("@hapi/boom");
const pino = require("pino");
const qrcode = require("qrcode-terminal");
async function startConect() {
const { state, saveCreds } = await useMultiFileAuthState("session");
store = makeInMemoryStore({
logger: pino().child({ level: "silent", stream: "store" }),
});
const dian = makeWaSocket({
printQRInTerminal: true,
browser: ["Ardian", "Linux", "3.0.0"],
auth: state,
getMessage: async (key) => {
if(store) {
const msg = await store.loadMessage(key.remoteJid, key.id);
return msg.message || undefined;
}
return {
conversation: "Halo Saya Ardian",
};
},
});
store.bin(dian.ev);
dian.ev.on("connection.update", async (update) => {
const { connection, lastDisconnect, qr } = update;
if (lastDisconnect == "undefined" && qr != "undefined") {
qrcode.generate(qr, {
small: true,
});
}
if (connection === "connecting") {
console.log("Connecting");
} else if (connection === "open") {
console.log("Connected ✓");
await console.log(
`Terhubung: ${dian.user.name || dian.user.verifiedName}`
);
} else if (connection === "close") {
if (
lastDisconnect.error.output.statusCode ==
DisconnectReason.loggedOut
) {
console.log("Failed Connect To WhatsApp");
await process.kill(0);
} else {
startConect().catch(() => startConect());
}
}
});
dian.ev.on("messages.upsert", (m) => {
const chat = messages[0].message.conversation;
const id = messages[0].m.key.remoteJid;
const reply = (text) => {
dian.sendMessage(chat, {
text: text,
});
};
//====// Perintah Pesan //=====//
if (chat == "/menu") {
dian.sendMessage(id, {
text: "Belum Ada Menu",
});
} else if (chat == "Halo") {
reply("halo ada apa?");
}
//=====// Batas Perintah //=====//
});
}
startConect();