UNPKG

@zigasebenik/node-red-zte-sms

Version:

A Node-RED node to send sms messages using ZTE modem.

31 lines (27 loc) 975 B
module.exports = function(RED) { function ZteSmsFilterNode(config) { RED.nodes.createNode(this, config); this.config = config; this.phoneNumberWhiteList = this.config.phoneNumberWhiteList.trim().split(';').map(s => s.trim()).filter(Boolean); this.on('input', function (msg, send, done) { const output = [[], [], [], [], [], []]; const sms = Array.isArray(msg.sms) ? msg.sms : [sms]; delete msg.sms; sms.forEach((s) => { const outIndex = this.phoneNumberWhiteList.length === 0 || this.phoneNumberWhiteList.includes(s.number) ? parseInt(s.tag, 10) : 5; output[outIndex].push(s); }); output.forEach((o, i) => { if (o.length > 0) { const m = RED.util.cloneMessage(msg); m.sms = o; output[i] = m; } }); send(output); done(); }); }; RED.nodes.registerType('zte-sms-filter', ZteSmsFilterNode); };