diff --git a/CHANGELOG.md b/CHANGELOG.md
index 31442ae..8ca5de0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+3.1.0
+==================
+* add lookup node
+
3.0.0
==================
* fixed nodes paths
diff --git a/README.md b/README.md
index 5679d63..9a3382c 100644
--- a/README.md
+++ b/README.md
@@ -1,20 +1,30 @@
-![alt text](https://www.sms77.io/wp-content/uploads/2019/07/sms77-Logo-400x79.png "sms77")
-# nodered-contrib-sms77
+![sms77 logo](https://www.sms77.io/wp-content/uploads/2019/07/sms77-Logo-400x79.png "sms77")
-Node-RED node collection for sending SMS/Text2Speech message(s) via the Sms77.io gateway.
+# nodered-contrib-sms77
+[Node-RED](http://nodered.org) node collection
+for [sending SMS](https://www.sms77.io/en/products/send-sms/)
+, [text-to-speech calls](https://www.sms77.io/en/products/voice/)
+and [number validation](https://www.sms77.io/en/products/number-validation/)
+via [sms77](https://www.sms77.io/).
## Installation
Run the following command in your Node-RED user directory - usually `~/.node-red`:
-
- - NPM
- npm install nodered-contrib-sms77
- - Yarn
- yarn add nodered-contrib-sms77
-
+**NPM**
+`npm install nodered-contrib-sms77`
+
+**Yarn**
+`yarn add nodered-contrib-sms77`
### Request Options
-Visit our API Documentation for a detailed request description.
\ No newline at end of file
+Visit our [API Documentation](https://www.sms77.io/en/docs/gateway/http-api/) for a
+detailed request description.
+
+#### Support
+
+Need help? Feel free to [contact us](https://www.sms77.io/en/company/contact/).
+
+[![MIT](https://img.shields.io/badge/License-MIT-teal.svg)](LICENSE)
diff --git a/package.json b/package.json
index f19640f..7e19450 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,7 @@
{
- "author": "sms77 e.K.",
+ "author": "sms77 e.K. (https://www.sms77.io/)",
"bugs": {
+ "email": "support@sms77.io",
"url": "https://github.com/sms77io/nodered-contrib-sms77/issues"
},
"dependencies": {
@@ -13,16 +14,20 @@
"node-red": {
"nodes": {
"sms77-config": "src/nodes/config/config.js",
+ "sms77-lookup": "src/nodes/lookup/lookup.js",
"sms77-sms": "src/nodes/sms/sms.js",
"sms77-voice": "src/nodes/voice/voice.js"
}
},
"homepage": "https://github.com/sms77io/nodered-contrib-sms77#readme",
"keywords": [
- "sms",
- "text2speech",
+ "cnam",
+ "hlr",
+ "mnp",
"node-red",
- "sms77"
+ "sms",
+ "sms77",
+ "text2speech"
],
"license": "MIT",
"repository": {
@@ -32,5 +37,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
- "version": "3.0.0"
+ "version": "3.1.0"
}
diff --git a/src/BaseMessageNode.js b/src/BaseMessageNode.js
new file mode 100644
index 0000000..9362809
--- /dev/null
+++ b/src/BaseMessageNode.js
@@ -0,0 +1,34 @@
+const globalThis = require('globalthis')()
+if (!globalThis.fetch) globalThis.fetch = require('node-fetch')
+const Util = require('./Util')
+const NodeUtil = require('./NodeUtil')
+
+module.exports = function(node, RED, config) {
+ try {
+ RED.nodes.createNode(node, config)
+
+ node.constructor.CFG = config
+ node.constructor.CLIENT = Util.initClient(
+ RED.nodes.getNode(config.config).credentials.apiKey)
+
+ node.status({fill: 'blue', shape: 'ring', text: `${node.name} connected`})
+
+ node._done = (done, error, msg) => done
+ ? done(error) // Use done if defined (1.0+)
+ : node.error(error, msg) // Fallback to node.error (pre-1.0)
+
+ node._util = new NodeUtil(node)
+
+ node._emptyStringFallback = node._util.emptyStringFallback
+
+ node._errorHandler = (done, msg) => node._util.errorHandler(done, msg)
+
+ node._onSuccess = node._util.onSuccess
+
+ node.on('input', node._util.onInput)
+ } catch (err) {
+ console.log({err})
+
+ node.error(err)
+ }
+}
diff --git a/src/BaseNode.js b/src/BaseNode.js
deleted file mode 100644
index 90cf659..0000000
--- a/src/BaseNode.js
+++ /dev/null
@@ -1,61 +0,0 @@
-const globalThis = require('globalthis')()
-const Sms77Client = require('sms77-client')
-
-if (!globalThis.fetch) globalThis.fetch = require('node-fetch')
-
-module.exports = function(node, RED, config) {
- try {
- RED.nodes.createNode(node, config)
-
- node.constructor.CFG = config
- node.constructor.CLIENT = new Sms77Client(
- RED.nodes.getNode(config.config).credentials.apiKey,
- 'node-red')
-
- node.status({
- fill: 'blue',
- shape: 'ring',
- text: `${node.name} connected`,
- })
-
- node._done = (done, error, msg) => done
- ? done(error) // Use done if defined (1.0+)
- : node.error(error, msg) // Fallback to node.error (pre-1.0)
-
- node._emptyStringFallback = (key, value = null) => {
- if (!key in node.constructor.CFG) return value
-
- return '' === (node.constructor.CFG[key] || '')
- ? value
- : node.constructor.CFG[key]
- }
-
- node._errorHandler = (done, msg) => err => {
- err = err.toString ? err.toString() : JSON.stringify(err)
-
- return node._done(done, err, msg)
- }
-
- node._onSuccess = (sent, failed, send, msg, payload, done) => {
- node.status({
- fill: 'yellow',
- shape: 'dot',
- text: `${sent} sent | ${failed} failed`,
- })
-
- send({...msg, payload})
-
- if (done) done() // Check done exists (1.0+)
- }
-
- node.on('input', async (msg, send, done) => {
- send = send ? send : () => node.send.apply(node, arguments) // If this is pre-1.0, 'send' will be undefined, so fallback to node.send
-
- await node._onInput(msg, send, done)
- })
- } catch (err) {
- console.log({err})
-
- node.error(err)
- }
-}
diff --git a/src/NodeUtil.js b/src/NodeUtil.js
new file mode 100644
index 0000000..1132d50
--- /dev/null
+++ b/src/NodeUtil.js
@@ -0,0 +1,32 @@
+const Util = require('./Util')
+
+module.exports = class NodeUtil {
+ constructor(node) {
+ this.node = node
+ }
+
+ emptyStringFallback = (key, value = null) => {
+ const cfg = this.node.constructor.CFG
+ if (!key in cfg) return value
+ return '' === (cfg[key] || '') ? value : cfg[key]
+ }
+
+ status = (text, fill = 'yellow', shape = 'dot') => {
+ this.node.status({fill, shape, text})
+ }
+
+ onSuccess = (sent, failed, send, msg, payload, done) => {
+ this.status(`${sent} sent | ${failed} failed`)
+ send({...msg, payload})
+ if (done) done() // Check done exists (1.0+)
+ }
+
+ onInput = async (msg, send, done) => {
+ if (!send) send = () => this.node.send.apply(this.node, [msg, send, done]) // If this is pre-1.0, 'send' will be undefined, so fallback to node.send
+ await this.node._onInput(msg, send, done)
+ }
+
+ errorHandler = (done, msg) => {
+ return e => this.node._done(done, Util.stringify(e), msg)
+ }
+}
diff --git a/src/Util.js b/src/Util.js
new file mode 100644
index 0000000..0b3ac2f
--- /dev/null
+++ b/src/Util.js
@@ -0,0 +1,13 @@
+const Sms77Client = require('sms77-client')
+
+module.exports = class Util {
+ static initClient(apiKey) {
+ return new Sms77Client(apiKey, 'node-red')
+ }
+
+ static stringify(value) {
+ if (typeof value === 'string') return value
+ if (typeof value.toString === 'function') return value.toString()
+ return JSON.stringify(value)
+ }
+}
diff --git a/src/nodes/lookup/locales/en/lookup.html b/src/nodes/lookup/locales/en/lookup.html
new file mode 100644
index 0000000..4b183d3
--- /dev/null
+++ b/src/nodes/lookup/locales/en/lookup.html
@@ -0,0 +1,17 @@
+
diff --git a/src/nodes/lookup/locales/en/lookup.json b/src/nodes/lookup/locales/en/lookup.json
new file mode 100644
index 0000000..5c6cf27
--- /dev/null
+++ b/src/nodes/lookup/locales/en/lookup.json
@@ -0,0 +1,11 @@
+{
+ "sms77-lookup": {
+ "cnam": "CNAM",
+ "config": "Config",
+ "format": "Format",
+ "hlr": "HLR",
+ "json": "Return JSON?",
+ "mnp": "MNP",
+ "type": "Type"
+ }
+}
diff --git a/src/nodes/lookup/lookup.html b/src/nodes/lookup/lookup.html
new file mode 100644
index 0000000..0b26582
--- /dev/null
+++ b/src/nodes/lookup/lookup.html
@@ -0,0 +1,68 @@
+
+
+
diff --git a/src/nodes/lookup/lookup.js b/src/nodes/lookup/lookup.js
new file mode 100644
index 0000000..e1e6701
--- /dev/null
+++ b/src/nodes/lookup/lookup.js
@@ -0,0 +1,31 @@
+const BaseNode = require('../../BaseMessageNode')
+const Util = require('../../Util')
+
+module.exports = function(RED) {
+ 'use strict'
+
+ class Sms77LookupNode {
+ constructor(config) {
+ BaseNode(this, RED, config)
+ }
+
+ async _onInput(msg, send, done) {
+ const params = {
+ json: 'true' === Sms77LookupNode.CFG.json,
+ number: this._emptyStringFallback('numbers', msg.topic),
+ type: Sms77LookupNode.CFG.lookupType,
+ }
+
+ try {
+ const response = await Sms77LookupNode.CLIENT.lookup(params)
+ this._util.status(Util.stringify(response))
+ send({...msg})
+ if (done) done() // Check done exists (1.0+)
+ } catch (e) {
+ this._errorHandler(done, msg)
+ }
+ }
+ }
+
+ RED.nodes.registerType('sms77-lookup', Sms77LookupNode)
+}
diff --git a/src/nodes/sms/sms.html b/src/nodes/sms/sms.html
index 5c57031..7c515ec 100644
--- a/src/nodes/sms/sms.html
+++ b/src/nodes/sms/sms.html
@@ -1,84 +1,82 @@