Skip to content

Commit c599b48

Browse files
committed
[Components] ntfy - Send Notification action
1 parent cb22999 commit c599b48

File tree

4 files changed

+84
-8
lines changed

4 files changed

+84
-8
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import app from "../../ntfy.app.mjs";
2+
3+
export default {
4+
key: "ntfy-send-notification",
5+
name: "Send Notification",
6+
description: "Send a notification using Ntfy. [See the documentation](https://docs.ntfy.sh/publish/).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
topic: {
12+
type: "string",
13+
label: "Topic",
14+
description: "The topic to which the notification will be sent",
15+
},
16+
data: {
17+
type: "string",
18+
label: "Message",
19+
description: "The message content of the notification",
20+
},
21+
headers: {
22+
type: "object",
23+
label: "Headers",
24+
description: "Optional headers to include in the request. [See the documentation](https://docs.ntfy.sh/publish/).",
25+
optional: true,
26+
},
27+
},
28+
methods: {
29+
sendNotification({
30+
topic, ...args
31+
} = {}) {
32+
return this.app.post({
33+
path: `/${topic}`,
34+
...args,
35+
});
36+
},
37+
},
38+
async run({ $ }) {
39+
const {
40+
sendNotification,
41+
topic,
42+
data,
43+
headers,
44+
} = this;
45+
46+
const response = await sendNotification({
47+
$,
48+
headers,
49+
topic,
50+
data,
51+
});
52+
53+
$.export("$summary", `Successfully sent notification with ID \`${response.id}\`.`);
54+
return response;
55+
},
56+
};

components/ntfy/ntfy.app.mjs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "ntfy",
4-
propDefinitions: {},
56
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
7+
getUrl(path) {
8+
return `${this.$auth.server}${path}`;
9+
},
10+
_makeRequest({
11+
$ = this, path, ...args
12+
} = {}) {
13+
return axios($, {
14+
...args,
15+
url: this.getUrl(path),
16+
});
17+
},
18+
post(args = {}) {
19+
return this._makeRequest({
20+
method: "POST",
21+
...args,
22+
});
923
},
1024
},
11-
};
25+
};

components/ntfy/package.json

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

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)