From e1c080f237f51fab9fc39cb7ca688384cc3ccf2d Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Mon, 5 Dec 2022 00:45:30 +0100 Subject: [PATCH] feat(ntfy): add send message action --- .../backend/src/apps/ntfy/actions/index.ts | 3 + .../apps/ntfy/actions/send-message/index.ts | 103 ++++++++++++++++++ packages/backend/src/apps/ntfy/index.ts | 2 + 3 files changed, 108 insertions(+) create mode 100644 packages/backend/src/apps/ntfy/actions/index.ts create mode 100644 packages/backend/src/apps/ntfy/actions/send-message/index.ts diff --git a/packages/backend/src/apps/ntfy/actions/index.ts b/packages/backend/src/apps/ntfy/actions/index.ts new file mode 100644 index 00000000..37aeb338 --- /dev/null +++ b/packages/backend/src/apps/ntfy/actions/index.ts @@ -0,0 +1,3 @@ +import sendMessage from './send-message'; + +export default [sendMessage]; diff --git a/packages/backend/src/apps/ntfy/actions/send-message/index.ts b/packages/backend/src/apps/ntfy/actions/send-message/index.ts new file mode 100644 index 00000000..8cc91584 --- /dev/null +++ b/packages/backend/src/apps/ntfy/actions/send-message/index.ts @@ -0,0 +1,103 @@ +import qs from 'qs'; +import defineAction from '../../../../helpers/define-action'; + +export default defineAction({ + name: 'Send message', + key: 'sendMessage', + description: 'Sends a message to a topic you specify.', + arguments: [ + { + label: 'Topic', + key: 'topic', + type: 'string' as const, + required: true, + description: 'Target topic name.', + variables: true, + }, + { + label: 'Message body', + key: 'message', + type: 'string' as const, + required: true, + description: 'Message body to be sent, set to triggered if empty or not passed.', + variables: true, + }, + { + label: 'Title', + key: 'title', + type: 'string' as const, + required: false, + description: 'Message title.', + variables: true, + }, + { + label: 'Email', + key: 'email', + type: 'string' as const, + required: false, + description: 'E-mail address for e-mail notifications.', + variables: true, + }, + { + label: 'Click URL', + key: 'click', + type: 'string' as const, + required: false, + description: 'Website opened when notification is clicked.', + variables: true, + }, + { + label: 'Attach file by URL', + key: 'attach', + type: 'string' as const, + required: false, + description: 'URL of an attachment.', + variables: true, + }, + { + label: 'Filename', + key: 'filename', + type: 'string' as const, + required: false, + description: 'File name of the attachment.', + variables: true, + }, + { + label: 'Delay', + key: 'delay', + type: 'string' as const, + required: false, + description: 'Timestamp or duration for delayed delivery. For example, 30min or 9am.', + variables: true, + }, + ], + + async run($) { + const { + topic, + message, + title, + email, + click, + attach, + filename, + delay + } = $.step.parameters; + const payload = { + topic, + message, + title, + email, + click, + attach, + filename, + delay + }; + + const response = await $.http.post('/', payload); + + $.setActionItem({ + raw: response.data, + }); + }, +}); diff --git a/packages/backend/src/apps/ntfy/index.ts b/packages/backend/src/apps/ntfy/index.ts index c1cddab4..1ba23966 100644 --- a/packages/backend/src/apps/ntfy/index.ts +++ b/packages/backend/src/apps/ntfy/index.ts @@ -1,6 +1,7 @@ import defineApp from '../../helpers/define-app'; import addAuthHeader from './common/add-auth-header'; import auth from './auth'; +import actions from './actions'; export default defineApp({ name: 'Ntfy', @@ -13,4 +14,5 @@ export default defineApp({ primaryColor: '56bda8', beforeRequest: [addAuthHeader], auth, + actions, });