diff --git a/components/bippybox/actions/activate-box/activate-box.mjs b/components/bippybox/actions/activate-box/activate-box.mjs new file mode 100644 index 0000000000000..7c8859fc44a33 --- /dev/null +++ b/components/bippybox/actions/activate-box/activate-box.mjs @@ -0,0 +1,39 @@ +import app from "../../bippybox.app.mjs"; + +export default { + key: "bippybox-activate-box", + name: "Activate Box", + description: "Triggers the BippyBox to play an audio file. [See the documentation](https://bippybox.io/docs/).", + version: "0.0.1", + type: "action", + props: { + app, + device: { + type: "string", + label: "Device", + description: "The device identifier. Eg. `DEVICE123`.", + }, + url: { + type: "string", + label: "URL", + description: "The URL of the audio file to play. Eg. `https://storage.example.com/users/exampleUserUID67890/audio/SampleAudioFile.wav?alt=media&token=exampleToken123456`.", + }, + }, + async run({ $ }) { + const { + app, + device, + url, + } = this; + + const response = await app.activateBox({ + $, + data: { + device, + URL: url, + }, + }); + $.export("$summary", "Successfully activated BippyBox."); + return response; + }, +}; diff --git a/components/bippybox/bippybox.app.mjs b/components/bippybox/bippybox.app.mjs index a28fdbc083d01..52c5cd0c53e20 100644 --- a/components/bippybox/bippybox.app.mjs +++ b/components/bippybox/bippybox.app.mjs @@ -1,11 +1,46 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "bippybox", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + return `https://websocket.bippybox.io${path}`; + }, + getHeaders(headers) { + return { + ...headers, + "Content-Type": "application/json", + "x-api-key": this.$auth.api_key, + }; + }, + _makeRequest({ + $ = this, path, headers, ...args + } = {}) { + return axios($, { + ...args, + url: this.getUrl(path), + headers: this.getHeaders(headers), + }); + }, + post(args = {}) { + return this._makeRequest({ + method: "POST", + ...args, + }); + }, + activateBox({ + data, ...args + } = {}) { + const { uid } = this.$auth; + return this.post({ + path: "/send", + data: { + ...data, + uid, + }, + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/bippybox/package.json b/components/bippybox/package.json index 4d0a22c696fc8..c69829f985d38 100644 --- a/components/bippybox/package.json +++ b/components/bippybox/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/bippybox", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream BippyBox Components", "main": "bippybox.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 a234fe7037a27..67c73622c0674 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1109,7 +1109,10 @@ importers: '@pipedream/platform': 1.5.1 components/bippybox: - specifiers: {} + specifiers: + '@pipedream/platform': 3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/bitbadges: specifiers: {}