chore: server code formatting

This commit is contained in:
Rafael Taranto 2025-05-12 15:35:00 +01:00
parent aedabcbdee
commit 68517170e2
234 changed files with 9824 additions and 6195 deletions

View file

@ -1,46 +1,47 @@
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
}
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

@ -2,7 +2,7 @@ const _ = require('lodash/fp')
const NAME = 'MockSMS'
function sendMessage (account, rec) {
function sendMessage(account, rec) {
console.log('Sending SMS: %j', rec)
return new Promise((resolve, reject) => {
if (_.endsWith('666', _.getOr(false, 'sms.toNumber', rec))) {
@ -15,5 +15,5 @@ function sendMessage (account, rec) {
module.exports = {
NAME,
sendMessage
sendMessage,
}

View file

@ -2,20 +2,19 @@ const Telnyx = require('telnyx')
const NAME = 'Telnyx'
function sendMessage (account, rec) {
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}`)
})
return telnyx.messages.create({ from, to, text }).catch(err => {
throw new Error(`Telnyx error: ${err.message}`)
})
}
module.exports = {
NAME,
sendMessage
sendMessage,
}

View file

@ -3,10 +3,12 @@ const _ = require('lodash/fp')
const NAME = 'Twilio'
const BAD_NUMBER_CODES = [21201, 21202, 21211, 21214, 21216, 21217, 21219, 21408,
21610, 21612, 21614, 21608]
const BAD_NUMBER_CODES = [
21201, 21202, 21211, 21214, 21216, 21217, 21219, 21408, 21610, 21612, 21614,
21608,
]
function sendMessage (account, rec) {
function sendMessage(account, rec) {
return Promise.resolve()
.then(() => {
// to catch configuration errors like
@ -14,14 +16,16 @@ function sendMessage (account, rec) {
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 from =
_.startsWith('+')(account.fromNumber) ||
!_.isNumber(String(account.fromNumber).replace(/\s/g, ''))
? account.fromNumber
: `+${account.fromNumber}`
const opts = {
body: body,
to: _toNumber,
from
from,
}
return client.messages.create(opts)
@ -39,5 +43,5 @@ function sendMessage (account, rec) {
module.exports = {
NAME,
sendMessage
sendMessage,
}

View file

@ -3,10 +3,10 @@ const { SMS } = require('@vonage/sms')
const NAME = 'Vonage'
function sendMessage (account, rec) {
function sendMessage(account, rec) {
const credentials = new Auth({
apiKey: account.apiKey,
apiSecret: account.apiSecret
apiSecret: account.apiSecret,
})
const from = account.fromNumber
@ -14,10 +14,9 @@ function sendMessage (account, rec) {
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}`)
})
smsClient.send({ from, text, to }).catch(err => {
throw new Error(`Vonage error: ${err.message}`)
})
}
module.exports = {

View file

@ -1,42 +1,41 @@
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
}
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,
}