Skip to content

Commit f24bc98

Browse files
committed
[Components] notiff_io #16263
Actions - Create Notification
1 parent 9a6b1bb commit f24bc98

File tree

7 files changed

+111
-63
lines changed

7 files changed

+111
-63
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import common from "../../../notiff_io/actions/create-notification/create-notification.mjs";
2+
import { adjustPropDefinitions } from "../../common/utils.mjs";
3+
import app from "../../notiff.app.mjs";
4+
5+
const props = adjustPropDefinitions(common.props, app);
6+
7+
export default {
8+
...common,
9+
key: "notiff-create-notification",
10+
name: "Create Notification",
11+
description: "Send a new notification to a user or system via notiff.io. [See the documentation](https://notiff.io/articles/welcome-to-notiff-getting-started-with-your-notification-center)",
12+
version: "0.0.1",
13+
type: "action",
14+
methods: {
15+
getNotificationSourceId() {
16+
return this.app.$auth.notification_source_id;
17+
},
18+
},
19+
props: {
20+
app,
21+
...props,
22+
},
23+
};

components/notiff/common/utils.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export function adjustPropDefinitions(props, app) {
2+
return Object.fromEntries(
3+
Object.entries(props).map(([
4+
key,
5+
prop,
6+
]) => {
7+
const {
8+
propDefinition, ...otherValues
9+
} = prop;
10+
if (propDefinition) {
11+
const [
12+
, ...otherDefs
13+
] = propDefinition;
14+
return [
15+
key,
16+
{
17+
propDefinition: [
18+
app,
19+
...otherDefs,
20+
],
21+
...otherValues,
22+
},
23+
];
24+
}
25+
return [
26+
key,
27+
otherValues.type === "app"
28+
? null
29+
: otherValues,
30+
];
31+
})
32+
.filter(([
33+
key,
34+
value,
35+
]) => key != "idNotificationSource" && (value)),
36+
);
37+
}

components/notiff/notiff.app.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import notiffIo from "../notiff_io/notiff_io.app.mjs";
2+
13
export default {
4+
...notiffIo,
25
type: "app",
36
app: "notiff",
4-
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
...notiffIo.methods,
9+
_headers() {
10+
return {
11+
"Content-Type": "application/json",
12+
};
913
},
1014
},
1115
};

components/notiff/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/notiff",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Notiff Components",
55
"main": "notiff.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+
}
Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
1-
import notiff_io from "../../notiff_io.app.mjs";
2-
import { axios } from "@pipedream/platform";
1+
import app from "../../notiff_io.app.mjs";
32

43
export default {
54
key: "notiff_io-create-notification",
65
name: "Create Notification",
76
description: "Send a new notification to a user or system via notiff.io. [See the documentation](https://notiff.io/articles/welcome-to-notiff-getting-started-with-your-notification-center)",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
11-
notiff_io,
10+
app,
1211
idNotificationSource: {
13-
propDefinition: [
14-
notiff_io,
15-
"idNotificationSource",
16-
],
12+
type: "string",
13+
label: "ID Notification Source",
14+
description: "To get your Notification Source ID, sign in to Notiff, go to the Settings menu with the gear icon on the top right, click the \"Settings\" option. Copy your Notification Source ID from the list.",
15+
secret: true,
1716
},
1817
title: {
1918
propDefinition: [
20-
notiff_io,
19+
app,
2120
"title",
2221
],
2322
},
2423
description: {
2524
propDefinition: [
26-
notiff_io,
25+
app,
2726
"description",
2827
],
2928
},
3029
url: {
3130
propDefinition: [
32-
notiff_io,
31+
app,
3332
"url",
3433
],
3534
},
3635
},
36+
methods: {
37+
getNotificationSourceId() {
38+
return this.idNotificationSource;
39+
},
40+
},
3741
async run({ $ }) {
38-
const response = await this.notiff_io.sendNotification({
39-
idNotificationSource: this.idNotificationSource,
40-
title: this.title,
41-
description: this.description,
42-
url: this.url,
42+
const response = await this.app.createNotification({
43+
$,
44+
data: {
45+
id_notification_source: this.getNotificationSourceId(),
46+
title: this.title,
47+
description: this.description,
48+
url: this.url,
49+
},
4350
});
4451

45-
$.export("$summary", `Notification titled "${this.title}" created successfully`);
52+
$.export("$summary", `Notification titled "${this.title}" created successfully!`);
4653
return response;
4754
},
4855
};

components/notiff_io/notiff_io.app.mjs

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ export default {
44
type: "app",
55
app: "notiff_io",
66
propDefinitions: {
7-
idNotificationSource: {
8-
type: "string",
9-
label: "Notification Source ID",
10-
description: "The unique identifier for the notification source.",
11-
async options() {
12-
const sources = await this.listNotificationSources();
13-
return sources.map((source) => ({
14-
label: source.title,
15-
value: source.id,
16-
}));
17-
},
18-
},
197
title: {
208
type: "string",
219
label: "Title",
@@ -33,44 +21,27 @@ export default {
3321
},
3422
},
3523
methods: {
36-
authKeys() {
37-
console.log(Object.keys(this.$auth));
38-
},
3924
_baseUrl() {
4025
return "https://notiff.io/api/1.1/wf";
4126
},
42-
async _makeRequest(opts = {}) {
43-
const {
44-
$ = this, method = "GET", path = "/", headers, ...otherOpts
45-
} = opts;
27+
_headers() {
28+
return {
29+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
30+
};
31+
},
32+
_makeRequest({
33+
$ = this, path, ...opts
34+
}) {
4635
return axios($, {
47-
...otherOpts,
48-
method,
4936
url: this._baseUrl() + path,
50-
headers: {
51-
"Authorization": `Bearer ${this.$auth.api_key}`,
52-
...headers,
53-
},
54-
});
55-
},
56-
async listNotificationSources(opts = {}) {
57-
return this._makeRequest({
58-
path: "/list_notification_sources",
37+
headers: this._headers(),
5938
...opts,
6039
});
6140
},
62-
async sendNotification({
63-
idNotificationSource, title, description, url,
64-
}, opts = {}) {
41+
createNotification(opts = {}) {
6542
return this._makeRequest({
6643
method: "POST",
6744
path: "/create_notification",
68-
data: {
69-
id_notification_source: idNotificationSource,
70-
title,
71-
description,
72-
url,
73-
},
7445
...opts,
7546
});
7647
},

components/notiff_io/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/notiff_io",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Notiff (OAuth) Components",
55
"main": "notiff_io.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
}
1518
}

0 commit comments

Comments
 (0)