chore: use monorepo organization

This commit is contained in:
Rafael Taranto 2025-05-12 10:52:54 +01:00
parent deaf7d6ecc
commit a687827f7e
1099 changed files with 8184 additions and 11535 deletions

View file

@ -0,0 +1,46 @@
const axios = require('axios')
const NAME = 'InforU'
function sendMessage (account, rec) {
const username = account.username
const apiKey = account.apiKey
const to = rec.sms.toNumber || account.toNumber
const text = rec.sms.body
const from = account.fromNumber
const url = 'https://capi.inforu.co.il/api/v2/SMS/SendSms'
const config = {
auth: {
username: username,
password: apiKey
},
maxBodyLength: Infinity,
headers:{
'Content-Type': 'application/json'
}
}
const data = {
Message: text,
Recipients: [{
Phone: to
}],
Settings: {
Sender: from
}
}
axios.post(url, data, config)
.catch(err => {
// console.log(err)
throw new Error(`inforu error: ${err.message}`)
})
}
module.exports = {
NAME,
sendMessage
}

View file

@ -0,0 +1,19 @@
const _ = require('lodash/fp')
const NAME = 'MockSMS'
function sendMessage (account, rec) {
console.log('Sending SMS: %j', rec)
return new Promise((resolve, reject) => {
if (_.endsWith('666', _.getOr(false, 'sms.toNumber', rec))) {
reject(new Error(`${exports.NAME} mocked error!`))
} else {
setTimeout(resolve, 10)
}
})
}
module.exports = {
NAME,
sendMessage
}

View file

@ -0,0 +1,21 @@
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}`)
})
}
module.exports = {
NAME,
sendMessage
}

View file

@ -0,0 +1,43 @@
const twilio = require('twilio')
const _ = require('lodash/fp')
const NAME = 'Twilio'
const BAD_NUMBER_CODES = [21201, 21202, 21211, 21214, 21216, 21217, 21219, 21408,
21610, 21612, 21614, 21608]
function sendMessage (account, rec) {
return Promise.resolve()
.then(() => {
// to catch configuration errors like
// "Error: username is required"
const client = twilio(account.accountSid, account.authToken)
const body = rec.sms.body
const _toNumber = rec.sms.toNumber || account.toNumber
const from = (_.startsWith('+')(account.fromNumber)
|| !_.isNumber(String(account.fromNumber).replace(/\s/g,'')))
? account.fromNumber : `+${account.fromNumber}`
const opts = {
body: body,
to: _toNumber,
from
}
return client.messages.create(opts)
})
.catch(err => {
if (_.includes(err.code, BAD_NUMBER_CODES)) {
const badNumberError = new Error(err.message)
badNumberError.name = 'BadNumberError'
throw badNumberError
}
throw new Error(`Twilio error: ${err.message}`)
})
}
module.exports = {
NAME,
sendMessage
}

View file

@ -0,0 +1,26 @@
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}`)
})
}
module.exports = {
NAME,
sendMessage,
}

View file

@ -0,0 +1,42 @@
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}`)
})
}
module.exports = {
NAME,
sendMessage
}