Added Telnyx SMS provider support. #3306
Ylian Saint-Hilaire committed
Nov 27, 2021 at 11:06 UTC
52cee415351053c1b7cef4e2ba42911d2587cfa6
4 files changed
+40
meshcentral-config-schema.json
+9
@@ -942,6 +942,15 @@
942
"from": { "type": "string" }
943
},
944
"required": [ "provider", "id", "token", "from" ]
945
+ },
946
+ {
947
+ "type": "object",
948
+ "properties": {
949
+ "provider": { "type": "string", "enum": [ "telnyx" ] },
950
+ "apikey": { "type": "string" },
951
+ "from": { "type": "string" }
952
+ },
953
+ "required": [ "provider", "apikey", "from" ]
954
}
955
]
956
}
meshcentral.js
+1
@@ -3418,6 +3418,7 @@ function mainStart() {
3418
// SMS support
3419
if ((config.sms != null) && (config.sms.provider == 'twilio')) { modules.push('twilio'); }
3420
if ((config.sms != null) && (config.sms.provider == 'plivo')) { modules.push('plivo'); }
3421
+ if ((config.sms != null) && (config.sms.provider == 'telnyx')) { modules.push('telnyx'); }
3422
3423
// Setup web based push notifications
3424
if ((typeof config.settings.webpush == 'object') && (typeof config.settings.webpush.email == 'string')) { modules.push('web-push'); }
meshsms.js
+25
@@ -30,6 +30,13 @@
30
"token": "xxxxxxx",
31
"from": "15555555555"
32
}
33
+
34
+// For Telnyx, add this in config.json
35
+"sms": {
36
+ "provider": "telnyx",
37
+ "apikey": "xxxxxxx",
38
+ "from": "15555555555"
39
+}
40
*/
41
42
// Construct a MeshAgent object, called upon connection
@@ -62,6 +69,15 @@ module.exports.CreateMeshSMS = function (parent) {
69
obj.provider = new plivo.Client(parent.config.sms.id, parent.config.sms.token);
70
break;
71
}
72
+ case 'telnyx': {
73
+ // Validate Telnyx configuration values
74
+ if (typeof parent.config.sms.apikey != 'string') { console.log('Invalid or missing SMS gateway provider apikey.'); return null; }
75
+ if (typeof parent.config.sms.from != 'string') { console.log('Invalid or missing SMS gateway provider from.'); return null; }
76
+
77
+ // Setup Telnyx
78
+ obj.provider = require('telnyx')(parent.config.sms.apikey);
79
+ break;
80
+ }
81
default: {
82
// Unknown SMS gateway provider
83
console.log('Unknown SMS gateway provider: ' + parent.config.sms.provider);
@@ -98,6 +114,15 @@ module.exports.CreateMeshSMS = function (parent) {
114
if (func != null) { func(false, msg, null); }
115
}
116
);
117
+ } else if (parent.config.sms.provider == 'telnyx') { // Telnyx
118
+ obj.provider.messages.create({
119
+ from: parent.config.sms.from,
120
+ to: to,
121
+ text: msg
122
+ }, function (err, result) {
123
+ if (err != null) { parent.debug('email', 'SMS error: ' + err.type); } else { parent.debug('email', 'SMS result: ' + JSON.stringify(result)); }
124
+ if (func != null) { func((err == null), err ? err.type : null, result); }
125
+ });
126
}
127
}
128
sample-config-advanced.json
+5
@@ -483,5 +483,10 @@
483
"id": "xxxxxxx",
484
"token": "xxxxxxx",
485
"from": "1-555-555-5555"
486
+ },
487
+ "___sms": {
488
+ "provider": "telnyx",
489
+ "apikey": "xxxxxxx",
490
+ "from": "1-555-555-5555"
491
}
492
}