fixing body message notification wa

This commit is contained in:
2026-01-13 16:18:09 +07:00
parent 890a88447e
commit 7122818181
5 changed files with 26 additions and 28 deletions

View File

@@ -21,7 +21,8 @@ const getNotificationByIdDb = async (id) => {
d.device_name, d.device_name,
d.device_location, d.device_location,
d.listen_channel, d.listen_channel,
e.brand_name e.brand_name,
e.brand_id
FROM notification_error a FROM notification_error a

View File

@@ -67,7 +67,9 @@ const getNotificationErrorUserByIdDb = async (id) => {
d.error_code, d.error_code,
d.error_code_name, d.error_code_name,
e.device_name e.device_name,
c.error_chanel as chanel_id
FROM notification_error_user a FROM notification_error_user a

View File

@@ -7,7 +7,7 @@ const {
updateNotificationErrorDb, updateNotificationErrorDb,
} = require("../db/notification_error.db"); } = require("../db/notification_error.db");
const { getErrorCodeByIdDb } = require("../db/brand_code.db"); const { getErrorCodeByIdDb, getErrorCodeByBrandAndCodeDb } = require("../db/brand_code.db");
const { getSolutionsByErrorCodeIdDb } = require("../db/brand_code_solution.db"); const { getSolutionsByErrorCodeIdDb } = require("../db/brand_code_solution.db");
@@ -175,7 +175,7 @@ class NotificationService {
const deviceNotification = await getNotificationByIdDb(id); const deviceNotification = await getNotificationByIdDb(id);
if (!deviceNotification) throw new ErrorHandler(404, "Data not found"); if (!deviceNotification) throw new ErrorHandler(404, "Data not found");
const errorCode = await getErrorCodeByIdDb( const errorCode = await getErrorCodeByBrandAndCodeDb(deviceNotification?.brand_id ?? 0,
deviceNotification.error_code_id deviceNotification.error_code_id
); );
const dataExist = await getUsersNotificationErrorDb(id); const dataExist = await getUsersNotificationErrorDb(id);
@@ -208,7 +208,7 @@ class NotificationService {
const sendPromises = activeUsers.map(async (user) => { const sendPromises = activeUsers.map(async (user) => {
try { try {
console.log(`user: ${user.contact_name} (${user.contact_phone})`); console.log(`user: ${user.contact_name} (${user.contact_phone})`);
const tokenRedirect = await generateTokenRedirect( const tokenRedirect = await generateTokenRedirect(
user.contact_phone, user.contact_phone,
user.contact_name, user.contact_name,
@@ -221,17 +221,17 @@ class NotificationService {
console.log("URL:", shortUrl); console.log("URL:", shortUrl);
const bodyWithUrl = const bodyWithUrl =
`Hai ${user.contact_name || "-"}\n` + `Hai ${user.contact_name || "-"},\n` +
`Terjadi peringatan dengan kode ${errorCode?.error_code || "-"} - ${ `Terjadi peringatan dengan kode ${errorCode?.error_code ?? "-"} "${errorCode?.error_code_name}", Chanel ${deviceNotification?.error_chanel ?? "-"} ` +
errorCode?.error_code_name `pada device ${deviceNotification.device_name ?? "berikut"}` +
} pada device ${deviceNotification.device_name || "-"}.\n` + `\nSilahkan cek detail pada link :` +
`Silahkan cek detail pada link berikut:\n ${shortUrl}`; `${shortUrl}`;
const resultSend = await sendNotifikasi( const resultSend = await sendNotifikasi(
user.contact_phone, user.contact_phone,
bodyWithUrl bodyWithUrl
); );
console.log("notifikasi wa:", resultSend) console.log("notifikasi wa:", resultSend)
const isSuccess = resultSend.success; const isSuccess = resultSend.success;
@@ -256,8 +256,7 @@ class NotificationService {
console.log("result akhir: ", results) console.log("result akhir: ", results)
console.log( console.log(
`Resend chat: ${ `Resend chat: ${results.filter((r) => r.status === "success").length
results.filter((r) => r.status === "success").length
}, Gagal: ${results.filter((r) => r.status === "failed").length}` }, Gagal: ${results.filter((r) => r.status === "failed").length}`
); );
} }

View File

@@ -20,7 +20,7 @@ class NotificationErrorUserService {
try { try {
const results = await getAllNotificationErrorUserDb(param); const results = await getAllNotificationErrorUserDb(param);
results.data.map((element) => {}); results.data.map((element) => { });
return results; return results;
} catch (error) { } catch (error) {
@@ -139,13 +139,10 @@ class NotificationErrorUserService {
const shortUrl = await shortUrltiny(encodedToken); const shortUrl = await shortUrltiny(encodedToken);
const bodyWithUrl = const bodyWithUrl =
`Hai ${data.contact_name || "-"}\n` + `Hai ${data.contact_name || "-"},\n` +
`Terjadi peringatan dengan kode error ${data.error_code || "-"} - ${ `Terjadi peringatan dengan kode ${data?.error_code ?? "-"} "${data?.error_code_name ?? ""}", Chanel ${data?.chanel_id ?? "-"} ` +
data.error_code_name || "-" `pada device ${data?.device_name ?? "berikut"},` +
} ` + `\nSilahkan cek detail pada link :` +
`pada device ${
data.device_name || "-"
}, silahkan cek detail pada link berikut:\n` +
`${shortUrl}`; `${shortUrl}`;
const resultSend = await sendNotifikasi( const resultSend = await sendNotifikasi(
@@ -165,9 +162,8 @@ class NotificationErrorUserService {
results.push({ results.push({
id, id,
status: "failed", status: "failed",
message: `WhatsApp API Gagal: ${ message: `WhatsApp API Gagal: ${resultSend?.message || "Unknown Error"
resultSend?.message || "Unknown Error" }`,
}`,
}); });
} else { } else {
results.push({ results.push({

View File

@@ -80,10 +80,10 @@ class NotifikasiWaService {
const shortUrl = await shortUrltiny(encodedToken); const shortUrl = await shortUrltiny(encodedToken);
const bodyMessage = const bodyMessage =
`Hai ${dataUser.contact_name || "-"}\n` + `Hai ${dataUser.contact_name || "-"},\n` +
`Terjadi kode error ${chanel?.value ?? "-"} ${errorCode?.error_code_name ?? ""}Chanel ${chanel?.chanel_id ?? "-"} ` + `Terjadi peringatan dengan kode ${chanel?.value ?? "-"} "${errorCode?.error_code_name ?? ""}", Chanel ${chanel?.chanel_id ?? "-"} ` +
`pada device ${deviceNotification?.device_name ?? "berikut" `pada device ${deviceNotification?.device_name ?? "berikut"},` +
}, Silahkan cek detail pada link berikut:\n` + `\nSilahkan cek detail pada link :` +
`${shortUrl}`; `${shortUrl}`;
const param = { const param = {