refactor: unify sms creation into a single function
This commit is contained in:
parent
ee8c46b51e
commit
ed7c515993
2 changed files with 19 additions and 31 deletions
36
lib/sms.js
36
lib/sms.js
|
|
@ -5,11 +5,18 @@ const _ = require('lodash/fp')
|
|||
|
||||
const customSms = require('./custom-sms')
|
||||
|
||||
function getPhoneCodeSms (phone, code) {
|
||||
return customSms.getCustomMessage('sms_code')
|
||||
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}]`
|
||||
})
|
||||
|
||||
function getSms (event, phone, content) {
|
||||
return customSms.getCustomMessage(event)
|
||||
.then(msg => {
|
||||
if (!_.isNil(msg)) {
|
||||
const messageContent = _.replace('#code', code, msg.message)
|
||||
var accMsg = msg.message
|
||||
const contentKeys = _.keys(content)
|
||||
const messageContent = _.reduce((acc, it) => _.replace(`#${it}`, content[it], acc), accMsg, contentKeys)
|
||||
return {
|
||||
toNumber: phone,
|
||||
body: messageContent
|
||||
|
|
@ -18,25 +25,7 @@ function getPhoneCodeSms (phone, code) {
|
|||
|
||||
return {
|
||||
toNumber: phone,
|
||||
body: `Your cryptomat code: ${code}`
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getCashOutReadySms (phone, timestamp) {
|
||||
return customSms.getCustomMessage('cash_out_dispense_ready')
|
||||
.then(msg => {
|
||||
if (!_.isNil(msg)) {
|
||||
const messageContent = _.replace('#timestamp', timestamp, msg.message)
|
||||
return {
|
||||
toNumber: phone,
|
||||
body: messageContent
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
toNumber: phone,
|
||||
body: `Your cash is waiting! Go to the Cryptomat and press Redeem within 24 hours. [${timestamp}]`
|
||||
body: getDefaultMessageContent(content)[_.camelCase(event)]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -131,8 +120,7 @@ function formatSmsReceipt (data, options) {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
getPhoneCodeSms,
|
||||
getCashOutReadySms,
|
||||
getSms,
|
||||
sendMessage,
|
||||
getLookup,
|
||||
formatSmsReceipt,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue