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

@ -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
}