diff --git a/components/streamlabs/actions/create-donation/create-donation.mjs b/components/streamlabs/actions/create-donation/create-donation.mjs new file mode 100644 index 0000000000000..f4e6226937400 --- /dev/null +++ b/components/streamlabs/actions/create-donation/create-donation.mjs @@ -0,0 +1,74 @@ +import streamlabs from "../../streamlabs.app.mjs"; +import currencies from "../../common/currencies.mjs"; + +export default { + key: "streamlabs-create-donation", + name: "Create Donation", + description: "Create a donation for the authenticated user. [See the documentation](https://dev.streamlabs.com/reference/donations-1)", + version: "0.0.1", + type: "action", + props: { + streamlabs, + name: { + type: "string", + label: "Name", + description: "The name of the donor. Has to be between 2-25 length and should only contain utf8 characters", + }, + identifier: { + type: "string", + label: "Identifier", + description: "An identifier for this donor, which is used to group donations with the same donor. For example, if you create more than one donation with the same identifier, they will be grouped together as if they came from the same donor. Typically this is best suited as an email address, or a unique hash.", + }, + amount: { + type: "string", + label: "Amount", + description: "The amount of this donation", + }, + currency: { + type: "string", + label: "Currency", + description: "The 3 letter currency code for this donation. Must be one of the [supported currency codes](https://dev.streamlabs.com/docs/currency-codes)", + options: currencies, + }, + message: { + type: "string", + label: "Message", + description: "The message from the donor. Must be < 255 characters", + optional: true, + }, + createdAt: { + type: "string", + label: "Created At", + description: "A timestamp that identifies when this donation was made. If left blank, it will default to now. Enter in ISO-8601 format (e.g., `2018-02-18T02:30:00-07:00` or `2018-02-18T08:00:00Z`, where Z stands for UTC)", + optional: true, + }, + skipAlert: { + type: "string", + label: "Skip Alert", + description: "Set to `yes` if you need to skip the alert. Default is `no`", + options: [ + "yes", + "no", + ], + optional: true, + }, + }, + async run({ $ }) { + const response = await this.streamlabs.createDonation({ + $, + data: { + name: this.name, + identifier: this.identifier, + amount: parseFloat(this.amount), + currency: this.currency, + message: this.message, + createdAt: this.createdAt && Date.parse(this.createdAt), + skip_alert: this.skipAlert, + }, + }); + if (response?.donation_id) { + $.export("$summary", `Successfully created donation with ID: ${response.donation_id}`); + } + return response; + }, +}; diff --git a/components/streamlabs/actions/send-alert/send-alert.mjs b/components/streamlabs/actions/send-alert/send-alert.mjs new file mode 100644 index 0000000000000..90464f67a3405 --- /dev/null +++ b/components/streamlabs/actions/send-alert/send-alert.mjs @@ -0,0 +1,74 @@ +import streamlabs from "../../streamlabs.app.mjs"; + +export default { + key: "streamlabs-send-alert", + name: "Send Alert", + description: "Sends an alert to the stream overlay with a custom message, image, and sound. [See the documentation](https://dev.streamlabs.com/reference/alerts)", + version: "0.0.1", + type: "action", + props: { + streamlabs, + type: { + type: "string", + label: "Type", + description: "determines which alert box this alert will show up in", + options: [ + "follow", + "subscription", + "donation", + "host", + ], + }, + message: { + type: "string", + label: "Message", + description: "The message to show with this alert", + }, + imageHref: { + type: "string", + label: "Image HREF", + description: "The href pointing to an image resource to play when this alert shows", + optional: true, + }, + soundHref: { + type: "string", + label: "Sound HREF", + description: "The href pointing to a sound resource to play when this alert shows", + optional: true, + }, + userMessage: { + type: "string", + label: "User Message", + description: "Acting as the second heading, this shows below message", + optional: true, + }, + duration: { + type: "string", + label: "Duration", + description: "How many seconds this alert should be displayed. Value should be in milliseconds. Ex: `1000` for 1 second.", + optional: true, + }, + specialTextColor: { + type: "string", + label: "Special Text Color", + description: "The color to use for special tokens. Must be a valid CSS color string", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.streamlabs.sendAlert({ + $, + data: { + type: this.type, + message: this.message, + image_href: this.imageHref, + sound_href: this.soundHref, + user_message: this.userMessage, + duration: this.duration, + special_text_color: this.specialTextColor, + }, + }); + $.export("$summary", `Alert sent with message: ${this.message}`); + return response; + }, +}; diff --git a/components/streamlabs/actions/send-test-alert/send-test-alert.mjs b/components/streamlabs/actions/send-test-alert/send-test-alert.mjs new file mode 100644 index 0000000000000..3ededd67bcfb5 --- /dev/null +++ b/components/streamlabs/actions/send-test-alert/send-test-alert.mjs @@ -0,0 +1,64 @@ +import streamlabs from "../../streamlabs.app.mjs"; + +export default { + key: "streamlabs-send-test-alert", + name: "Send Test Alert", + description: "Send a test alert to the stream overlay in StreamLabs. [See the documentation](https://dev.streamlabs.com/reference/alertssend_test_alert)", + version: "0.0.1", + type: "action", + props: { + streamlabs, + platform: { + type: "string", + label: "Platform", + description: "The streaming platform", + options: [ + "twitch", + "youtube", + ], + reloadProps: true, + }, + }, + additionalProps() { + if (!this.platform) { + return {}; + } + const props = { + type: { + type: "string", + label: "Type", + description: "The type of the alert", + }, + }; + if (this.platform === "twitch") { + props.type.options = [ + "follow", + "subscription", + "donation", + "host", + "bits", + "raid", + ]; + } + if (this.platform === "youtube") { + props.type.options = [ + "subscription", + "sponsor", + "superchat", + "donation", + ]; + } + return props; + }, + async run({ $ }) { + const response = await this.streamlabs.sendTestAlert({ + $, + data: { + platform: this.platform, + type: this.type, + }, + }); + $.export("$summary", "Successfully sent test alert"); + return response; + }, +}; diff --git a/components/streamlabs/common/currencies.mjs b/components/streamlabs/common/currencies.mjs new file mode 100644 index 0000000000000..8a86e5edfa79c --- /dev/null +++ b/components/streamlabs/common/currencies.mjs @@ -0,0 +1,90 @@ +export default [ + { + value: "USD", + label: "US Dollar", + }, + { + value: "AUD", + label: "Australian Dollar", + }, + { + value: "BRL", + label: "Brazilian Real", + }, + { + value: "CAD", + label: "Canadian Dollar", + }, + { + value: "CZK", + label: "Czech Koruna", + }, + { + value: "DKK", + label: "Danish Krone", + }, + { + value: "EUR", + label: "Euro", + }, + { + value: "HKD", + label: "Hong Kong Dollar", + }, + { + value: "ILS", + label: "Israeli New Sheqel", + }, + { + value: "MYR", + label: "Malaysian Ringgit", + }, + { + value: "MXN", + label: "Mexican Peso", + }, + { + value: "NOK", + label: "Norwegian Krone", + }, + { + value: "NZD", + label: "New Zealand Dollar", + }, + { + value: "PHP", + label: "Philippine Peso", + }, + { + value: "PLN", + label: "Polish Zloty", + }, + { + value: "GBP", + label: "Pound Sterling", + }, + { + value: "RUB", + label: "Russian Ruble", + }, + { + value: "SGD", + label: "Singapore Dollar", + }, + { + value: "SEK", + label: "Swedish Krona", + }, + { + value: "CHF", + label: "Swiss Franc", + }, + { + value: "THB", + label: "Thai Baht", + }, + { + value: "TRY", + label: "Turkish Lira", + }, +]; diff --git a/components/streamlabs/package.json b/components/streamlabs/package.json new file mode 100644 index 0000000000000..b6f33111e3558 --- /dev/null +++ b/components/streamlabs/package.json @@ -0,0 +1,18 @@ +{ + "name": "@pipedream/streamlabs", + "version": "0.0.1", + "description": "Pipedream Streamlabs Components", + "main": "streamlabs.app.mjs", + "keywords": [ + "pipedream", + "streamlabs" + ], + "homepage": "https://pipedream.com/apps/streamlabs", + "author": "Pipedream (https://pipedream.com/)", + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" + } +} diff --git a/components/streamlabs/streamlabs.app.mjs b/components/streamlabs/streamlabs.app.mjs index 11983339a57f6..7b2f37cdf4ba0 100644 --- a/components/streamlabs/streamlabs.app.mjs +++ b/components/streamlabs/streamlabs.app.mjs @@ -1,11 +1,51 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "streamlabs", propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://streamlabs.com/api/v1.0"; + }, + _accessToken() { + return this.$auth.oauth_access_token; + }, + _makeRequest({ + $ = this, + path, + data, + ...otherOpts + }) { + return axios($, { + ...otherOpts, + url: `${this._baseUrl()}${path}`, + data: { + access_token: this._accessToken(), + ...data, + }, + }); + }, + sendAlert(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/alerts", + ...opts, + }); + }, + createDonation(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/donations", + ...opts, + }); + }, + sendTestAlert(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/alerts/send_test_alert", + ...opts, + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 11b0cd8871854..a944b5ef26431 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2454,8 +2454,7 @@ importers: specifier: ^0.1.6 version: 0.1.6 - components/current_rms: - specifiers: {} + components/current_rms: {} components/customer_fields: dependencies: @@ -7284,8 +7283,7 @@ importers: components/odoo: {} - components/office_365_management: - specifiers: {} + components/office_365_management: {} components/offlight: dependencies: @@ -10421,6 +10419,12 @@ importers: specifier: ^1.1.1 version: 1.6.6 + components/streamlabs: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 + components/streamtime: dependencies: '@pipedream/platform': @@ -12645,8 +12649,7 @@ importers: specifier: ^1.0.5 version: 1.0.5 - components/zoho_tables: - specifiers: {} + components/zoho_tables: {} components/zoho_workdrive: dependencies: @@ -32274,6 +32277,8 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) + transitivePeerDependencies: + - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: