|
|
@@ -8,15 +8,9 @@ import dotenv from 'dotenv' |
|
|
dotenv.config() |
|
|
dotenv.config() |
|
|
|
|
|
|
|
|
const app = express() |
|
|
const app = express() |
|
|
const queueName = process.env.QUEUE_NAME |
|
|
|
|
|
|
|
|
const queuePaylater = process.env.QUEUE_PAYLATER |
|
|
|
|
|
const queueNota = process.env.QUEUE_NOTA |
|
|
const senderEmail = process.env.SENDER_EMAIL |
|
|
const senderEmail = process.env.SENDER_EMAIL |
|
|
// const mailTransporter = nodemailer.createTransport({ |
|
|
|
|
|
// service: 'gmail', |
|
|
|
|
|
// auth: { |
|
|
|
|
|
// user: process.env.TRANS_NAME, |
|
|
|
|
|
// pass: process.env.TRANS_PASS |
|
|
|
|
|
// } |
|
|
|
|
|
// }) |
|
|
|
|
|
var defaultClient = SibApiV3Sdk.ApiClient.instance |
|
|
var defaultClient = SibApiV3Sdk.ApiClient.instance |
|
|
var apiKey = defaultClient.authentications['api-key'] |
|
|
var apiKey = defaultClient.authentications['api-key'] |
|
|
apiKey.apiKey = process.env.SENDING_BLUE_API_KEY |
|
|
apiKey.apiKey = process.env.SENDING_BLUE_API_KEY |
|
|
@@ -32,16 +26,17 @@ app.get('/', (_req, res) => { |
|
|
|
|
|
|
|
|
amqp.connect(process.env.AMQP_SERVER).then(async conn=> { |
|
|
amqp.connect(process.env.AMQP_SERVER).then(async conn=> { |
|
|
const ch = await conn.createChannel() |
|
|
const ch = await conn.createChannel() |
|
|
const queue = ch.assertQueue(queueName, { durable: true }) |
|
|
|
|
|
if (queue) { |
|
|
|
|
|
queue.then(() => { |
|
|
|
|
|
return ch.consume(queueName, async (msg) => { |
|
|
|
|
|
|
|
|
const queuePaylaterExist = ch.assertQueue(queuePaylater, { durable : true }); |
|
|
|
|
|
const queueNotaExist = ch.assertQueue(queueNota, { durable: true }) |
|
|
|
|
|
if (queueNotaExist) { |
|
|
|
|
|
queueNotaExist.then(() => { |
|
|
|
|
|
return ch.consume(queueNota, async (msg) => { |
|
|
var messageBody = JSON.parse(msg.content.toString()) |
|
|
var messageBody = JSON.parse(msg.content.toString()) |
|
|
console.log(`[*] Message Received! email : ${messageBody.email} and pesan : ${messageBody.html}`) |
|
|
console.log(`[*] Message Received! email : ${messageBody.email} and pesan : ${messageBody.html}`) |
|
|
sendReceipt(messageBody.email, messageBody.html) |
|
|
sendReceipt(messageBody.email, messageBody.html) |
|
|
}, { noAck: true }) |
|
|
}, { noAck: true }) |
|
|
}).then(() => { |
|
|
}).then(() => { |
|
|
console.log('* Waiting for messages from queue ' + queueName) |
|
|
|
|
|
|
|
|
console.log('* Waiting for messages from queue ' + queueNota) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
}).catch(console.warn) |
|
|
}).catch(console.warn) |
|
|
@@ -61,22 +56,4 @@ function sendReceipt(recepientEmail, receipt) { |
|
|
}, function(error) { |
|
|
}, function(error) { |
|
|
console.error(error) |
|
|
console.error(error) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// ============ GMAIL's ============ |
|
|
|
|
|
// var nodemailerOptions = { |
|
|
|
|
|
// from: process.env.SENDER_EMAIL, |
|
|
|
|
|
// to: receiverEmail, |
|
|
|
|
|
// subject: "Nota " + date.toLocaleDateString(), |
|
|
|
|
|
// text: receiptToSend |
|
|
|
|
|
// } |
|
|
|
|
|
// mailTransporter.sendMail(nodemailerOptions, function(err, info) { |
|
|
|
|
|
// if (err) { |
|
|
|
|
|
// console.log(err.message) |
|
|
|
|
|
// } |
|
|
|
|
|
// if (info) { |
|
|
|
|
|
// console.log(`Email sent!` + " | " +today.toLocaleTimeString("id")) |
|
|
|
|
|
// } |
|
|
|
|
|
// }) |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// sendReceipt("michael.pandu270@gmail.com", "Berikut detail nota terbaru anda") |
|
|
|