Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions components/typeflowai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/typeflowai",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream TypeflowAI Components",
"main": "typeflowai.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
}
}
}
54 changes: 54 additions & 0 deletions components/typeflowai/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import typeflowai from "../../typeflowai.app.mjs";

export default {
props: {
typeflowai,
db: "$.service.db",
http: "$.interface.http",
workflowIds: {
propDefinition: [
typeflowai,
"workflowIds",
],
},
},
hooks: {
async activate() {
const { data: { id } } = await this.typeflowai.createWebhook({
data: {
url: this.http.endpoint,
triggers: this.getTriggers(),
workflowIds: this.workflowIds,
},
});
this._setHookId(id);
},
async deactivate() {
const hookId = this._getHookId();
if (hookId) {
await this.typeflowai.deleteWebhook({
hookId,
});
}
},
},
methods: {
_getHookId() {
return this.db.get("hookId");
},
_setHookId(hookId) {
this.db.set("hookId", hookId);
},
getTriggers() {
throw new Error("getTriggers is not implemented");
},
generateMeta() {
throw new Error("generateMeta is not implemented");
},
},
async run(event) {
const { body } = event;
const meta = this.generateMeta(body.data);
this.$emit(body, meta);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "typeflowai-new-response-created",
name: "New Response Created (Instant)",
description: "Emit new event when a response is created for a workflow in TypeflowAI. [See the documentation](https://typeflowai.com/docs/api/management/webhooks)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getTriggers() {
return [
"responseCreated",
];
},
generateMeta(data) {
return {
id: data.id,
summary: `New Response Created with ID: ${data.id}`,
ts: Date.parse(data.createdAt),
};
},
},
sampleEmit,
};
34 changes: 34 additions & 0 deletions components/typeflowai/sources/new-response-created/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export default {
"webhookId": "clysvncl1000h3zacrgownemj",
"event": "responseCreated",
"data": {
"id": "clysvvfoy00016uyngkpnkfa6",
"createdAt": "2024-07-19T15:57:13.138Z",
"updatedAt": "2024-07-19T15:57:13.138Z",
"workflowId": "clyovrgyj00001xs7dp1q82pn",
"person": null,
"personAttributes": null,
"finished": false,
"data": {
"inputType": "text",
"lead-name": "Bob Ross"
},
"ttc": {
"lead-name": 202776.6000000238
},
"notes": [],
"tags": [],
"meta": {
"source": "",
"url": "https://dashboard.typeflowai.com/s/clyovrgyj00001xs7dp1q82pn",
"userAgent": {
"browser": "Chrome",
"os": "Mac OS",
"device": "desktop"
},
"country": "US"
},
"singleUseId": null,
"language": "default"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "typeflowai-new-response-finished",
name: "New Response Finished (Instant)",
description: "Emit new event when a response is marked as finished. [See the documentation](https://typeflowai.com/docs/api/management/webhooks)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getTriggers() {
return [
"responseFinished",
];
},
generateMeta(data) {
return {
id: data.id,
summary: `New Response Finished with ID: ${data.id}`,
ts: Date.now(),
};
},
},
sampleEmit,
};
35 changes: 35 additions & 0 deletions components/typeflowai/sources/new-response-finished/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export default {
"webhookId": "clysvosum000j3zacdfyu8214",
"event": "responseFinished",
"data": {
"id": "clysxxx5c000d6uynim7hydd4",
"createdAt": "2024-07-19T16:55:08.305Z",
"updatedAt": "2024-07-19T16:55:08.305Z",
"workflowId": "clysxvqnt0000147rgp14gxjs",
"person": null,
"personAttributes": null,
"finished": true,
"data": {
"inputType": "text",
"x45vvrnfd06yl46ay1iwtpj1": "hello world"
},
"ttc": {
"_total": 9927.100000023842,
"x45vvrnfd06yl46ay1iwtpj1": 9927.100000023842
},
"notes": [],
"tags": [],
"meta": {
"source": "",
"url": "https://dashboard.typeflowai.com/s/clysxvqnt0000147rgp14gxjs",
"userAgent": {
"browser": "Chrome",
"os": "Mac OS",
"device": "desktop"
},
"country": "US"
},
"singleUseId": null,
"language": "default"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "typeflowai-new-response-updated",
name: "New Response Updated (Instant)",
description: "Emit new event when a response is updated within a workflow. [See the documentation](https://typeflowai.com/docs/api/management/webhooks)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getTriggers() {
return [
"responseUpdated",
];
},
generateMeta(data) {
const ts = Date.parse(data.updatedAt);
return {
id: `${data.id}-${ts}`,
summary: `New Response Updated with ID: ${data.id}`,
ts,
};
},
},
sampleEmit,
};
36 changes: 36 additions & 0 deletions components/typeflowai/sources/new-response-updated/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export default {
"webhookId": "clysvo37m000i3zacvkle85xz",
"event": "responseUpdated",
"data": {
"id": "clysvvfoy00016uyngkpnkfa6",
"createdAt": "2024-07-19T15:57:13.138Z",
"updatedAt": "2024-07-19T15:57:29.219Z",
"workflowId": "clyovrgyj00001xs7dp1q82pn",
"person": null,
"personAttributes": null,
"finished": false,
"data": {
"inputType": "text",
"lead-name": "Bob Ross",
"lead-company-do": "Art"
},
"ttc": {
"lead-name": 202776.6000000238,
"lead-company-do": 17130.09999999404
},
"notes": [],
"tags": [],
"meta": {
"source": "",
"url": "https://dashboard.typeflowai.com/s/clyovrgyj00001xs7dp1q82pn",
"userAgent": {
"browser": "Chrome",
"os": "Mac OS",
"device": "desktop"
},
"country": "US"
},
"singleUseId": null,
"language": "default"
}
}
62 changes: 57 additions & 5 deletions components/typeflowai/typeflowai.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,63 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "typeflowai",
propDefinitions: {},
propDefinitions: {
workflowIds: {
type: "string[]",
label: "Workflow IDs",
description: "List of workflow IDs that will trigger the webhook. If not provided, the webhook will be triggered for all workflows.",
async options() {
const { data } = await this.listWorkflows();
return data?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://dashboard.typeflowai.com/api/v1";
},
_makeRequest(opts = {}) {
const {
$ = this,
path,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
"x-api-key": this.$auth.api_key,
},
});
},
listWorkflows(opts = {}) {
return this._makeRequest({
path: "/management/workflows",
...opts,
});
},
createWebhook(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/webhooks",
...opts,
});
},
deleteWebhook({
hookId, ...opts
}) {
return this._makeRequest({
method: "DELETE",
path: `/webhooks/${hookId}`,
...opts,
});
},
},
};
};
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.