fix: add machine name and timestamp to pending notifs messages

This commit is contained in:
siiky 2024-06-28 16:24:36 +01:00
parent 2c8ab635a7
commit e7f37a4b5b
2 changed files with 7 additions and 6 deletions

View file

@ -167,6 +167,7 @@ function transactionNotify (tx, rec) {
}
function complianceNotify (settings, customer, deviceId, action, period) {
const timestamp = (new Date()).toLocaleString()
return queries.getMachineName(deviceId)
.then(machineName => {
const notifications = configManager.getGlobalNotifications(settings.config)
@ -179,15 +180,15 @@ function complianceNotify (settings, customer, deviceId, action, period) {
const rec = {
sms: {
body: `Customer ${customer.phone} ${msgCore[action]} - ${machineName}`
body: `Customer ${customer.phone} ${msgCore[action]} - ${machineName}. ${timestamp}`
},
email: {
subject: `Customer compliance`,
body: `Customer ${customer.phone} ${msgCore[action]} in machine ${machineName}`
body: `Customer ${customer.phone} ${msgCore[action]} in machine ${machineName}. ${timestamp}`
},
webhook: {
topic: `Customer compliance`,
content: `Customer ${customer.phone} ${msgCore[action]} in machine ${machineName}`
content: `Customer ${customer.phone} ${msgCore[action]} in machine ${machineName}. ${timestamp}`
}
}
@ -207,7 +208,7 @@ function complianceNotify (settings, customer, deviceId, action, period) {
if (smsActive) promises.push(smsFuncs.sendMessage(settings, rec))
if (webhookActive) promises.push(webhookFuncs.sendMessage(settings, rec))
notifyIfActive('compliance', 'customerComplianceNotify', customer, deviceId, action, period)
notifyIfActive('compliance', 'customerComplianceNotify', customer, deviceId, action, machineName, period)
return Promise.all(promises)
.catch(err => console.error(`An error occurred when sending a notification. Please check your notification preferences and 3rd party account configuration: ${err.stack}`))

View file

@ -31,7 +31,7 @@ const clearOldCustomerSuspendedNotifications = (customerId, deviceId) => {
return queries.invalidateNotification(detailB, 'compliance')
}
const customerComplianceNotify = (customer, deviceId, code, days = null) => {
const customerComplianceNotify = (customer, deviceId, code, machineName, days = null) => {
// code for now can be "BLOCKED", "SUSPENDED"
const detailB = utils.buildDetail({ customerId: customer.id, code, deviceId })
const date = new Date()
@ -40,7 +40,7 @@ const customerComplianceNotify = (customer, deviceId, code, days = null) => {
}
const message = code === 'SUSPENDED' ? `Customer ${customer.phone} suspended until ${date.toLocaleString()}` :
code === 'BLOCKED' ? `Customer ${customer.phone} blocked` :
`Customer ${customer.phone} has pending compliance`
`Customer ${customer.phone} has pending compliance in machine ${machineName}`
return clearOldCustomerSuspendedNotifications(customer.id, deviceId)
.then(() => queries.getValidNotifications(COMPLIANCE, detailB))