diff --git a/.env.example b/.env.example index 61be1ad..5077517 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ AMQP_SERVER=amqp://localhost -QUEUE_NAME= +QUEUE_NOTA= +QUEUE_PAYLATER= SENDER_EMAIL= SENDER_NAME= SENDING_BLUE_API_KEY= \ No newline at end of file diff --git a/index.mjs b/index.mjs index 440db92..f96915e 100644 --- a/index.mjs +++ b/index.mjs @@ -8,15 +8,9 @@ import dotenv from 'dotenv' dotenv.config() 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 mailTransporter = nodemailer.createTransport({ -// service: 'gmail', -// auth: { -// user: process.env.TRANS_NAME, -// pass: process.env.TRANS_PASS -// } -// }) var defaultClient = SibApiV3Sdk.ApiClient.instance var apiKey = defaultClient.authentications['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=> { 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()) console.log(`[*] Message Received! email : ${messageBody.email} and pesan : ${messageBody.html}`) sendReceipt(messageBody.email, messageBody.html) }, { noAck: true }) }).then(() => { - console.log('* Waiting for messages from queue ' + queueName) + console.log('* Waiting for messages from queue ' + queueNota) }) } }).catch(console.warn) @@ -61,22 +56,4 @@ function sendReceipt(recepientEmail, receipt) { }, function(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")