From 17c27f2d21e88ee3f79186f2d75f46c189c4c27f Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Thu, 4 Jul 2024 08:26:47 -0300 Subject: [PATCH 1/2] Added actions --- .../send-text-message/send-text-message.mjs | 44 +++++++++++++++++ components/noor/noor.app.mjs | 49 +++++++++++++++++-- components/noor/package.json | 7 ++- pnpm-lock.yaml | 5 +- 4 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 components/noor/actions/send-text-message/send-text-message.mjs diff --git a/components/noor/actions/send-text-message/send-text-message.mjs b/components/noor/actions/send-text-message/send-text-message.mjs new file mode 100644 index 0000000000000..fdc38950cba8a --- /dev/null +++ b/components/noor/actions/send-text-message/send-text-message.mjs @@ -0,0 +1,44 @@ +import app from "../../noor.app.mjs"; + +export default { + key: "noor-send-text-message", + name: "Send Text Message", + description: "Send a message in a thread. [See the documentation](https://usenoor.notion.site/v0-e812ae5e5976420f81232fa1c0316e84)", + version: "0.0.1", + type: "action", + props: { + app, + spaceId: { + propDefinition: [ + app, + "spaceId", + ], + }, + thread: { + propDefinition: [ + app, + "thread", + ], + }, + text: { + propDefinition: [ + app, + "text", + ], + }, + }, + async run({ $ }) { + const response = await this.app.sendMessage({ + $, + data: { + spaceId: this.spaceId, + thread: this.thread, + text: this.text, + }, + }); + + $.export("$summary", `Successfully sent message to '${this.thread}' thread`); + + return response; + }, +}; diff --git a/components/noor/noor.app.mjs b/components/noor/noor.app.mjs index 4f935c64224a2..bd32273dc1158 100644 --- a/components/noor/noor.app.mjs +++ b/components/noor/noor.app.mjs @@ -1,11 +1,52 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "noor", - propDefinitions: {}, + propDefinitions: { + thread: { + type: "string", + label: "Thread", + description: "Thread to where the message will be sent", + }, + text: { + type: "string", + label: "Text", + description: "Text of the message", + }, + spaceId: { + type: "string", + label: "Space ID", + description: "ID of the space, can be viewed in your space settings", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://sun.noor.to/api/v0"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + "Authorization": `Bearer ${this.$auth.api_key}`, + "Content-Type": "application/json", + }, + }); + }, + async sendMessage(args = {}) { + return this._makeRequest({ + method: "post", + path: "/sendMessage", + ...args, + }); }, }, }; diff --git a/components/noor/package.json b/components/noor/package.json index a123c6186a784..42ad01d436733 100644 --- a/components/noor/package.json +++ b/components/noor/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/noor", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Noor Components", "main": "noor.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7d674b2a09677..5f695f91169e6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5952,7 +5952,10 @@ importers: '@pipedream/platform': 1.5.1 components/noor: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.0 + dependencies: + '@pipedream/platform': 3.0.0 components/nordigen: specifiers: From 4d8b9a8e51b1d3a3ae3bea58f370309de1ec384e Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Tue, 9 Jul 2024 09:51:33 -0300 Subject: [PATCH 2/2] Fixed requested changes --- components/noor/actions/send-text-message/send-text-message.mjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/noor/actions/send-text-message/send-text-message.mjs b/components/noor/actions/send-text-message/send-text-message.mjs index fdc38950cba8a..7024688a62b01 100644 --- a/components/noor/actions/send-text-message/send-text-message.mjs +++ b/components/noor/actions/send-text-message/send-text-message.mjs @@ -37,6 +37,8 @@ export default { }, }); + if (response.error) throw new Error(response?.error); + $.export("$summary", `Successfully sent message to '${this.thread}' thread`); return response;