feat: add Telnyx sms support

This commit is contained in:
Taranto 2023-07-30 11:43:33 +01:00
parent 7307466df4
commit e8a3d2ed11
8 changed files with 409 additions and 39 deletions

View file

@ -48,6 +48,7 @@ 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: '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,8 @@ const SECRET_FIELDS = [
'binanceus.privateKey',
'cex.privateKey',
'binance.privateKey',
'twilio.authToken'
'twilio.authToken',
'telnyx.apiKey'
]
/*

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

@ -25,7 +25,7 @@ function getSms (event, phone, content) {
}
function getPlugin (settings) {
const pluginCode = argv.mockSms ? 'mock-sms' : 'twilio'
const pluginCode = argv.mockSms ? 'mock-sms' : argv.telnyxSms ? 'telnyx' : 'twilio'
const plugin = ph.load(ph.SMS, pluginCode)
const account = settings.accounts[pluginCode]