Migrate plugins to lib directory
This commit is contained in:
parent
09b29bba56
commit
e7ab8223c2
27 changed files with 869 additions and 858 deletions
34
lib/plugins/sms/twilio/schema.json
Normal file
34
lib/plugins/sms/twilio/schema.json
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"code": "twilio",
|
||||
"display": "Twilio",
|
||||
"fields": [
|
||||
{
|
||||
"code": "accountSid",
|
||||
"display": "Account SID",
|
||||
"fieldType": "string",
|
||||
"required": true,
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"code": "authToken",
|
||||
"display": "Auth token",
|
||||
"fieldType": "password",
|
||||
"required": true,
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"code": "fromNumber",
|
||||
"display": "From number",
|
||||
"fieldType": "string",
|
||||
"required": true,
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"code": "toNumber",
|
||||
"display": "To number",
|
||||
"fieldType": "string",
|
||||
"required": true,
|
||||
"value": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
33
lib/plugins/sms/twilio/twilio.js
Normal file
33
lib/plugins/sms/twilio/twilio.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
const Client = 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) {
|
||||
const client = Client(account.accountSid, account.authToken)
|
||||
const body = rec.sms.body
|
||||
const _toNumber = rec.sms.toNumber || account.toNumber
|
||||
|
||||
return client.sendMessage({
|
||||
body: body,
|
||||
to: _toNumber,
|
||||
from: account.fromNumber
|
||||
})
|
||||
.catch(err => {
|
||||
if (_.includes(err.code, BAD_NUMBER_CODES)) {
|
||||
const badNumberError = new Error(err.message)
|
||||
badNumberError.name = 'BadNumberError'
|
||||
throw badNumberError
|
||||
}
|
||||
|
||||
throw new Error(err.message)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
NAME,
|
||||
sendMessage
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue