Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 64 additions & 5 deletions components/_360nrs/_360nrs.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,70 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "_360nrs",
propDefinitions: {},
propDefinitions: {
message: {
type: "string",
label: "Message",
description: "Text of message. At most, there can be 160 characters. The text must be encoded in UTF-8.",
},
phoneNumber: {
type: "string",
label: "Phone Number",
description: "Mobile phone number(s) to receive message. Must include the prefix (e.g. in Spain `34666666666`).",
async options() {
const { data } = await this.listContacts();
return data.map(({
email: label, phone: value,
}) => ({
label,
value,
}));
},
},
from: {
type: "string",
label: "From Sender",
description: "Sender text, this label will consist of 15 numbers or 11 alphanumeric characters.",
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://dashboard.360nrs.com/api/rest";
},
getHeaders(headers) {
const {
username,
api_password: password,
} = this.$auth;
const token = Buffer.from(`${username}:${password}`).toString("base64");
return {
...headers,
"Content-Type": "application/json",
"Authorization": `Basic ${token}`,
};
},
_makeRequest({
$ = this, path, headers, ...args
} = {}) {
return axios($, {
...args,
url: `${this._baseUrl()}${path}`,
headers: this.getHeaders(headers),
});
},
post(args = {}) {
return this._makeRequest({
method: "POST",
...args,
});
},
listContacts(args = {}) {
return this._makeRequest({
path: "/contacts",
...args,
});
},
},
};
};
60 changes: 60 additions & 0 deletions components/_360nrs/actions/send-sms/send-sms.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import app from "../../_360nrs.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "_360nrs-send-sms",
name: "Send SMS",
description: "Send an SMS message to one or more recipients. [See the documentation](https://apidocs.360nrs.com/?shell#sms)",
version: "0.0.1",
type: "action",
props: {
app,
message: {
propDefinition: [
app,
"message",
],
},
to: {
type: "string[]",
label: "To Phone Number(s)",
propDefinition: [
app,
"phoneNumber",
],
},
from: {
propDefinition: [
app,
"from",
],
},
},
methods: {
sendSMS(args = {}) {
return this.app.post({
path: "/sms",
...args,
});
},
},
async run({ $ }) {
const {
sendSMS,
message,
from,
to,
} = this;

const response = await sendSMS({
data: {
message,
to: utils.parseArray(to),
from,
},
});

$.export("$summary", `Successfully sent SMS with ID \`${response.result[0]?.id}\``);
return response;
},
};
28 changes: 28 additions & 0 deletions components/_360nrs/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ConfigurationError } from "@pipedream/platform";

function parseArray(value) {
try {
if (!value) {
return [];
}

if (Array.isArray(value)) {
return value;
}

const parsedValue = JSON.parse(value);

if (!Array.isArray(parsedValue)) {
throw new Error("Not an array");
}

return parsedValue;

} catch (e) {
throw new ConfigurationError("Make sure the custom expression contains a valid array object");
}
}

export default {
parseArray,
};
7 changes: 5 additions & 2 deletions components/_360nrs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/_360nrs",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream 360NRS Components",
"main": "_360nrs.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
}
}
}
17 changes: 5 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.