@semilimes/node-red-semilimes
Advanced tools
Comparing version 0.9.5 to 0.9.6
{ | ||
"name": "@semilimes/node-red-semilimes", | ||
"version": "0.9.5", | ||
"version": "0.9.6", | ||
"description": "The new semilimes connector which integrates with the public API", | ||
@@ -22,2 +22,3 @@ "scripts": { | ||
"sme-main-formUpdater": "src/sme-main-formUpdater.js", | ||
"sme-main-uploader": "src/sme-main-uploader.js", | ||
"sme-comp-text": "src/data-components/sme-comp-text.js", | ||
@@ -55,2 +56,4 @@ "sme-comp-html": "src/data-components/sme-comp-html.js", | ||
"dependencies": { | ||
"axios": "^1.6.5", | ||
"form-data": "^4.0.0", | ||
"node-forge": "^1.3.1", | ||
@@ -62,7 +65,6 @@ "ssh2": "^1.11.0", | ||
"node": ">=12.0.0" | ||
}, | ||
}, | ||
"directories": { | ||
"example": "examples" | ||
}, | ||
"devDependencies": {}, | ||
"repository": { | ||
@@ -69,0 +71,0 @@ "type": "git", |
# Node-RED semilimes connector | ||
[![Platform](https://img.shields.io/badge/platform-Node--RED-red)](https://nodered.org) [![License](https://img.shields.io/badge/license-Apache--License-lightgrey)](http://www.apache.org/licenses/LICENSE-2.0) [![Downloads](https://img.shields.io/badge/download-github-purple)](https://github.com/semilimes/nodered-publicapi-connector) [![Install](https://img.shields.io/badge/Install-NPM-blue)](https://www.npmjs.com/package/@semilimes/node-red-semilimes) | ||
This package of Node-RED nodes to extends your semilimes account with your programming ability, such as auto reply, booking flow or even message-base interface of your exsting system to expose to semilimes Messenger. | ||
This Node-RED package lets you extend your semilimes experience with automation and IoT capabilities, such as the implementation of auto replies, booking flows, control dashboards or message-based interfaces, all exposed through your semilimes app. | ||
@@ -10,28 +10,43 @@ [Github project](https://github.com/semilimes/nodered-publicapi-connector) | ||
## Installation | ||
## Install | ||
[![NPM](https://nodei.co/npm/@semilimes/node-red-semilimes.png?downloads=true)](https://nodei.co/npm/@semilimes/node-red-semilimes/) | ||
You can install the nodes using node-red's "Manage palette" in the side bar. | ||
You can install the nodes by either | ||
- using node-red's "Manage palette" in the side bar and searching for `node-red-semilimes` | ||
or | ||
- running the following command in the root directory of your Node-RED installation | ||
``` | ||
npm install @semilimes/node-red-semilimes --save | ||
``` | ||
Or run the following command in the root directory of your Node-RED installation | ||
npm install @semilimes/node-red-semilimes --save | ||
## Setup your developer environment | ||
## Installation of the mobile apps | ||
- IOS semilimes Messenger : [![Platform](https://img.shields.io/badge/Apple%20IOS-semilimes%20Messenger-blue.svg)](https://apps.apple.com/us/app/semilimes-mesh/id1536363738?l=en) | ||
1. Install the semilimes app through the [Official semilimes Website](https://www.semilimes.com/apps/) or by using the following direct store links | ||
- **iOS** : [![Platform](https://img.shields.io/badge/Apple%20IOS-semilimes%20Messenger-blue.svg)](https://apps.apple.com/us/app/semilimes-mesh/id1536363738?l=en) | ||
- Android semilimes Messenger : [![Platform](https://img.shields.io/badge/Google--Play-semilimes%20Messenger-darkgreen.svg)](https://play.google.com/store/apps/details?id=net.semilimes.messenger&hl=en&gl=US) | ||
- **Android** : [![Platform](https://img.shields.io/badge/Google--Play-semilimes%20Messenger-darkgreen.svg)](https://play.google.com/store/apps/details?id=net.semilimes.messenger&hl=en&gl=US) | ||
## Dependencies | ||
The nodes are tested with `Node.js v19.2.0` and `Node-RED v3.0.2`. | ||
2. Access the [semilimes Services](https://my.semilimes.net) website and login using the on-screen instructions | ||
3. Create a subaccount | ||
![CreateSubAccount](resources/images/createSubAccount.png) | ||
4. Enter billing information for the created subaccount | ||
![EnterBillingInfo](resources/images/enterBillingInfo.png) | ||
5. Request an API Key for your new subaccount | ||
![GenerateApiKey](resources/images/generateApiKey.png) | ||
## Connect to semilimes | ||
1. Get an API key on [semilimes](https://www.semilimes.com) website | ||
2. Add a new `Text` node and configure it with your preferred message | ||
1. Add a new `Text` node and configure it with your preferred message | ||
3. Add an `Action Selector` node and select the `Account - Get Contacts` to get a list of contacts to send a message to. | ||
2. Add an `Action Selector` node and select the `Account - Get Contacts` to get a list of contacts to send a message to. | ||
4. Add a `sender` node then config its `Connector` property to create a `connector` configuration. | ||
3. Add a `sender` node then config its `Connector` property to create a `connector` configuration. | ||
![Property editor of listener node](resources/images/sender_node_properties.jpg) | ||
@@ -48,14 +63,21 @@ | ||
4. Add a `sender` node and run. You have sent your first message! | ||
4. Add a `sender` node and run. | ||
The flow should look like this [example](https://github.com/semilimes/nodered-publicapi-connector/blob/main/examples/Connect%20To%20semilimes%20flow.json) | ||
Sample flow to connect to semilimes and send your first message. | ||
[Connect to semilimes flow](https://github.com/semilimes/nodered-publicapi-connector/blob/main/examples/Connect%20To%20Semilimes%20flow.json) | ||
![connect to semilimes flow example](resources/images/connecttosemilimesflow.png) | ||
You have sent your first message! | ||
# Examples | ||
- [All Example flows](https://github.com/semilimes/nodered-publicapi-connector/tree/main/examples) | ||
## Handy setup connection to semilimes | ||
Communication with semilimes is API-key based | ||
You can find all the provided examples by importing them from this Node-RED package, or you can explore and import them manually at this GitHub link: | ||
[All Example flows](https://github.com/semilimes/nodered-publicapi-connector/tree/main/examples) | ||
## Dependencies | ||
The nodes are tested on linux environments with `Node.js v19.2.0` and `Node-RED v3.0.2` | ||
# License | ||
@@ -62,0 +84,0 @@ Apache License |
@@ -24,3 +24,3 @@ "use strict"; | ||
var referenceValue = smeHelper.getNodeConfigValue(node, msg, node.referenceType, node.reference); | ||
console.log("referenceValue: ", referenceValue); | ||
//filter submissions | ||
@@ -27,0 +27,0 @@ var isMatchedSubmissionMessage = |
@@ -7,2 +7,5 @@ "use strict"; | ||
const { debug } = require('util'); | ||
const fs = require('fs'); | ||
const FormData = require('form-data'); | ||
const axios = require('axios'); | ||
@@ -152,8 +155,4 @@ module.exports = function (RED) { | ||
} | ||
var firstProperty = String(selectionValue).split('.')[0]; | ||
var searchPath = String(selectionValue).replace(`${firstProperty}`, ''); | ||
console.log("SelectionValue: ", selectionValue); | ||
console.log("firstProperty: ",firstProperty); | ||
console.log("searchPath: ", searchPath); | ||
@@ -380,86 +379,120 @@ switch (selectionType) { | ||
function callApi(endpoint, method, data) { | ||
return new Promise((resolve, reject) => { | ||
var body = data.body && JSON.stringify(data.body); | ||
var query = ''; | ||
if (data.parameters) { | ||
query += '?'; | ||
Object.entries(data.parameters).forEach((parameter, index) => { | ||
const [key, value] = parameter; | ||
query += key + '=' + value; | ||
if (index < Object.keys(data.parameters).length - 1) { | ||
query += '&'; | ||
} | ||
}); | ||
} | ||
if (endpoint == "/service/file/upload") { | ||
var baseUrl = new URL(serverApiURL); | ||
var options = { | ||
hostname: baseUrl.hostname, | ||
port: 443, | ||
path: `${baseUrl.pathname == "/" ? "" : baseUrl.pathname}${endpoint}${query}`, | ||
method: method, | ||
rejectUnauthorized: false, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': (body && body.length) || 0, | ||
}, | ||
timeout: 3000 | ||
}; | ||
if (apiKey) { | ||
//Authorize | ||
options.headers.Authorization = `Bearer ${apiKey}`; | ||
} | ||
if (xAccount) { | ||
//dev mode | ||
options.headers['X-Account'] = `${xAccount}`; | ||
} | ||
return new Promise((resolve, reject) => { | ||
let formdata = new FormData(); | ||
formdata.append('httpFiles', fs.createReadStream(`${data.filePath}`)); | ||
console.log('Attempt to send call to:', options); | ||
console.log('With data: ', body); | ||
let config = { | ||
method: method, | ||
maxBodyLength: Infinity, | ||
url: `${serverApiURL}${endpoint}`, | ||
headers: { | ||
'Authorization': `Bearer ${apiKey}`, | ||
...formdata.getHeaders() | ||
}, | ||
data : formdata | ||
}; | ||
var req = https.request(options, (res) => { | ||
console.log("Status Code: ", res.statusCode); | ||
let totalBuffer = ""; | ||
res.on('data', (buffer) => { | ||
totalBuffer += buffer.toString("utf8"); | ||
}); | ||
axios.request(config) | ||
.then((response) => { | ||
console.log(JSON.stringify(response.data)); | ||
resolve(response.data); | ||
}) | ||
.catch((error) => { | ||
console.log('Error when calling uploader API: ', error); | ||
reject(error); | ||
}) | ||
}); | ||
} else { | ||
//Message endpoints | ||
return new Promise((resolve, reject) => { | ||
var body = data.body && JSON.stringify(data.body); | ||
var query = ''; | ||
if (data.parameters) { | ||
query += '?'; | ||
Object.entries(data.parameters).forEach((parameter, index) => { | ||
const [key, value] = parameter; | ||
query += key + '=' + value; | ||
if (index < Object.keys(data.parameters).length - 1) { | ||
query += '&'; | ||
} | ||
}); | ||
} | ||
var baseUrl = new URL(serverApiURL); | ||
res.on('end', () => { | ||
if (typeof (totalBuffer) == 'string' && totalBuffer.startsWith('{')) { | ||
try { | ||
var jsonData = JSON.parse(totalBuffer); | ||
if (jsonData) { | ||
console.log('Call API resolved a JSON: ', jsonData); | ||
resolve(jsonData); | ||
return; | ||
} else { | ||
console.log('Response raw data: ', totalBuffer); | ||
var options = { | ||
hostname: baseUrl.hostname, | ||
port: 443, | ||
path: `${baseUrl.pathname == "/" ? "" : baseUrl.pathname}${endpoint}${query}`, | ||
method: method, | ||
rejectUnauthorized: false, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': (body && body.length) || 0, | ||
}, | ||
timeout: 3000 | ||
}; | ||
if (apiKey) { | ||
//Authorize | ||
options.headers.Authorization = `Bearer ${apiKey}`; | ||
} | ||
if (xAccount) { | ||
//dev mode | ||
options.headers['X-Account'] = `${xAccount}`; | ||
} | ||
console.log('Attempt to send call to:', options); | ||
console.log('With data: ', body); | ||
var req = https.request(options, (res) => { | ||
console.log("Status Code: ", res.statusCode); | ||
let totalBuffer = ""; | ||
res.on('data', (buffer) => { | ||
totalBuffer += buffer.toString("utf8"); | ||
}); | ||
res.on('end', () => { | ||
if (typeof (totalBuffer) == 'string' && totalBuffer.startsWith('{')) { | ||
try { | ||
var jsonData = JSON.parse(totalBuffer); | ||
if (jsonData) { | ||
console.log('Call API resolved a JSON: ', jsonData); | ||
resolve(jsonData); | ||
return; | ||
} else { | ||
console.log('Response raw data: ', totalBuffer); | ||
} | ||
} | ||
catch (ex) { | ||
console.debug('Error parsing API JSON result: ', ex); | ||
} | ||
} | ||
catch (ex) { | ||
console.debug('Error parsing API JSON result: ', ex); | ||
} | ||
} | ||
console.log('Call API resolved: ', totalBuffer); | ||
resolve(totalBuffer); | ||
console.log('Call API resolved: ', totalBuffer); | ||
resolve(totalBuffer); | ||
}); | ||
}); | ||
// use its "timeout" event to abort the request | ||
req.on('timeout', () => { | ||
console.log('API call timeout. Call aborted.') | ||
request.destroy(); | ||
}); | ||
req.on('error', (e) => { | ||
console.log('Call API rejected: ', e); | ||
reject(e); | ||
}); | ||
if (body) | ||
req.write(body); | ||
req.end(); | ||
}); | ||
} | ||
// use its "timeout" event to abort the request | ||
req.on('timeout', () => { | ||
console.log('API call timeout. Call aborted.') | ||
request.destroy(); | ||
}); | ||
req.on('error', (e) => { | ||
console.log('Call API rejected: ', e); | ||
reject(e); | ||
}); | ||
if (body) | ||
req.write(body); | ||
req.end(); | ||
}); | ||
}; | ||
@@ -466,0 +499,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
626756
90
3634
85
5
6
+ Addedaxios@^1.6.5
+ Addedform-data@^4.0.0
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@1.7.7(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedproxy-from-env@1.1.0(transitive)