Skip to content

Commit b7ad61c

Browse files
committed
feat: add welcome and goodbye messages with custom images
1 parent 42208bd commit b7ad61c

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/admin/wellcome.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,20 @@ export const HandleWelcome = async (sock, update) => {
9696
const memberCount = groupMetadata.participants.length;
9797
const groupDesc = groupMetadata.desc?.toString() || "Tidak ada deskripsi";
9898

99+
// 1. Ambil Welcome Message dari Database
99100
const { data, error } = await supabase
100101
.from("wellcome")
101102
.from("wellcome")
102103
.select("message")
103104
.eq("id_grub", chatId)
104105
.maybeSingle();
105106

107+
// Loop untuk Setiap Member Baru
106108
for (const participant of participants) {
107109
const jid =
108110
typeof participant === "string" ? participant : participant.id;
109111

112+
// === DAPATKAN NAMA PENGGUNA ===
110113
let username = await getDisplayName(sock, jid, chatId);
111114
const phoneNumber = jid.split("@")[0];
112115

@@ -118,6 +121,12 @@ export const HandleWelcome = async (sock, update) => {
118121
ppUrl = "https://telegra.ph/file/24fa902ead26340f3df2c.png";
119122
}
120123

124+
// 4. Generate Welcome Image via API
125+
// DISESUAIKAN:
126+
// phone = Nomor HP (kiri bawah)
127+
// name = Nama User (kanan bawah)
128+
// group = Nama Grup (tengah)
129+
// image = Foto Profil
121130
const apiUrl = `https://neuraapi.vercel.app/api/etc/wellcome?phone=${phoneNumber}&name=${encodeURIComponent(username)}&group=${encodeURIComponent(groupName)}&image=${ppUrl}`;
122131

123132
const response = await axios.get(apiUrl, { responseType: "arraybuffer" });
@@ -145,3 +154,47 @@ export const HandleWelcome = async (sock, update) => {
145154
console.error("[WELCOME ERROR]", err);
146155
}
147156
};
157+
export const outGC = async (sock, update) => {
158+
try {
159+
const { id: chatId, participants, action } = update;
160+
if (action !== "remove") return;
161+
162+
const groupMetadata = await sock.groupMetadata(chatId);
163+
if (!groupMetadata) return;
164+
165+
const groupName = groupMetadata.subject || "Group";
166+
const memberCount = groupMetadata.participants?.length || 0;
167+
const groupDesc = groupMetadata.desc?.toString() || "Tidak ada deskripsi";
168+
169+
for (const participant of participants) {
170+
const jid =
171+
typeof participant === "string" ? participant : participant.id;
172+
if (!jid) continue;
173+
174+
let username = await getDisplayName(sock, jid, chatId);
175+
176+
// fallback jika nama = nomor
177+
if (username === jid.split("@")[0]) {
178+
const participantObj = groupMetadata.participants?.find(
179+
(p) => p.id === jid,
180+
);
181+
if (participantObj?.notify) {
182+
username = participantObj.notify;
183+
}
184+
}
185+
186+
const number = jid.split("@")[0];
187+
188+
const message = `
189+
Selamat tinggal @${number}
190+
`.trim();
191+
192+
await sock.sendMessage(chatId, {
193+
text: message,
194+
mentions: [jid],
195+
});
196+
}
197+
} catch (err) {
198+
console.log("outGC error:", err);
199+
}
200+
};

0 commit comments

Comments
 (0)