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
73 changes: 73 additions & 0 deletions components/alerty/actions/notify-devices/notify-devices.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import alerty from "../../alerty.app.mjs";
import { URGENCY_OPTIONS } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "alerty-notify-devices",
name: "Notify Devices",
description: "Sends a notification to active devices. [See the documentation](https://alerty.dev/api/notify)",
version: "0.0.1",
type: "action",
props: {
alerty,
message: {
type: "string",
label: "Message",
description: "The message to be included in the push notification.",
},
title: {
type: "string",
label: "Title",
description: "Title for your notification message.",
optional: true,
},
image: {
type: "string",
label: "Image URL",
description: "URL of an image to be displayed in the notification.",
optional: true,
},
icon: {
type: "string",
label: "Icon URL",
description: "URL of an image to be used as an icon by the notification. Default: Alerty Logo",
optional: true,
},
deviceId: {
type: "string[]",
label: "Device ID",
description: "Specific device IDs to send the notification to. If no Device Id is included, the push message will be sent to all active devices on your account.",
optional: true,
},
urgency: {
type: "string",
label: "Urgency",
description: "Urgency of the notification. Default: very-low",
options: URGENCY_OPTIONS,
optional: true,
},
actions: {
type: "string[]",
label: "Actions",
description: "Actions for the notification, each item should be a JSON string. Example: { \"action\": \"https://example.com\", \"title\": \"Open Site\", \"icon\": \"https://example.com/icon.png\" }",
optional: true,
},
},
async run({ $ }) {
const response = await this.alerty.makeRequest({
$,
data: {
message: this.message,
title: this.title,
image: this.image,
icon: this.icon,
device_id: parseObject(this.deviceId),
urgency: this.urgency,
actions: parseObject(this.actions),
},
});

$.export("$summary", `Notification sent with message: "${this.message}"`);
return response;
},
};
25 changes: 20 additions & 5 deletions components/alerty/alerty.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "alerty",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return `${this.$auth.notification_url}`;
},
_headers() {
return {
Authorization: `Bearer ${this.$auth.api_key}`,
};
},
makeRequest({
$ = this, ...opts
}) {
return axios($, {
method: "POST",
url: this._baseUrl(),
headers: this._headers(),
...opts,
});
},
},
};
};
6 changes: 6 additions & 0 deletions components/alerty/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const URGENCY_OPTIONS = [
"very-low",
"low",
"normal",
"high",
];
24 changes: 24 additions & 0 deletions components/alerty/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
8 changes: 6 additions & 2 deletions components/alerty/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/alerty",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Alerty Components",
"main": "alerty.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.1"
}
}
}

133 changes: 68 additions & 65 deletions pnpm-lock.yaml

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