Skip to content

Commit 03de4c5

Browse files
committed
fix stringifed null params; fix wrong context when using multiple nodes of same type
1 parent bdd0ac2 commit 03de4c5

File tree

11 files changed

+166
-152
lines changed

11 files changed

+166
-152
lines changed

.idea/php.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
3.3.0
2+
==================
3+
* use empty string for unset parameters
4+
* fix wrong context when using multiple nodes of the same type
5+
* bump sms77-client to ^2.25.0
6+
17
3.2.0
28
==================
39
* add missing translations

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

3-
Copyright (c) 2020-present sms77 e.K.
3+
Copyright (c) 2020-2022 sms77 e.K.
4+
Copyright (c) 2023-present seven communications GmbH & Co. KG
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
![](https://www.sms77.io/wp-content/uploads/2019/07/sms77-Logo-400x79.png "sms77 logo")
1+
![](https://www.seven.io/wp-content/uploads/Logo.svg "seven Logo")
22

3-
# nodered-contrib-sms77
3+
# Official seven nodes for Node-RED
44

55
[Node-RED](http://nodered.org) node collection
6-
for [sending SMS](https://www.sms77.io/en/products/send-sms/)
7-
, [text-to-speech calls](https://www.sms77.io/en/products/voice/)
8-
and [number validation](https://www.sms77.io/en/products/number-validation/)
9-
via [sms77](https://www.sms77.io/).
6+
for [sending SMS](https://www.seven.io/en/products/send-sms/)
7+
, [text-to-speech calls](https://www.seven.io/en/products/voice/)
8+
and [number validation](https://www.seven.io/en/products/number-validation/)
9+
via [seven](https://www.seven.io/).
1010

1111
## Installation
1212

@@ -22,8 +22,8 @@ Run the following command in your Node-RED user directory - usually `~/.node-red
2222

2323
### sms77-config node
2424

25-
*API Key*: An API key from sms77 - create one in
26-
your [developer dashboard](https://app.sms77.io/developer).
25+
*API Key*: An API key from [seven](https://help.seven.io/en/api-key-access) - create one in
26+
your [developer dashboard](https://app.seven.io/developer).
2727

2828
*Name*: An arbitrary name for the node, helpful if you use multiple configurations.
2929

@@ -39,7 +39,7 @@ Use this node for sending SMS.
3939
*From (Sender)*: Set a custom sender identifier.
4040

4141
*Label*: Set a custom label for
42-
sorting [analytics](https://www.sms77.io/en/docs/gateway/http-api/analytics/).
42+
sorting [analytics](https://www.seven.io/en/docs/gateway/http-api/analytics/).
4343

4444
*Foreign ID*: Optionally set a custom value returned in callbacks.
4545

@@ -54,7 +54,7 @@ date/time string formatted as yyyy-mm-dd hh:ii.
5454

5555
*Unicode?*: If enabled, enforce unicode encoding ignoring API detection.
5656

57-
*Flash?*: If enabled, SMS get sent as [flash](https://help.sms77.io/en/flash-sms).
57+
*Flash?*: If enabled, SMS get sent as [flash](https://help.seven.io/en/flash-sms).
5858

5959
*Details?*: If enabled, the API returns dispatch specific information - is ignored
6060
if `json` is enabled.
@@ -68,7 +68,7 @@ testing.
6868
seconds, gets allowed.
6969

7070
*Performance Tracking?*: If enabled, links found in the text get replaced with a shortened
71-
URL and [click tracking](https://help.sms77.io/en/performance-tracking-1) enabled.
71+
URL and [click tracking](https://help.seven.io/en/performance-tracking-1) enabled.
7272

7373
*Name*: An arbitrary name for the node helpful for identification.
7474

@@ -84,8 +84,8 @@ Use this node for converting a text to speech, call a number and read the messag
8484
.
8585

8686
*From (Caller)*: The caller identifier which must be your
87-
own [virtual number](https://help.sms77.io/en/ordering-your-own-number) or
88-
a [shared number](https://www.sms77.io/en/docs/glossary/shared-numbers/).
87+
own [virtual number](https://help.seven.io/en/ordering-your-own-number) or
88+
a [shared number](https://www.seven.io/en/docs/glossary/shared-numbers/).
8989

9090
*Is XML?*: If enabled, the API parses the text as XML format.
9191

@@ -109,11 +109,11 @@ other types return JSON by default.
109109

110110
> Required options are marked with an asterisk (*).
111111
112-
Visit our [API Documentation](https://www.sms77.io/en/docs/gateway/http-api/) for a
112+
Visit our [API Documentation](https://www.seven.io/en/docs/gateway/http-api/) for a
113113
detailed request description.
114114

115115
## Support
116116

117-
Need help? Feel free to [contact us](https://www.sms77.io/en/company/contact/).
117+
Need help? Feel free to [contact us](https://www.seven.io/en/company/contact/).
118118

119119
[![MIT](https://img.shields.io/badge/License-MIT-teal.svg)](LICENSE)

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"author": "sms77 e.K. <support@sms77.io> (https://www.sms77.io/)",
2+
"author": "seven communications GmbH & Co. KG <support@seven.io> (https://www.seven.io/)",
33
"bugs": {
4-
"email": "support@sms77.io",
5-
"url": "https://github.com/sms77io/nodered-contrib-sms77/issues"
4+
"email": "support@seven.io",
5+
"url": "https://github.com/seven-io/node-red/issues"
66
},
77
"dependencies": {
8-
"sms77-client": "^2.24.0",
8+
"sms77-client": "^2.25.0",
99
"node-fetch": "^2.6.7",
1010
"globalthis": "^1.0.3"
1111
},
@@ -19,7 +19,7 @@
1919
"sms77-voice": "src/nodes/voice/voice.js"
2020
}
2121
},
22-
"homepage": "https://github.com/sms77io/nodered-contrib-sms77",
22+
"homepage": "https://github.com/seven-io/node-red",
2323
"keywords": [
2424
"cnam",
2525
"hlr",
@@ -33,10 +33,10 @@
3333
"license": "MIT",
3434
"repository": {
3535
"type": "git",
36-
"url": "git+https://github.com/sms77io/nodered-contrib-sms77.git"
36+
"url": "git+https://github.com/seven-io/node-red.git"
3737
},
3838
"scripts": {
3939
"test": "echo \"Error: no test specified\" && exit 1"
4040
},
41-
"version": "3.2.2"
41+
"version": "3.3.0"
4242
}

src/BaseMessageNode.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/NodeUtil.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
const Util = require('./Util')
22

33
module.exports = class NodeUtil {
4-
constructor(node) {
4+
constructor(node, config) {
55
this.node = node
6+
this.config = config
7+
8+
this.status(`${node.name} connected`, 'blue', 'ring')
69
}
710

8-
emptyStringFallback = (key, value = null) => {
9-
const cfg = this.node.constructor.CFG
11+
onDone = (done, error, msg) => done
12+
? done(error) // Use done if defined (1.0+)
13+
: this.node.error(error, msg) // Fallback to node.error (pre-1.0)
14+
15+
emptyStringFallback = (key, value = '') => {
16+
const cfg = this.config
1017
if (!key in cfg) return value
1118
return '' === (cfg[key] || '') ? value : cfg[key]
1219
}
@@ -15,18 +22,12 @@ module.exports = class NodeUtil {
1522
this.node.status({fill, shape, text})
1623
}
1724

18-
onSuccess = (sent, failed, send, msg, payload, done) => {
19-
this.status(`${sent} sent | ${failed} failed`)
25+
onSuccess = (send, msg, payload, done) => {
2026
send({...msg, payload})
2127
if (done) done() // Check done exists (1.0+)
2228
}
2329

24-
onInput = async (msg, send, done) => {
25-
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
26-
await this.node._onInput(msg, send, done)
27-
}
28-
2930
errorHandler = (done, msg) => {
30-
return e => this.node._done(done, Util.stringify(e), msg)
31+
return e => this.onDone(done, Util.stringify(e), msg)
3132
}
3233
}

src/Util.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
const Sms77Client = require('sms77-client')
2+
const globalThis = require('globalthis')()
3+
if (!globalThis.fetch) globalThis.fetch = require('node-fetch')
24

35
module.exports = class Util {
4-
static initClient(apiKey) {
6+
static initClient(RED, config) {
7+
const apiKey = RED.nodes.getNode(config.config).credentials.apiKey
58
return new Sms77Client(apiKey, 'node-red')
69
}
710

src/nodes/lookup/lookup.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
1-
const BaseNode = require('../../BaseMessageNode')
21
const Util = require('../../Util')
2+
const NodeUtil = require('../../NodeUtil')
33

4-
module.exports = function(RED) {
4+
module.exports = function (RED) {
55
'use strict'
66

7-
class Sms77LookupNode {
8-
constructor(config) {
9-
BaseNode(this, RED, config)
10-
}
7+
function Sms77LookupNode(config) {
8+
RED.nodes.createNode(this, config)
119

12-
async _onInput(msg, send, done) {
10+
const node = this
11+
const nodeUtil = new NodeUtil(node, config)
12+
const client = Util.initClient(RED, config)
13+
14+
this.on('input', async function onInput(msg, send, done) {
15+
if (!send) send = () => node.send.apply(node, [msg, send, done]) // If this is pre-1.0, 'send' will be undefined, so fallback to node.send
16+
17+
const type = config.lookupType
1318
const params = {
14-
json: 'true' === Sms77LookupNode.CFG.json,
15-
number: this._emptyStringFallback('numbers', msg.topic),
16-
type: Sms77LookupNode.CFG.lookupType,
19+
json: 'true' === config.json,
20+
number: nodeUtil.emptyStringFallback('numbers', msg.topic),
21+
type,
1722
}
1823

1924
try {
20-
const response = await Sms77LookupNode.CLIENT.lookup(params)
21-
this._util.status(Util.stringify(response))
22-
send({...msg})
25+
const response = await client.lookup(params)
26+
nodeUtil.status(`Lookup of type "${type}" performed.`)
27+
send({...msg, payload: response})
2328
if (done) done() // Check done exists (1.0+)
2429
} catch (e) {
25-
this._errorHandler(done, msg)
30+
nodeUtil.errorHandler(done, msg)(e)
2631
}
27-
}
32+
})
2833
}
2934

3035
RED.nodes.registerType('sms77-lookup', Sms77LookupNode)

0 commit comments

Comments
 (0)