Merge remote-tracking branch 'origin/release-8.1' into release-8.6

This commit is contained in:
Rafael Taranto 2023-08-22 13:13:41 +01:00
commit 0079edb9dc
20 changed files with 970 additions and 95 deletions

View file

@ -48,6 +48,8 @@ const ALL_ACCOUNTS = [
{ code: 'mock-sms', display: 'Mock SMS', class: SMS, dev: true },
{ code: 'mock-id-verify', display: 'Mock ID verifier', class: ID_VERIFIER, dev: true },
{ code: 'twilio', display: 'Twilio', class: SMS },
{ code: 'telnyx', display: 'Telnyx', class: SMS },
{ code: 'vonage', display: 'Vonage', class: SMS },
{ code: 'mailgun', display: 'Mailgun', class: EMAIL },
{ code: 'none', display: 'None', class: ZERO_CONF, cryptos: ALL_CRYPTOS },
{ code: 'blockcypher', display: 'Blockcypher', class: ZERO_CONF, cryptos: [BTC] },

View file

@ -23,7 +23,9 @@ const SECRET_FIELDS = [
'binanceus.privateKey',
'cex.privateKey',
'binance.privateKey',
'twilio.authToken'
'twilio.authToken',
'telnyx.apiKey',
'vonage.apiSecret'
]
/*

View file

@ -1,5 +1,4 @@
const _ = require('lodash/fp')
const argv = require('minimist')(process.argv.slice(2))
const crypto = require('crypto')
const pgp = require('pg-promise')()
const dateFormat = require('dateformat')
@ -201,11 +200,9 @@ function plugins (settings, deviceId) {
const virtualCassettes = [Math.max(...denominations) * 2]
const counts = argv.cassettes
? argv.cassettes.split(',')
: _cassettes.counts
const counts = _cassettes.counts
if (_cassettes.counts.length !== denominations.length) {
if (counts.length !== denominations.length) {
throw new Error('Denominations and respective counts do not match!')
}
@ -961,7 +958,9 @@ function plugins (settings, deviceId) {
}
function getPhoneCode (phone) {
const code = argv.mockSms
const notifications = configManager.getNotifications(settings.config)
const code = notifications.thirdParty_sms === 'mock-sms'
? '123'
: randomCode()

View file

@ -0,0 +1,27 @@
const Telnyx = require('telnyx')
const NAME = 'Telnyx'
function sendMessage (account, rec) {
const telnyx = Telnyx(account.apiKey)
const from = account.fromNumber
const text = rec.sms.body
const to = rec.sms.toNumber || account.toNumber
return telnyx.messages.create({ from, to, text })
.catch(err => {
throw new Error(`Telnyx error: ${err.message}`)
})
}
function getLookup () {
throw new Error('Telnyx error: lookup not supported')
}
module.exports = {
NAME,
sendMessage,
getLookup
}

View file

@ -0,0 +1,31 @@
const { Auth } = require('@vonage/auth')
const { SMS } = require('@vonage/sms')
const NAME = 'Vonage'
function sendMessage (account, rec) {
const credentials = new Auth({
apiKey: account.apiKey,
apiSecret: account.apiSecret
})
const from = account.fromNumber
const text = rec.sms.body
const to = rec.sms.toNumber || account.toNumber
const smsClient = new SMS(credentials)
smsClient.send({ from, text, to })
.catch(err => {
throw new Error(`Vonage error: ${err.message}`)
})
}
function getLookup () {
throw new Error('Vonage error: lookup not supported')
}
module.exports = {
NAME,
sendMessage,
getLookup
}

View file

@ -0,0 +1,47 @@
const axios = require('axios')
const NAME = 'Whatsapp'
function sendMessage (account, rec) {
const phoneId = account.phoneId
const token = account.apiKey
const to = rec.sms.toNumber || account.toNumber
const template = rec.sms.template
const url = `https://graph.facebook.com/v17.0/${phoneId}/messages`
const config = {
headers:{
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json'
}
}
const data = {
messaging_product: 'whatsapp',
recipient_type: 'individual',
type: 'template',
to,
template: {
name: template,
language: { code: 'en_US' }
}
}
axios.post(url, data, config)
.catch(err => {
// console.log(err)
throw new Error(`Whatsapp error: ${err.message}`)
})
}
function getLookup () {
throw new Error('Whatsapp error: lookup not supported')
}
module.exports = {
NAME,
sendMessage,
getLookup
}

View file

@ -2,7 +2,6 @@
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')
@ -25,7 +24,8 @@ function getSms (event, phone, content) {
}
function getPlugin (settings) {
const pluginCode = argv.mockSms ? 'mock-sms' : 'twilio'
const smsProvider = settings.config.notifications_thirdParty_sms
const pluginCode = smsProvider ?? 'twilio'
const plugin = ph.load(ph.SMS, pluginCode)
const account = settings.accounts[pluginCode]