notification wa by mqtt broker
This commit is contained in:
@@ -24,6 +24,7 @@ const getAllContactDb = async (searchParams = {}) => {
|
||||
[
|
||||
{ column: "a.contact_name", param: searchParams.name, type: "string" },
|
||||
{ column: "a.contact_type", param: searchParams.code, type: "string" },
|
||||
{ column: "a.is_active", param: searchParams.active, type: "boolean" },
|
||||
],
|
||||
queryParams
|
||||
);
|
||||
|
||||
@@ -349,7 +349,7 @@ const getHistoryValueTrendingPivotDb = async (tableName, searchParams = {}) => {
|
||||
const tagList = Object.keys(rows[0]).filter(k => k !== timeKey);
|
||||
|
||||
const nivoData = tagList.map(tag => ({
|
||||
id: tag,
|
||||
name: tag,
|
||||
data: rows.map(row => ({
|
||||
x: row[timeKey],
|
||||
y: row[tag] !== null ? Number(row[tag]) : null
|
||||
|
||||
59
db/notification_wa.db.js
Normal file
59
db/notification_wa.db.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const { default: axios } = require('axios');
|
||||
const CryptoJS = require('crypto-js');
|
||||
|
||||
const generateTokenRedirect = async (userPhone, userName, id) => {
|
||||
|
||||
const plain = {
|
||||
user_phone: userPhone,
|
||||
user_name: userName,
|
||||
id
|
||||
}
|
||||
|
||||
const tokenCrypt = CryptoJS.AES.encrypt(JSON.stringify(plain), process.env.VITE_KEY_SESSION).toString();
|
||||
return tokenCrypt
|
||||
}
|
||||
|
||||
const shortUrltiny = async (encodedToken) => {
|
||||
const url = `${process.env.ENDPOINT_FE}/redirect?token=${encodedToken}`
|
||||
|
||||
const encodedUrl = encodeURIComponent(url); // ⬅️ Encode dulu!
|
||||
|
||||
const response = await axios.get(`https://tinyurl.com/api-create.php?url=${encodedUrl}`);
|
||||
|
||||
let shortUrl = response.data;
|
||||
if (!shortUrl.startsWith('http')) {
|
||||
shortUrl = 'https://' + shortUrl;
|
||||
}
|
||||
|
||||
return shortUrl
|
||||
}
|
||||
|
||||
const sendNotifikasi = async (phone, message) => {
|
||||
const payload = {
|
||||
phone: phone,
|
||||
message: message
|
||||
};
|
||||
|
||||
// console.log('payload', payload);
|
||||
|
||||
const endPointWhatsapp = process.env.ENDPOINT_WHATSAPP;
|
||||
|
||||
const response = await axios.post(endPointWhatsapp, payload);
|
||||
// console.log('response', response);
|
||||
|
||||
try {
|
||||
const response = await axios.post(endPointWhatsapp, payload);
|
||||
// console.log(response.data);
|
||||
return response?.data
|
||||
} catch (error) {
|
||||
// console.error(error.response?.data || error.message);
|
||||
return error.response?.data || error.message
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
generateTokenRedirect,
|
||||
shortUrltiny,
|
||||
sendNotifikasi,
|
||||
};
|
||||
Reference in New Issue
Block a user