diff --git a/db/notification_wa.db.js b/db/notification_wa.db.js index a2a1a98..b2ffb31 100644 --- a/db/notification_wa.db.js +++ b/db/notification_wa.db.js @@ -1,11 +1,11 @@ // db/notification_wa.db.js const { default: axios } = require('axios'); const CryptoJS = require('crypto-js'); -// const https = require('https'); +const https = require('https'); -// const httpsAgent = new https.Agent({ -// rejectUnauthorized: false, -// }); +const httpsAgent = new https.Agent({ + rejectUnauthorized: false, +}); const generateTokenRedirect = async (userPhone, userName, id) => { @@ -24,7 +24,7 @@ const shortUrltiny = async (encodedToken) => { const encodedUrl = encodeURIComponent(url); // ⬅️ Encode dulu! - const response = await axios.get(`https://tinyurl.com/api-create.php?url=${encodedUrl}`); + const response = await axios.get(`https://tinyurl.com/api-create.php?url=${encodedUrl}`,{httpsAgent}) ; let shortUrl = response.data; if (!shortUrl.startsWith('http')) { @@ -45,7 +45,7 @@ const sendNotifikasi = async (phone, message) => { const endPointWhatsapp = process.env.ENDPOINT_WHATSAPP; try { - const response = await axios.post(endPointWhatsapp, payload); + const response = await axios.post(endPointWhatsapp, payload,{httpsAgent} ); // console.log(response.data); return response?.data } catch (error) { diff --git a/services/notification_error.service.js b/services/notification_error.service.js index fc8b004..634ed42 100644 --- a/services/notification_error.service.js +++ b/services/notification_error.service.js @@ -186,7 +186,7 @@ class NotificationService { if (activeUsers.length < 1) throw new ErrorHandler(404, "No active contacts"); - this._executeResendInBackground( + this._executeResendWa( id, activeUsers, deviceNotification, @@ -198,23 +198,27 @@ class NotificationService { }; } - static async _executeResendInBackground( + static async _executeResendWa( id, activeUsers, deviceNotification, errorCode ) { - console.log(`process untuk ID: ${id}`); + console.log(`user active: `, id, activeUsers); const sendPromises = activeUsers.map(async (user) => { try { + console.log(`user: ${user.contact_name} (${user.contact_phone})`); const tokenRedirect = await generateTokenRedirect( user.contact_phone, user.contact_name, id ); + const encodedToken = encodeURIComponent(tokenRedirect); + console.log("token: ", tokenRedirect); const shortUrl = await shortUrltiny(encodedToken); + console.log("URL:", shortUrl); const bodyWithUrl = `Hai ${user.contact_name || "-"}\n` + @@ -227,6 +231,8 @@ class NotificationService { user.contact_phone, bodyWithUrl ); + + console.log("notifikasi wa:", resultSend) const isSuccess = resultSend?.error ? false : true; @@ -247,6 +253,7 @@ class NotificationService { }); const results = await Promise.all(sendPromises); + console.log("result akhir: ", results) console.log( `Resend chat: ${