fix: compliance notifications through sms and email
This commit is contained in:
parent
6537938ec3
commit
129e5555df
2 changed files with 48 additions and 2 deletions
|
|
@ -166,6 +166,51 @@ function transactionNotify (tx, rec) {
|
|||
})
|
||||
}
|
||||
|
||||
function complianceNotify (customer, deviceId, ...args) {
|
||||
return Promise.all([
|
||||
settingsLoader.loadLatest(),
|
||||
queries.getMachineName(deviceId)
|
||||
])
|
||||
.then(([settings, machineName]) => {
|
||||
const notifications = configManager.getGlobalNotifications(settings.config)
|
||||
|
||||
const action = args[0]
|
||||
const period = args[1]
|
||||
|
||||
const msgCore = {
|
||||
BLOCKED: `was blocked`,
|
||||
SUSPENDED: `was suspended for ${!!period && period} days`
|
||||
}
|
||||
|
||||
const rec = {
|
||||
sms: {
|
||||
body: `Customer ${customer.phone} ${msgCore[action]} - ${machineName}`
|
||||
},
|
||||
email: {
|
||||
subject: `Customer compliance`,
|
||||
body: `Customer ${customer.phone} ${msgCore[action]} in machine ${machineName}`
|
||||
}
|
||||
}
|
||||
|
||||
const promises = []
|
||||
|
||||
const emailActive =
|
||||
notifications.email.active &&
|
||||
notifications.email.compliance
|
||||
|
||||
const smsActive =
|
||||
notifications.sms.active &&
|
||||
notifications.sms.compliance
|
||||
|
||||
if (emailActive) promises.push(emailFuncs.sendMessage(settings, rec))
|
||||
if (smsActive) promises.push(smsFuncs.sendMessage(settings, rec))
|
||||
|
||||
notifyIfActive('compliance', 'customerComplianceNotify', customer, deviceId, ...args)
|
||||
|
||||
return Promise.all(promises)
|
||||
})
|
||||
}
|
||||
|
||||
function sendRedemptionMessage (txId, error) {
|
||||
const subject = `Here's an update on transaction ${txId}`
|
||||
const body = error
|
||||
|
|
@ -216,6 +261,7 @@ const notifyIfActive = (type, fnName, ...args) => {
|
|||
|
||||
module.exports = {
|
||||
transactionNotify,
|
||||
complianceNotify,
|
||||
checkNotification,
|
||||
checkPings,
|
||||
checkStuckScreen,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue