refactor: pull-up sms plugin getter method
This commit is contained in:
parent
a6eb4b904f
commit
8db565c609
1 changed files with 10 additions and 8 deletions
18
lib/sms.js
18
lib/sms.js
|
|
@ -1,13 +1,18 @@
|
|||
const ph = require('./plugin-helper')
|
||||
const argv = require('minimist')(process.argv.slice(2))
|
||||
|
||||
function getPlugin (settings) {
|
||||
const pluginCode = argv.mockSms ? 'mock-sms' : 'twilio'
|
||||
const plugin = ph.load(ph.SMS, pluginCode)
|
||||
const account = settings.accounts[pluginCode]
|
||||
|
||||
return { plugin, account }
|
||||
}
|
||||
|
||||
function sendMessage (settings, rec) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
const pluginCode = argv.mockSms ? 'mock-sms' : 'twilio'
|
||||
const plugin = ph.load(ph.SMS, pluginCode)
|
||||
const account = settings.accounts[pluginCode]
|
||||
|
||||
const { plugin, account } = getPlugin(settings)
|
||||
return plugin.sendMessage(account, rec)
|
||||
})
|
||||
}
|
||||
|
|
@ -15,10 +20,7 @@ function sendMessage (settings, rec) {
|
|||
function getLookup (settings, number) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
const pluginCode = argv.mockSms ? 'mock-sms' : 'twilio'
|
||||
const plugin = ph.load(ph.SMS, pluginCode)
|
||||
const account = settings.accounts[pluginCode]
|
||||
|
||||
const { plugin, account } = getPlugin(settings)
|
||||
return plugin.getLookup(account, number)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue