feat: add sms preview

feat: add reset to default button
feat: add attachable values
feat: connect the sms receipt notice to the sms receipt request
This commit is contained in:
Sérgio Salgado 2022-02-10 00:36:32 +00:00
parent 91e209b6ab
commit cd01d894a3
10 changed files with 186 additions and 69 deletions

View file

@ -1,13 +1,13 @@
const customSms = require('../../../sms-notices')
const smsNotices = require('../../../sms-notices')
const resolvers = {
Query: {
SMSNotices: () => customSms.getSMSNotices()
SMSNotices: () => smsNotices.getSMSNotices()
},
Mutation: {
editSMSNotice: (...[, { id, event, message }]) => customSms.editSMSNotice(id, event, message),
enableSMSNotice: (...[, { id }]) => customSms.enableSMSNotice(id),
disableSMSNotice: (...[, { id }]) => customSms.disableSMSNotice(id)
editSMSNotice: (...[, { id, event, message }]) => smsNotices.editSMSNotice(id, event, message),
enableSMSNotice: (...[, { id }]) => smsNotices.enableSMSNotice(id),
disableSMSNotice: (...[, { id }]) => smsNotices.disableSMSNotice(id)
}
}

View file

@ -772,7 +772,8 @@ function plugins (settings, deviceId) {
? '123'
: randomCode()
return sms.getSms(CONFIRMATION_CODE, phone, { code })
const timestamp = dateFormat(new Date(), 'UTC:HH:MM Z')
return sms.getSms(CONFIRMATION_CODE, phone, { code, timestamp })
.then(smsObj => {
const rec = {
sms: smsObj

View file

@ -9,7 +9,7 @@ const NAME = 'FakeWallet'
const SECONDS = 1000
const PUBLISH_TIME = 3 * SECONDS
const AUTHORIZE_TIME = PUBLISH_TIME + 5 * SECONDS
const CONFIRM_TIME = AUTHORIZE_TIME + 120 * SECONDS
const CONFIRM_TIME = AUTHORIZE_TIME + 10 * SECONDS
let t0

View file

@ -190,6 +190,6 @@ router.patch('/:id/block', triggerBlock)
router.patch('/:id/suspend', triggerSuspend)
router.patch('/:id/photos/idcarddata', updateIdCardData)
router.patch('/:id/:txId/photos/customerphoto', updateTxCustomerPhoto)
router.patch('/:id/smsreceipt', sendSmsReceipt)
router.post('/:id/smsreceipt', sendSmsReceipt)
module.exports = router

View file

@ -36,12 +36,12 @@ const getSMSNotice = event => {
}
const enableSMSNotice = id => {
const sql = `UPDATE sms_notices SET enabled = true WHERE id=$1 LIMIT 1`
const sql = `UPDATE sms_notices SET enabled = true WHERE id=$1`
return db.oneOrNone(sql, [id])
}
const disableSMSNotice = id => {
const sql = `UPDATE sms_notices SET enabled = false WHERE id=$1 LIMIT 1`
const sql = `UPDATE sms_notices SET enabled = false WHERE id=$1`
return db.oneOrNone(sql, [id])
}

View file

@ -1,17 +1,16 @@
const dateFormat = require('dateformat')
const ph = require('./plugin-helper')
const argv = require('minimist')(process.argv.slice(2))
const { utils: coinUtils } = require('lamassu-coins')
const _ = require('lodash/fp')
const customSms = require('./sms-notices')
const getDefaultMessageContent = content => ({
smsCode: `Your cryptomat code: ${content.code}`,
cashOutDispenseReady: `Your cash is waiting! Go to the Cryptomat and press Redeem within 24 hours. [${content.timestamp}]`
})
const smsNotices = require('./sms-notices')
const { RECEIPT } = require('./constants')
function getSms (event, phone, content) {
return customSms.getCustomMessage(event)
return smsNotices.getSMSNotice(event)
.then(msg => {
if (!_.isNil(msg)) {
var accMsg = msg.message
@ -22,11 +21,6 @@ function getSms (event, phone, content) {
body: messageContent
}
}
return {
toNumber: phone,
body: getDefaultMessageContent(content)[_.camelCase(event)]
}
})
}
@ -110,13 +104,16 @@ function formatSmsReceipt (data, options) {
message = message.concat(`Address: ${data.address}\n`)
}
const request = {
sms: {
toNumber: data.customerPhone,
body: message
}
}
return request
const timestamp = dateFormat(new Date(), 'UTC:HH:MM Z')
const postReceiptSmsPromise = getSms(RECEIPT, data.customerPhone, { timestamp })
return Promise.all([smsNotices.getSMSNotice(RECEIPT), postReceiptSmsPromise])
.then(([res, postReceiptSms]) => ({
sms: {
toNumber: data.customerPhone,
body: res.enabled ? message.concat('\n\n', postReceiptSms.body) : message
}
}))
}
module.exports = {