add notification plugins
This commit is contained in:
parent
7e15308499
commit
a8b75ca4d2
7 changed files with 123 additions and 126 deletions
|
|
@ -29,6 +29,8 @@ var traderPlugins = {}
|
|||
var walletPlugins = {}
|
||||
var idVerifierPlugin = null
|
||||
var infoPlugin = null
|
||||
var emailPlugin = null
|
||||
var smsPlugin = null
|
||||
|
||||
var currentlyUsedPlugins = {}
|
||||
|
||||
|
|
@ -61,7 +63,8 @@ function loadPlugin (name, config) {
|
|||
trader: ['purchase', 'sell'],
|
||||
wallet: ['balance', 'sendBitcoins', 'newAddress'],
|
||||
idVerifier: ['verifyUser', 'verifyTransaction'],
|
||||
info: ['checkAddress']
|
||||
info: ['checkAddress'],
|
||||
email: ['sendMessage']
|
||||
}
|
||||
|
||||
var plugin = null
|
||||
|
|
@ -106,7 +109,7 @@ function loadPlugin (name, config) {
|
|||
'\' fails to implement *recommended* \'config\' method'))
|
||||
plugin.config = function () {}
|
||||
} else if (config !== null) {
|
||||
plugin.config(config) // only when plugin supports it, and config is passed
|
||||
plugin.config(config, logger) // only when plugin supports it, and config is passed
|
||||
}
|
||||
|
||||
return plugin
|
||||
|
|
@ -144,7 +147,9 @@ function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, currency,
|
|||
|
||||
return pluginHandle
|
||||
}
|
||||
exports.loadOrConfigPlugin = loadOrConfigPlugin
|
||||
|
||||
// Note: this whole function gets called every time there's a config update
|
||||
exports.configure = function configure (config) {
|
||||
if (config.exchanges.settings.lowBalanceMargin < 1) {
|
||||
throw new Error('\'settings.lowBalanceMargin\' has to be >= 1')
|
||||
|
|
@ -204,7 +209,18 @@ exports.configure = function configure (config) {
|
|||
infoPlugin,
|
||||
'info'
|
||||
)
|
||||
|
||||
emailPlugin = loadOrConfigPlugin(
|
||||
emailPlugin,
|
||||
'email'
|
||||
)
|
||||
|
||||
smsPlugin = loadOrConfigPlugin(
|
||||
smsPlugin,
|
||||
'sms'
|
||||
)
|
||||
}
|
||||
|
||||
exports.getConfig = function getConfig () {
|
||||
return cachedConfig
|
||||
}
|
||||
|
|
@ -613,3 +629,18 @@ exports.verifyTx = function verifyTx (data, cb) {
|
|||
exports.getcryptoCodes = function getcryptoCodes () {
|
||||
return cryptoCodes
|
||||
}
|
||||
|
||||
exports.sendMessage = function sendMessage (rec, cb) {
|
||||
console.log('DEBUG5')
|
||||
cb = cb || function () {}
|
||||
console.log(cachedConfig.exchanges.plugins.current.notify)
|
||||
var pluginTypes = JSON.parse(cachedConfig.exchanges.plugins.current.notify)
|
||||
console.log('DEBUG7')
|
||||
console.log(pluginTypes)
|
||||
var pluginPromises = pluginTypes.map(function (pluginType) {
|
||||
if (pluginType === 'email') return emailPlugin.sendMessage(rec, cb)
|
||||
if (pluginType === 'sms') return smsPlugin.sendMessage(rec, cb)
|
||||
throw new Error('No such plugin type: ' + pluginType)
|
||||
})
|
||||
return Promise.all(pluginPromises)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue