diff --git a/components/ntfy/actions/send-notification/send-notification.mjs b/components/ntfy/actions/send-notification/send-notification.mjs new file mode 100644 index 0000000000000..4c23e89c5249e --- /dev/null +++ b/components/ntfy/actions/send-notification/send-notification.mjs @@ -0,0 +1,56 @@ +import app from "../../ntfy.app.mjs"; + +export default { + key: "ntfy-send-notification", + name: "Send Notification", + description: "Send a notification using Ntfy. [See the documentation](https://docs.ntfy.sh/publish/).", + version: "0.0.1", + type: "action", + props: { + app, + topic: { + type: "string", + label: "Topic", + description: "The topic to which the notification will be sent", + }, + data: { + type: "string", + label: "Message", + description: "The message content of the notification", + }, + headers: { + type: "object", + label: "Headers", + description: "Optional headers to include in the request. [See the documentation](https://docs.ntfy.sh/publish/).", + optional: true, + }, + }, + methods: { + sendNotification({ + topic, ...args + } = {}) { + return this.app.post({ + path: `/${topic}`, + ...args, + }); + }, + }, + async run({ $ }) { + const { + sendNotification, + topic, + data, + headers, + } = this; + + const response = await sendNotification({ + $, + headers, + topic, + data, + }); + + $.export("$summary", `Successfully sent notification with ID \`${response.id}\`.`); + return response; + }, +}; diff --git a/components/ntfy/ntfy.app.mjs b/components/ntfy/ntfy.app.mjs index c69479794c732..7933474f09d0d 100644 --- a/components/ntfy/ntfy.app.mjs +++ b/components/ntfy/ntfy.app.mjs @@ -1,11 +1,25 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "ntfy", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + return `${this.$auth.server}${path}`; + }, + _makeRequest({ + $ = this, path, ...args + } = {}) { + return axios($, { + ...args, + url: this.getUrl(path), + }); + }, + post(args = {}) { + return this._makeRequest({ + method: "POST", + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/ntfy/package.json b/components/ntfy/package.json index 7ecb9883ef75b..9b18e22fd40e3 100644 --- a/components/ntfy/package.json +++ b/components/ntfy/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/ntfy", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream ntfy Components", "main": "ntfy.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 386208bb30d06..458e849a4aba2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6821,7 +6821,10 @@ importers: '@pipedream/platform': 3.0.0 components/ntfy: - specifiers: {} + specifiers: + '@pipedream/platform': 3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/nudgify: specifiers: