diff --git a/components/facebook_graph_api/facebook_graph_api.app.mjs b/components/facebook_graph_api/facebook_graph_api.app.mjs index e43e6f28f6bc8..a897a39bcf741 100644 --- a/components/facebook_graph_api/facebook_graph_api.app.mjs +++ b/components/facebook_graph_api/facebook_graph_api.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/gather/gather.app.mjs b/components/gather/gather.app.mjs index 8ffeb104402d4..e4656c599633c 100644 --- a/components/gather/gather.app.mjs +++ b/components/gather/gather.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/hamsa/actions/create-content/create-content.mjs b/components/hamsa/actions/create-content/create-content.mjs new file mode 100644 index 0000000000000..c181e0d1a0b94 --- /dev/null +++ b/components/hamsa/actions/create-content/create-content.mjs @@ -0,0 +1,40 @@ +import { AI_PARTS_OPTIONS } from "../../common/constants.mjs"; +import hamsa from "../../hamsa.app.mjs"; + +export default { + key: "hamsa-create-content", + name: "Create AI Content", + description: "Transform transcribed content into various formats for content marketing. [See the documentation](https://docs.tryhamsa.com/api-reference/endpoint/post-ai-content)", + version: "0.0.1", + type: "action", + props: { + hamsa, + jobId: { + propDefinition: [ + hamsa, + "jobId", + ], + }, + aiParts: { + type: "string[]", + label: "AI Parts", + description: "Parts for AI content in marketing.", + options: AI_PARTS_OPTIONS, + }, + }, + async run({ $ }) { + const response = await this.hamsa.createAIContent({ + $, + params: { + jobId: this.jobId, + }, + data: { + aiParts: this.aiParts, + }, + }); + + $.export("$summary", `AI content creation job created with ID: ${response.data.id}`); + + return response; + }, +}; diff --git a/components/hamsa/actions/list-jobs/list-jobs.mjs b/components/hamsa/actions/list-jobs/list-jobs.mjs new file mode 100644 index 0000000000000..ecb471b0cc7f0 --- /dev/null +++ b/components/hamsa/actions/list-jobs/list-jobs.mjs @@ -0,0 +1,21 @@ +import hamsa from "../../hamsa.app.mjs"; + +export default { + key: "hamsa-list-jobs", + name: "List Jobs", + description: "Fetch the list of jobs from Hamsa. [See the documentation](https://docs.tryhamsa.com/api-reference/endpoint/get-jobs-list)", + version: "0.0.1", + type: "action", + props: { + hamsa, + }, + async run({ $ }) { + const response = await this.hamsa.listJobs({ + $, + }); + + $.export("$summary", `Successfully fetched ${response?.data?.jobs?.length} jobs.`); + + return response; + }, +}; diff --git a/components/hamsa/actions/synthesize-voice/synthesize-voice.mjs b/components/hamsa/actions/synthesize-voice/synthesize-voice.mjs new file mode 100644 index 0000000000000..843f8beb6cc6f --- /dev/null +++ b/components/hamsa/actions/synthesize-voice/synthesize-voice.mjs @@ -0,0 +1,66 @@ +import hamsa from "../../hamsa.app.mjs"; + +export default { + key: "hamsa-synthesize-voice", + name: "Synthesize Voice", + description: "Converts text input into artificial speech using Hamsa. [See the documentation](https://docs.tryhamsa.com/api-reference/endpoint/generate-tts)", + version: "0.0.1", + type: "action", + props: { + hamsa, + voiceId: { + propDefinition: [ + hamsa, + "voiceId", + ], + }, + text: { + type: "string", + label: "Text for TTS", + description: "The text you want to convert to speech. Minimum 5 words required.", + }, + webhookUrl: { + propDefinition: [ + hamsa, + "webhookUrl", + ], + optional: true, + }, + webhookAuthKey: { + type: "string", + label: "Webhook Auth Key", + description: "Authorization key for the webhook notifications.", + optional: true, + }, + webhookAuthSecret: { + type: "string", + label: "Webhook Auth Secret", + description: "Authorization secret for the webhook notifications.", + optional: true, + }, + }, + async run({ $ }) { + const webhookAuth = {}; + if (this.webhookAuthKey) { + webhookAuth.authKey = this.webhookAuthKey; + } + if (this.webhookAuthSecret) { + webhookAuth.authSecret = this.webhookAuthSecret; + } + const data = { + voiceId: this.voiceId, + text: this.text, + webhookUrl: this.webhookUrl, + }; + if (Object.keys(webhookAuth).length) { + data.webhookAuth = webhookAuth; + } + const response = await this.hamsa.generateTTS({ + $, + data, + }); + + $.export("$summary", `Text to speech job successfully created with ID ${response.data.id}`); + return response; + }, +}; diff --git a/components/hamsa/actions/transcribe-video/transcribe-video.mjs b/components/hamsa/actions/transcribe-video/transcribe-video.mjs new file mode 100644 index 0000000000000..c0fa078ecffb5 --- /dev/null +++ b/components/hamsa/actions/transcribe-video/transcribe-video.mjs @@ -0,0 +1,88 @@ +import { + LANGUAGE_OPTIONS, + MODEL_OPTIONS, +} from "../../common/constants.mjs"; +import hamsa from "../../hamsa.app.mjs"; + +export default { + key: "hamsa-transcribe-video", + name: "Transcribe Video", + description: "Automatically transcribe Arabic videos from YouTube URLs or direct links. [See the documentation](https://docs.tryhamsa.com/api-reference/endpoint/transcribe)", + version: "0.0.1", + type: "action", + props: { + hamsa, + mediaUrl: { + type: "string", + label: "Media URL", + description: "The URL of the video to be transcribed.", + }, + model: { + type: "string", + label: "Model", + description: "The model you want to use to transcribe.", + options: MODEL_OPTIONS, + }, + webhookUrl: { + propDefinition: [ + hamsa, + "webhookUrl", + ], + optional: true, + }, + webhookAuthKey: { + type: "string", + label: "Webhook Auth Key", + description: "The key to use for authenticating the webhook.", + optional: true, + }, + webhookAuthSecret: { + type: "string", + label: "Webhook Auth Secret", + description: "The secret to use for authenticating the webhook.", + secret: true, + optional: true, + }, + title: { + type: "string", + label: "Title", + description: "The title of the transcription.", + optional: true, + }, + language: { + type: "string", + label: "Language", + description: "The language of the transcription.", + options: LANGUAGE_OPTIONS, + optional: true, + }, + }, + async run({ $ }) { + const webhookAuth = {}; + if (this.webhookAuthKey) { + webhookAuth.authKey = this.webhookAuthKey; + } + if (this.webhookAuthSecret) { + webhookAuth.authSecret = this.webhookAuthSecret; + } + const data = { + mediaUrl: this.mediaUrl, + model: this.model, + processingType: "async", + webhookUrl: this.webhookUrl, + title: this.title, + language: this.language, + }; + if (Object.keys(webhookAuth).length) { + data.webhookAuth = webhookAuth; + } + + const response = await this.hamsa.transcribeVideo({ + $, + data, + }); + + $.export("$summary", "Transcription job started successfully."); + return response; + }, +}; diff --git a/components/hamsa/common/constants.mjs b/components/hamsa/common/constants.mjs new file mode 100644 index 0000000000000..83d62eff0a1be --- /dev/null +++ b/components/hamsa/common/constants.mjs @@ -0,0 +1,68 @@ +export const LIMIT = 100; + +export const MODEL_OPTIONS = [ + { + label: "Hamsa-General-V2.0 - Our most advanced ASR model, optimized for high accuracy across podcasts, videos, and general audio.", + value: "Hamsa-General-V2.0", + }, + { + label: "Hamsa-Conversational-V1.0 - Best suited for conversational use cases, optimized for accurately transcribing phone calls and meetings.", + value: "Hamsa-Conversational-V1.0", + }, +]; + +export const LANGUAGE_OPTIONS = [ + "ar", + "en", +]; + +export const AI_PARTS_OPTIONS = [ + { + label: "Introduction", + value: "introduction", + }, + { + label: "Titles", + value: "titles", + }, + { + label: "Summary", + value: "summary", + }, + { + label: "Web Article SEO Friendly", + value: "webArticleSEOFriendly", + }, + { + label: "Key Topics With Bullets", + value: "keyTopicsWithBullets", + }, + { + label: "Keywords", + value: "keywords", + }, + { + label: "Threads By Instagram", + value: "threadsByInstagram", + }, + { + label: "FAQ", + value: "faq", + }, + { + label: "Facebook Post", + value: "facebookPost", + }, + { + label: "YouTube Description", + value: "youtubeDescription", + }, + { + label: "Twitter Thread", + value: "twitterThread", + }, + { + label: "LinkedIn Post", + value: "linkedInPost", + }, +]; diff --git a/components/hamsa/hamsa.app.mjs b/components/hamsa/hamsa.app.mjs index f531675faa474..3dab4270657d3 100644 --- a/components/hamsa/hamsa.app.mjs +++ b/components/hamsa/hamsa.app.mjs @@ -1,11 +1,121 @@ +import { axios } from "@pipedream/platform"; +import { LIMIT } from "./common/constants.mjs"; + export default { type: "app", app: "hamsa", - propDefinitions: {}, + propDefinitions: { + jobId: { + type: "string", + label: "Job Id", + description: "The ID of the job you want to use.", + async options({ page }) { + const { data: { jobs } } = await this.listJobs({ + params: { + take: LIMIT, + skip: page * LIMIT, + }, + }); + + return jobs.map(({ + id: value, title: label, + }) => ({ + label, + value, + })); + }, + }, + voiceId: { + type: "string", + label: "Voice ID", + description: "The voice ID for Text to Speech conversion.", + async options({ page }) { + const params = { + take: LIMIT, + }; + if (page) { + params.skip = page * LIMIT; + } + const { data } = await this.listVoices({ + params, + }); + + return data.map(({ + id: value, name, tags, + }) => ({ + label: `${name} (${tags.join(" - ")})`, + value, + })); + }, + }, + webhookUrl: { + type: "string", + label: "Webhook URL", + description: "The URL to receive the webhook notifications.", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.tryhamsa.com/v1"; + }, + _headers() { + return { + "authorization": `Token ${this.$auth.api_key}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: this._baseUrl() + path, + headers: this._headers(), + ...opts, + }); + }, + async listJobs({ + params, ...opts + }) { + const { data: { id: projectId } } = await this._makeRequest({ + path: "/projects/by-api-key", + ...opts, + }); + + return this._makeRequest({ + method: "POST", + path: "/jobs/all", + params: { + ...params, + projectId, + }, + ...opts, + }); + }, + listVoices(opts = {}) { + return this._makeRequest({ + path: "/tts/voices", + ...opts, + }); + }, + transcribeVideo(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/jobs/transcribe", + ...opts, + }); + }, + generateTTS(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/jobs/text-to-speech", + ...opts, + }); + }, + createAIContent(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/jobs/ai-content", + ...opts, + }); }, }, }; diff --git a/components/hamsa/package.json b/components/hamsa/package.json index 3e9a0c9fd4bce..8c5f0faae14fb 100644 --- a/components/hamsa/package.json +++ b/components/hamsa/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/hamsa", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Hamsa Components", "main": "hamsa.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 88c0fcbfb9798..a68a4edf98b36 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4308,8 +4308,7 @@ importers: components/facebook_conversions: {} - components/facebook_graph_api: - specifiers: {} + components/facebook_graph_api: {} components/facebook_groups: dependencies: @@ -4929,8 +4928,7 @@ importers: components/gatekeeper: {} - components/gather: - specifiers: {} + components/gather: {} components/gatherup: dependencies: @@ -5786,7 +5784,11 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/hamsa: {} + components/hamsa: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/handwrytten: {}