Merge pull request #1693 from siiky/fix/lam-969/message
LAM-969 fix: add machine name and timestamp to pending notifs messages
This commit is contained in:
commit
89160f623a
2 changed files with 7 additions and 6 deletions
|
|
@ -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}`))
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue