diff --git a/meshcentral-config-schema.json b/meshcentral-config-schema.json index af01f912..f36a46f2 100644 --- a/meshcentral-config-schema.json +++ b/meshcentral-config-schema.json @@ -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" ] } ] } diff --git a/meshcentral.js b/meshcentral.js index 530cb53e..de1a8573 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -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'); } diff --git a/meshsms.js b/meshsms.js index a132f087..8de5eeb1 100644 --- a/meshsms.js +++ b/meshsms.js @@ -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); } + }); } } diff --git a/sample-config-advanced.json b/sample-config-advanced.json index 8511b69b..3b958922 100644 --- a/sample-config-advanced.json +++ b/sample-config-advanced.json @@ -483,5 +483,10 @@ "id": "xxxxxxx", "token": "xxxxxxx", "from": "1-555-555-5555" + }, + "___sms": { + "provider": "telnyx", + "apikey": "xxxxxxx", + "from": "1-555-555-5555" } }