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..7024688a62b01 --- /dev/null +++ b/components/noor/actions/send-text-message/send-text-message.mjs @@ -0,0 +1,46 @@ +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, + }, + }); + + if (response.error) throw new Error(response?.error); + + $.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: