add notification plugins
This commit is contained in:
parent
7e15308499
commit
a8b75ca4d2
7 changed files with 123 additions and 126 deletions
|
|
@ -1,4 +1,3 @@
|
|||
require('es6-promise').polyfill()
|
||||
var fs = require('fs')
|
||||
var pgp = require('pg-promise')()
|
||||
|
||||
|
|
|
|||
48
lib/email.js
48
lib/email.js
|
|
@ -1,48 +0,0 @@
|
|||
var SMTPConnection = require('smtp-connection')
|
||||
var Config = require('./config')
|
||||
|
||||
/*
|
||||
|
||||
Nice job signing up! Let's finish getting you set up.
|
||||
Simply change the settings in your email software to these:
|
||||
SMTP Server: mail.smtp2go.com
|
||||
SMTP Port: 2525 (recommended)
|
||||
Username: josh@lamassu.is
|
||||
Password: view / edit
|
||||
*/
|
||||
|
||||
var options = {
|
||||
port: 2525,
|
||||
host: 'mail.smtp2go.com',
|
||||
requireTLS: true
|
||||
}
|
||||
|
||||
function send (from, to, subject, body, cb) {
|
||||
Config.loadConfig()
|
||||
.then(function (config) {
|
||||
var _config = config.exchanges.plugins.settings.email
|
||||
var user = _config.user
|
||||
var pass = _config.pass
|
||||
|
||||
var connection = new SMTPConnection(options)
|
||||
connection.connect(function () {
|
||||
connection.login({user: user, pass: pass}, function (err) {
|
||||
if (err) return console.error(err)
|
||||
var envelope = {
|
||||
from: from,
|
||||
to: to
|
||||
}
|
||||
var message = 'Subject: ' + subject + '\n\n' + body
|
||||
connection.send(envelope, message, function (err, info) {
|
||||
connection.quit()
|
||||
cb(err, info)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
send('josh@lamassu.is', 'joshmh@gmail.com', 'Another test', 'Screen is stale.\n\nTest4', function (err, info) {
|
||||
console.log(err)
|
||||
console.log(info)
|
||||
})
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
22
lib/sms.js
22
lib/sms.js
|
|
@ -1,22 +0,0 @@
|
|||
var Client = require('twilio')
|
||||
var Config = require('./config')
|
||||
|
||||
var toNumber = process.argv[2]
|
||||
|
||||
Config.loadConfig()
|
||||
.then(function (config) {
|
||||
var _config = config.exchanges.plugins.settings.sms
|
||||
var accountSid = _config.accountSid
|
||||
var authToken = _config.authToken
|
||||
var fromNumber = _config.fromNumber
|
||||
|
||||
var client = Client(accountSid, authToken)
|
||||
client.messages.create({
|
||||
body: '[Lamassu] ALERT Stale screen: acceptingFirstBill',
|
||||
to: toNumber,
|
||||
from: fromNumber
|
||||
}, function (err, message) {
|
||||
console.log(err)
|
||||
console.log(message)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue