| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- const axios = require('../utils/axios')
- const kontakModel = require('../model/kontak.model')
- const { logInfo, logError } = require('./logger')
- exports.notifWA = async (templateId, data, where = {}) => {
- const kontak = await kontakModel.find(where)
- const contacts = kontak.map((e) => ({ name: e.nama, number: e.no_hp }))
- const url = 'https://api2.kemdiktisaintek.go.id/qontak/1.0/send'
-
- logInfo('WA_SEND_V1', 'Sending WA via notifWA v1', { templateId, contactsCount: contacts.length, contacts })
- try {
- const send = await axios.post(url, { templateId, contacts, body: data })
- logInfo('WA_SEND_V1', 'WA sent successfully v1', { templateId, response: send })
- return send
- } catch (error) {
- logError('WA_SEND_V1', 'Failed to send WA v1', {
- templateId,
- error: error.message,
- response: error.response?.data || null
- })
- throw error
- }
- }
- exports.notifWA2 = async (templateId, { nama, no_hp }, data) => {
- const url = 'https://api2.kemdiktisaintek.go.id/qontak/1.0/send'
- const contacts = [{ name: nama, number: no_hp }]
-
- logInfo('WA_SEND_V1', 'Sending WA via notifWA2 v1', { templateId, contacts })
- try {
- const send = await axios.post(url, { templateId, contacts, body: data })
- logInfo('WA_SEND_V1', 'WA2 sent successfully v1', { templateId, response: send })
- return send
- } catch (error) {
- logError('WA_SEND_V1', 'Failed to send WA2 v1', {
- templateId,
- error: error.message,
- response: error.response?.data || null
- })
- throw error
- }
- }
|