Skip to content

Commit 3106435

Browse files
authored
New Components - alerty (#13901)
* alerty init * [Components] alerty #13848 Actions - Notify Devices * pnpm update
1 parent 9a4b071 commit 3106435

File tree

6 files changed

+133
-8
lines changed

6 files changed

+133
-8
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import alerty from "../../alerty.app.mjs";
2+
import { URGENCY_OPTIONS } from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "alerty-notify-devices",
7+
name: "Notify Devices",
8+
description: "Sends a notification to active devices. [See the documentation](https://alerty.dev/api/notify)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
alerty,
13+
message: {
14+
type: "string",
15+
label: "Message",
16+
description: "The message to be included in the push notification.",
17+
},
18+
title: {
19+
type: "string",
20+
label: "Title",
21+
description: "Title for your notification message.",
22+
optional: true,
23+
},
24+
image: {
25+
type: "string",
26+
label: "Image URL",
27+
description: "URL of an image to be displayed in the notification.",
28+
optional: true,
29+
},
30+
icon: {
31+
type: "string",
32+
label: "Icon URL",
33+
description: "URL of an image to be used as an icon by the notification. Default: Alerty Logo",
34+
optional: true,
35+
},
36+
deviceId: {
37+
type: "string[]",
38+
label: "Device ID",
39+
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.",
40+
optional: true,
41+
},
42+
urgency: {
43+
type: "string",
44+
label: "Urgency",
45+
description: "Urgency of the notification. Default: very-low",
46+
options: URGENCY_OPTIONS,
47+
optional: true,
48+
},
49+
actions: {
50+
type: "string[]",
51+
label: "Actions",
52+
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\" }",
53+
optional: true,
54+
},
55+
},
56+
async run({ $ }) {
57+
const response = await this.alerty.makeRequest({
58+
$,
59+
data: {
60+
message: this.message,
61+
title: this.title,
62+
image: this.image,
63+
icon: this.icon,
64+
device_id: parseObject(this.deviceId),
65+
urgency: this.urgency,
66+
actions: parseObject(this.actions),
67+
},
68+
});
69+
70+
$.export("$summary", `Notification sent with message: "${this.message}"`);
71+
return response;
72+
},
73+
};

components/alerty/alerty.app.mjs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "alerty",
4-
propDefinitions: {},
56
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
7+
_baseUrl() {
8+
return `${this.$auth.notification_url}`;
9+
},
10+
_headers() {
11+
return {
12+
Authorization: `Bearer ${this.$auth.api_key}`,
13+
};
14+
},
15+
makeRequest({
16+
$ = this, ...opts
17+
}) {
18+
return axios($, {
19+
method: "POST",
20+
url: this._baseUrl(),
21+
headers: this._headers(),
22+
...opts,
23+
});
924
},
1025
},
11-
};
26+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const URGENCY_OPTIONS = [
2+
"very-low",
3+
"low",
4+
"normal",
5+
"high",
6+
];

components/alerty/common/utils.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

components/alerty/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/alerty",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Alerty Components",
55
"main": "alerty.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1"
1417
}
15-
}
18+
}
19+

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)