Skip to content

Commit 696d83f

Browse files
authored
[Components] speak_ai - new components (#16256)
1 parent bf65598 commit 696d83f

File tree

13 files changed

+934
-7
lines changed

13 files changed

+934
-7
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import app from "../../speak_ai.app.mjs";
2+
3+
export default {
4+
key: "speak_ai-analyze-text",
5+
name: "Analyze Text",
6+
description: "Analyzes a block of text for key insights, sentiment, and keyword extraction using Speak Ai's NLP engine. [See the documentation](https://docs.speakai.co/#d65573c9-98ad-4089-93ad-9d0a173fdeea).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
folderId: {
12+
propDefinition: [
13+
app,
14+
"folderId",
15+
],
16+
},
17+
mediaId: {
18+
propDefinition: [
19+
app,
20+
"mediaId",
21+
({ folderId }) => ({
22+
folderId,
23+
mediaType: "text",
24+
}),
25+
],
26+
},
27+
},
28+
async run({ $ }) {
29+
const {
30+
app,
31+
mediaId,
32+
} = this;
33+
34+
const response = await app.getTextInsight({
35+
$,
36+
mediaId,
37+
});
38+
39+
$.export("$summary", `Successfully analyzed text with ID \`${response.data.mediaId}\`.`);
40+
return response;
41+
},
42+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import app from "../../speak_ai.app.mjs";
2+
3+
export default {
4+
key: "speak_ai-get-transcription",
5+
name: "Get Transcription",
6+
description: "Retrieve the full transcription of a processed media file. [See the documentation](https://docs.speakai.co/#0b586e5b-6e0a-4b79-b440-e6889a803ccd).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
folderId: {
12+
propDefinition: [
13+
app,
14+
"folderId",
15+
],
16+
},
17+
mediaId: {
18+
propDefinition: [
19+
app,
20+
"mediaId",
21+
({ folderId }) => ({
22+
folderId,
23+
}),
24+
],
25+
},
26+
},
27+
async run({ $ }) {
28+
const {
29+
app,
30+
mediaId,
31+
} = this;
32+
33+
const response = await app.getInsight({
34+
$,
35+
mediaId,
36+
});
37+
38+
$.export("$summary", `Successfully retrieved transcription for media ID \`${response.data.mediaId}\`.`);
39+
return response.data.insight.transcript;
40+
},
41+
};
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import app from "../../speak_ai.app.mjs";
2+
3+
export default {
4+
key: "speak_ai-upload-media",
5+
name: "Upload Media",
6+
description: "Upload an audio or video file for transcription and natural language processing into Speak AI. [See the documentation](https://docs.speakai.co/#c6106a66-6a3d-4b05-b4a2-4a68a4c1e95d).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
type: "string",
13+
label: "Name",
14+
description: "Name of the media file",
15+
},
16+
url: {
17+
type: "string",
18+
label: "URL",
19+
description: "Public URL or AWS signed URL",
20+
},
21+
mediaType: {
22+
propDefinition: [
23+
app,
24+
"mediaType",
25+
],
26+
},
27+
folderId: {
28+
propDefinition: [
29+
app,
30+
"folderId",
31+
],
32+
},
33+
description: {
34+
type: "string",
35+
label: "Description",
36+
description: "Description of the media file",
37+
optional: true,
38+
},
39+
tags: {
40+
type: "string[]",
41+
label: "Tags",
42+
description: "Optional metadata tags for the media file upload",
43+
optional: true,
44+
},
45+
},
46+
methods: {
47+
uploadMedia(args = {}) {
48+
return this.app.post({
49+
path: "/media/upload",
50+
...args,
51+
});
52+
},
53+
},
54+
async run({ $ }) {
55+
const {
56+
uploadMedia,
57+
name,
58+
url,
59+
mediaType,
60+
folderId,
61+
description,
62+
tags,
63+
} = this;
64+
65+
const response = await uploadMedia({
66+
$,
67+
data: {
68+
name,
69+
url,
70+
mediaType,
71+
folderId,
72+
description,
73+
tags: Array.isArray(tags)
74+
? tags.join(",")
75+
: tags,
76+
},
77+
});
78+
79+
$.export("$summary", `Successfully uploaded media with ID \`${response.data.mediaId}\`.`);
80+
return response;
81+
},
82+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const BASE_URL = "https://api.speakai.co";
2+
const VERSION_PATH = "/v1";
3+
4+
const DEFAULT_LIMIT = 50;
5+
6+
const WEBHOOK_ID = "webhookId";
7+
8+
export default {
9+
BASE_URL,
10+
VERSION_PATH,
11+
DEFAULT_LIMIT,
12+
WEBHOOK_ID,
13+
};

components/speak_ai/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/speak_ai",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Speak AI Components",
55
"main": "speak_ai.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default {
2+
MEDIA_CREATED: "media.created",
3+
MEDIA_ANALYZED: "media.analyzed",
4+
MEDIA_REANALYZED: "media.reanalyzed",
5+
MEDIA_FAILED: "media.failed",
6+
TEXT_CREATED: "text.created",
7+
TEXT_ANALYZED: "text.analyzed",
8+
TEXT_REANALYZED: "text.reanalyzed",
9+
TEXT_FAILED: "text.failed",
10+
TEXT_DELETED: "text.deleted",
11+
EMBED_RECORDER_CREATED: "embed_recorder.created",
12+
EMBED_RECORDER_DELETED: "embed_recorder.deleted",
13+
EMBED_RECORDER_RECORDING_RECEIVED: "embed_recorder.recording_received",
14+
MEETING_ASSISTANT_STATUS: "meeting_assistant.status",
15+
CHAT_STATUS: "chat.status",
16+
CSV_UPLOADED: "csv.uploaded",
17+
CSV_FAILED: "csv.failed",
18+
};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import app from "../../speak_ai.app.mjs";
3+
import constants from "../../common/constants.mjs";
4+
5+
export default {
6+
props: {
7+
app,
8+
db: "$.service.db",
9+
http: "$.interface.http",
10+
},
11+
hooks: {
12+
async activate() {
13+
const {
14+
http: { endpoint: callbackUrl },
15+
createWebhook,
16+
getEvents,
17+
setWebhookId,
18+
} = this;
19+
20+
const response =
21+
await createWebhook({
22+
data: {
23+
callbackUrl,
24+
events: getEvents(),
25+
},
26+
});
27+
28+
setWebhookId(response.data.webhookId);
29+
},
30+
async deactivate() {
31+
const {
32+
deleteWebhook,
33+
getWebhookId,
34+
} = this;
35+
36+
const webhookId = getWebhookId();
37+
if (webhookId) {
38+
await deleteWebhook({
39+
webhookId,
40+
});
41+
}
42+
},
43+
},
44+
methods: {
45+
generateMeta() {
46+
throw new ConfigurationError("generateMeta is not implemented");
47+
},
48+
setWebhookId(value) {
49+
this.db.set(constants.WEBHOOK_ID, value);
50+
},
51+
getWebhookId() {
52+
return this.db.get(constants.WEBHOOK_ID);
53+
},
54+
getEvents() {
55+
throw new ConfigurationError("getEvents is not implemented");
56+
},
57+
async getData(resource) {
58+
return resource;
59+
},
60+
async processResource(resource) {
61+
const data = await this.getData(resource);
62+
this.$emit({
63+
...resource,
64+
data,
65+
}, this.generateMeta(resource));
66+
},
67+
createWebhook(args = {}) {
68+
return this.app.post({
69+
debug: true,
70+
path: "/webhook",
71+
...args,
72+
});
73+
},
74+
deleteWebhook({
75+
webhookId, ...args
76+
} = {}) {
77+
return this.app.delete({
78+
debug: true,
79+
path: `/webhook/${webhookId}`,
80+
...args,
81+
});
82+
},
83+
},
84+
async run({ body }) {
85+
await this.processResource(body);
86+
},
87+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import common from "../common/webhook.mjs";
2+
import events from "../common/events.mjs";
3+
import sampleEmit from "./test-event.mjs";
4+
5+
export default {
6+
...common,
7+
key: "speak_ai-new-media-created-instant",
8+
name: "New Media Created (Instant)",
9+
description: "Emit new event when a new media file is created. Useful for initiating workflows based on new media intake. [See the documentation](https://docs.speakai.co/#5777a89c-a6c3-4d0e-aab1-d33fdec5cbe8).",
10+
version: "0.0.1",
11+
type: "source",
12+
dedupe: "unique",
13+
methods: {
14+
...common.methods,
15+
getEvents() {
16+
return [
17+
events.MEDIA_CREATED,
18+
];
19+
},
20+
async getData(resource) {
21+
const { data } = await this.app.getInsight({
22+
mediaId: resource.mediaId,
23+
});
24+
return data;
25+
},
26+
generateMeta(resource) {
27+
return {
28+
id: resource.mediaId,
29+
summary: `New Media Created: ${resource.mediaId}`,
30+
ts: Date.now(),
31+
};
32+
},
33+
},
34+
sampleEmit,
35+
};

0 commit comments

Comments
 (0)