Added Telnyx SMS provider support. #3306

This commit is contained in:
Ylian Saint-Hilaire 2021-11-27 11:06:56 -08:00
parent 51744bb277
commit 52cee41535
4 changed files with 40 additions and 0 deletions

View File

@ -942,6 +942,15 @@
"from": { "type": "string" }
},
"required": [ "provider", "id", "token", "from" ]
},
{
"type": "object",
"properties": {
"provider": { "type": "string", "enum": [ "telnyx" ] },
"apikey": { "type": "string" },
"from": { "type": "string" }
},
"required": [ "provider", "apikey", "from" ]
}
]
}

View File

@ -3418,6 +3418,7 @@ function mainStart() {
// SMS support
if ((config.sms != null) && (config.sms.provider == 'twilio')) { modules.push('twilio'); }
if ((config.sms != null) && (config.sms.provider == 'plivo')) { modules.push('plivo'); }
if ((config.sms != null) && (config.sms.provider == 'telnyx')) { modules.push('telnyx'); }
// Setup web based push notifications
if ((typeof config.settings.webpush == 'object') && (typeof config.settings.webpush.email == 'string')) { modules.push('web-push'); }

View File

@ -30,6 +30,13 @@
"token": "xxxxxxx",
"from": "15555555555"
}
// For Telnyx, add this in config.json
"sms": {
"provider": "telnyx",
"apikey": "xxxxxxx",
"from": "15555555555"
}
*/
// Construct a MeshAgent object, called upon connection
@ -62,6 +69,15 @@ module.exports.CreateMeshSMS = function (parent) {
obj.provider = new plivo.Client(parent.config.sms.id, parent.config.sms.token);
break;
}
case 'telnyx': {
// Validate Telnyx configuration values
if (typeof parent.config.sms.apikey != 'string') { console.log('Invalid or missing SMS gateway provider apikey.'); return null; }
if (typeof parent.config.sms.from != 'string') { console.log('Invalid or missing SMS gateway provider from.'); return null; }
// Setup Telnyx
obj.provider = require('telnyx')(parent.config.sms.apikey);
break;
}
default: {
// Unknown SMS gateway provider
console.log('Unknown SMS gateway provider: ' + parent.config.sms.provider);
@ -98,6 +114,15 @@ module.exports.CreateMeshSMS = function (parent) {
if (func != null) { func(false, msg, null); }
}
);
} else if (parent.config.sms.provider == 'telnyx') { // Telnyx
obj.provider.messages.create({
from: parent.config.sms.from,
to: to,
text: msg
}, function (err, result) {
if (err != null) { parent.debug('email', 'SMS error: ' + err.type); } else { parent.debug('email', 'SMS result: ' + JSON.stringify(result)); }
if (func != null) { func((err == null), err ? err.type : null, result); }
});
}
}

View File

@ -483,5 +483,10 @@
"id": "xxxxxxx",
"token": "xxxxxxx",
"from": "1-555-555-5555"
},
"___sms": {
"provider": "telnyx",
"apikey": "xxxxxxx",
"from": "1-555-555-5555"
}
}