diff --git a/components/botcake/actions/create-keyword/create-keyword.mjs b/components/botcake/actions/create-keyword/create-keyword.mjs new file mode 100644 index 0000000000000..0d16ec7da99fe --- /dev/null +++ b/components/botcake/actions/create-keyword/create-keyword.mjs @@ -0,0 +1,20 @@ +import app from "../../botcake.app.mjs"; + +export default { + key: "botcake-create-keyword", + name: "Create Keyword", + description: "Create a new Keyword. [See the documentation](https://docs.botcake.io/english/api-reference#create-keyword)", + version: "0.0.1", + type: "action", + props: { + app, + }, + + async run({ $ }) { + const response = await this.app.createKeyword({ + $, + }); + $.export("$summary", "Successfully created new Keyword"); + return response; + }, +}; diff --git a/components/botcake/actions/get-tools/get-tools.mjs b/components/botcake/actions/get-tools/get-tools.mjs new file mode 100644 index 0000000000000..fe2138dea9645 --- /dev/null +++ b/components/botcake/actions/get-tools/get-tools.mjs @@ -0,0 +1,20 @@ +import app from "../../botcake.app.mjs"; + +export default { + key: "botcake-get-tools", + name: "Get Tools", + description: "Get a list of tools associated with the specified page. [See the documentation](https://docs.botcake.io/english/api-reference#get-tools)", + version: "0.0.1", + type: "action", + props: { + app, + }, + + async run({ $ }) { + const response = await this.app.getTools({ + $, + }); + $.export("$summary", `Successfully retrieved ${response.data.length} tools`); + return response; + }, +}; diff --git a/components/botcake/actions/update-keyword/update-keyword.mjs b/components/botcake/actions/update-keyword/update-keyword.mjs new file mode 100644 index 0000000000000..7318c9f0236ae --- /dev/null +++ b/components/botcake/actions/update-keyword/update-keyword.mjs @@ -0,0 +1,38 @@ +import app from "../../botcake.app.mjs"; + +export default { + key: "botcake-update-keyword", + name: "Update Keyword", + description: "Update the Keyword with the specified ID. [See the documentation](https://docs.botcake.io/english/api-reference#update-keyword)", + version: "0.0.1", + type: "action", + props: { + app, + keywordId: { + propDefinition: [ + app, + "keywordId", + ], + }, + flowId: { + propDefinition: [ + app, + "flowId", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.updateKeyword({ + $, + data: { + keyword_id: this.keywordId, + update: { + flow_id: this.flowId, + }, + }, + }); + $.export("$summary", `Successfully updated Keyword with ID: '${this.keywordId}'`); + return response; + }, +}; diff --git a/components/botcake/botcake.app.mjs b/components/botcake/botcake.app.mjs index ffe6baef5f474..5c64d3338c85f 100644 --- a/components/botcake/botcake.app.mjs +++ b/components/botcake/botcake.app.mjs @@ -1,11 +1,88 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "botcake", - propDefinitions: {}, + propDefinitions: { + flowId: { + type: "integer", + label: "Flow ID", + description: "ID of the Flow", + async options() { + const response = await this.getFlow(); + const flowsIds = response.data.flows; + return flowsIds.map(({ + id, name, + }) => ({ + label: name, + value: id, + })); + }, + }, + keywordId: { + type: "integer", + label: "Keyword ID", + description: "ID of the Keyword", + async options() { + const response = await this.getKeyword(); + const keywordIds = response.data; + return keywordIds.map(({ id }) => ({ + value: id, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://botcake.io/api/public_api/v1/"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + "access-token": `${this.$auth.api_key}`, + }, + }); + }, + async createKeyword(args = {}) { + return this._makeRequest({ + path: `/pages/${this.$auth.page_id}/keywords/create`, + method: "post", + ...args, + }); + }, + async updateKeyword(args = {}) { + return this._makeRequest({ + path: `/pages/${this.$auth.page_id}/keywords/update`, + method: "post", + ...args, + }); + }, + async getTools(args = {}) { + return this._makeRequest({ + path: `/pages/${this.$auth.page_id}/tools`, + ...args, + }); + }, + async getKeyword(args = {}) { + return this._makeRequest({ + path: `/pages/${this.$auth.page_id}/keywords`, + ...args, + }); + }, + async getFlow(args = {}) { + return this._makeRequest({ + path: `/pages/${this.$auth.page_id}/flows`, + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/botcake/package.json b/components/botcake/package.json index da01c14f2e911..6f582da0df783 100644 --- a/components/botcake/package.json +++ b/components/botcake/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/botcake", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Botcake Components", "main": "botcake.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 797a1ce86b743..9e53224e87a72 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1256,7 +1256,11 @@ importers: components/botbaba: {} - components/botcake: {} + components/botcake: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/botconversa: dependencies: