Skip to content

Commit 6cef93e

Browse files
authored
New Components - typeflowai (#12927)
* typeflowai init * new components * pnpm-lock.yaml
1 parent f64c1cf commit 6cef93e

File tree

10 files changed

+310
-8
lines changed

10 files changed

+310
-8
lines changed

components/typeflowai/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/typeflowai",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream TypeflowAI Components",
55
"main": "typeflowai.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.0"
1417
}
15-
}
18+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import typeflowai from "../../typeflowai.app.mjs";
2+
3+
export default {
4+
props: {
5+
typeflowai,
6+
db: "$.service.db",
7+
http: "$.interface.http",
8+
workflowIds: {
9+
propDefinition: [
10+
typeflowai,
11+
"workflowIds",
12+
],
13+
},
14+
},
15+
hooks: {
16+
async activate() {
17+
const { data: { id } } = await this.typeflowai.createWebhook({
18+
data: {
19+
url: this.http.endpoint,
20+
triggers: this.getTriggers(),
21+
workflowIds: this.workflowIds,
22+
},
23+
});
24+
this._setHookId(id);
25+
},
26+
async deactivate() {
27+
const hookId = this._getHookId();
28+
if (hookId) {
29+
await this.typeflowai.deleteWebhook({
30+
hookId,
31+
});
32+
}
33+
},
34+
},
35+
methods: {
36+
_getHookId() {
37+
return this.db.get("hookId");
38+
},
39+
_setHookId(hookId) {
40+
this.db.set("hookId", hookId);
41+
},
42+
getTriggers() {
43+
throw new Error("getTriggers is not implemented");
44+
},
45+
generateMeta() {
46+
throw new Error("generateMeta is not implemented");
47+
},
48+
},
49+
async run(event) {
50+
const { body } = event;
51+
const meta = this.generateMeta(body.data);
52+
this.$emit(body, meta);
53+
},
54+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "typeflowai-new-response-created",
7+
name: "New Response Created (Instant)",
8+
description: "Emit new event when a response is created for a workflow in TypeflowAI. [See the documentation](https://typeflowai.com/docs/api/management/webhooks)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getTriggers() {
15+
return [
16+
"responseCreated",
17+
];
18+
},
19+
generateMeta(data) {
20+
return {
21+
id: data.id,
22+
summary: `New Response Created with ID: ${data.id}`,
23+
ts: Date.parse(data.createdAt),
24+
};
25+
},
26+
},
27+
sampleEmit,
28+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export default {
2+
"webhookId": "clysvncl1000h3zacrgownemj",
3+
"event": "responseCreated",
4+
"data": {
5+
"id": "clysvvfoy00016uyngkpnkfa6",
6+
"createdAt": "2024-07-19T15:57:13.138Z",
7+
"updatedAt": "2024-07-19T15:57:13.138Z",
8+
"workflowId": "clyovrgyj00001xs7dp1q82pn",
9+
"person": null,
10+
"personAttributes": null,
11+
"finished": false,
12+
"data": {
13+
"inputType": "text",
14+
"lead-name": "Bob Ross"
15+
},
16+
"ttc": {
17+
"lead-name": 202776.6000000238
18+
},
19+
"notes": [],
20+
"tags": [],
21+
"meta": {
22+
"source": "",
23+
"url": "https://dashboard.typeflowai.com/s/clyovrgyj00001xs7dp1q82pn",
24+
"userAgent": {
25+
"browser": "Chrome",
26+
"os": "Mac OS",
27+
"device": "desktop"
28+
},
29+
"country": "US"
30+
},
31+
"singleUseId": null,
32+
"language": "default"
33+
}
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "typeflowai-new-response-finished",
7+
name: "New Response Finished (Instant)",
8+
description: "Emit new event when a response is marked as finished. [See the documentation](https://typeflowai.com/docs/api/management/webhooks)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getTriggers() {
15+
return [
16+
"responseFinished",
17+
];
18+
},
19+
generateMeta(data) {
20+
return {
21+
id: data.id,
22+
summary: `New Response Finished with ID: ${data.id}`,
23+
ts: Date.now(),
24+
};
25+
},
26+
},
27+
sampleEmit,
28+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export default {
2+
"webhookId": "clysvosum000j3zacdfyu8214",
3+
"event": "responseFinished",
4+
"data": {
5+
"id": "clysxxx5c000d6uynim7hydd4",
6+
"createdAt": "2024-07-19T16:55:08.305Z",
7+
"updatedAt": "2024-07-19T16:55:08.305Z",
8+
"workflowId": "clysxvqnt0000147rgp14gxjs",
9+
"person": null,
10+
"personAttributes": null,
11+
"finished": true,
12+
"data": {
13+
"inputType": "text",
14+
"x45vvrnfd06yl46ay1iwtpj1": "hello world"
15+
},
16+
"ttc": {
17+
"_total": 9927.100000023842,
18+
"x45vvrnfd06yl46ay1iwtpj1": 9927.100000023842
19+
},
20+
"notes": [],
21+
"tags": [],
22+
"meta": {
23+
"source": "",
24+
"url": "https://dashboard.typeflowai.com/s/clysxvqnt0000147rgp14gxjs",
25+
"userAgent": {
26+
"browser": "Chrome",
27+
"os": "Mac OS",
28+
"device": "desktop"
29+
},
30+
"country": "US"
31+
},
32+
"singleUseId": null,
33+
"language": "default"
34+
}
35+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "typeflowai-new-response-updated",
7+
name: "New Response Updated (Instant)",
8+
description: "Emit new event when a response is updated within a workflow. [See the documentation](https://typeflowai.com/docs/api/management/webhooks)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getTriggers() {
15+
return [
16+
"responseUpdated",
17+
];
18+
},
19+
generateMeta(data) {
20+
const ts = Date.parse(data.updatedAt);
21+
return {
22+
id: `${data.id}-${ts}`,
23+
summary: `New Response Updated with ID: ${data.id}`,
24+
ts,
25+
};
26+
},
27+
},
28+
sampleEmit,
29+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export default {
2+
"webhookId": "clysvo37m000i3zacvkle85xz",
3+
"event": "responseUpdated",
4+
"data": {
5+
"id": "clysvvfoy00016uyngkpnkfa6",
6+
"createdAt": "2024-07-19T15:57:13.138Z",
7+
"updatedAt": "2024-07-19T15:57:29.219Z",
8+
"workflowId": "clyovrgyj00001xs7dp1q82pn",
9+
"person": null,
10+
"personAttributes": null,
11+
"finished": false,
12+
"data": {
13+
"inputType": "text",
14+
"lead-name": "Bob Ross",
15+
"lead-company-do": "Art"
16+
},
17+
"ttc": {
18+
"lead-name": 202776.6000000238,
19+
"lead-company-do": 17130.09999999404
20+
},
21+
"notes": [],
22+
"tags": [],
23+
"meta": {
24+
"source": "",
25+
"url": "https://dashboard.typeflowai.com/s/clyovrgyj00001xs7dp1q82pn",
26+
"userAgent": {
27+
"browser": "Chrome",
28+
"os": "Mac OS",
29+
"device": "desktop"
30+
},
31+
"country": "US"
32+
},
33+
"singleUseId": null,
34+
"language": "default"
35+
}
36+
}
Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "typeflowai",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
workflowIds: {
8+
type: "string[]",
9+
label: "Workflow IDs",
10+
description: "List of workflow IDs that will trigger the webhook. If not provided, the webhook will be triggered for all workflows.",
11+
async options() {
12+
const { data } = await this.listWorkflows();
13+
return data?.map(({
14+
id: value, name: label,
15+
}) => ({
16+
value,
17+
label,
18+
})) || [];
19+
},
20+
},
21+
},
522
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
23+
_baseUrl() {
24+
return "https://dashboard.typeflowai.com/api/v1";
25+
},
26+
_makeRequest(opts = {}) {
27+
const {
28+
$ = this,
29+
path,
30+
...otherOpts
31+
} = opts;
32+
return axios($, {
33+
...otherOpts,
34+
url: `${this._baseUrl()}${path}`,
35+
headers: {
36+
"x-api-key": this.$auth.api_key,
37+
},
38+
});
39+
},
40+
listWorkflows(opts = {}) {
41+
return this._makeRequest({
42+
path: "/management/workflows",
43+
...opts,
44+
});
45+
},
46+
createWebhook(opts = {}) {
47+
return this._makeRequest({
48+
method: "POST",
49+
path: "/webhooks",
50+
...opts,
51+
});
52+
},
53+
deleteWebhook({
54+
hookId, ...opts
55+
}) {
56+
return this._makeRequest({
57+
method: "DELETE",
58+
path: `/webhooks/${hookId}`,
59+
...opts,
60+
});
961
},
1062
},
11-
};
63+
};

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)