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
88 changes: 88 additions & 0 deletions components/insighto_ai/actions/add-text-blob/add-text-blob.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import app from "../../insighto_ai.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "insighto_ai-add-text-blob",
name: "Add Text Blob",
description: "Adds a text blob into an existing data source. [See the documentation](https://api.insighto.ai/docs#/datasource/add_datasourcefile_text_blob_api_v1_datasource__datasource_id__text_blob_post)",
version: "0.0.1",
type: "action",
props: {
app,
dataSourceId: {
propDefinition: [
app,
"dataSourceId",
],
},
dataSourceType: {
propDefinition: [
app,
"dataSourceType",
({ dataSourceId }) => ({
dataSourceId,
}),
],
},
name: {
type: "string",
label: "Name",
description: "The name of the text blob.",
optional: true,
},
description: {
type: "string",
label: "Description",
description: "The description of the text blob.",
optional: true,
},
orgId: {
optional: true,
propDefinition: [
app,
"orgId",
],
},
data: {
type: "object",
label: "Attributes",
description: "The attributes of the text blob.",
optional: true,
},
},
methods: {
addTextBlob({
dataSourceId, ...args
} = {}) {
return this.app.post({
path: `/datasource/${dataSourceId}/text_blob`,
...args,
});
},
},
async run({ $ }) {
const {
addTextBlob,
dataSourceId,
dataSourceType,
name,
description,
orgId,
data,
} = this;

const response = await addTextBlob({
$,
dataSourceId,
params: {
ds_type: dataSourceType,
name,
description,
org_id: orgId,
},
data: utils.parse(data),
});
$.export("$summary", `Successfully added text blob with ID \`${response.data?.id}\``);
return response;
},
};
107 changes: 107 additions & 0 deletions components/insighto_ai/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import app from "../../insighto_ai.app.mjs";

export default {
key: "insighto_ai-create-contact",
name: "Create Contact",
description: "Creates a new contact within the system. [See the documentation](https://api.insighto.ai/docs#/contact/create_contact_api_v1_contact_post)",
version: "0.0.1",
type: "action",
props: {
app,
firstName: {
type: "string",
label: "First Name",
description: "The first name of the contact.",
},
lastName: {
type: "string",
label: "Last Name",
description: "The last name of the contact.",
},
email: {
type: "string",
label: "Email",
description: "The email address of the contact.",
},
orgId: {
optional: true,
propDefinition: [
app,
"orgId",
],
},
firstAssistantId: {
label: "First Assistant ID",
description: "The ID of the first assistant.",
optional: true,
propDefinition: [
app,
"assistantId",
],
},
lastAssistantId: {
label: "Last Assistant ID",
description: "The ID of the last assistant.",
optional: true,
propDefinition: [
app,
"assistantId",
],
},
firstWidgetId: {
label: "First Widget ID",
description: "The ID of the first widget.",
optional: true,
propDefinition: [
app,
"widgetId",
],
},
lastWidgetId: {
label: "Last Widget ID",
description: "The ID of the last widget.",
optional: true,
propDefinition: [
app,
"widgetId",
],
},
},
methods: {
createContact(args = {}) {
return this.app.post({
path: "/contact",
...args,
});
},
},
async run({ $ }) {
const {
createContact,
firstName,
lastName,
email,
orgId,
firstAssistantId,
lastAssistantId,
firstWidgetId,
lastWidgetId,
} = this;

const response = await createContact({
$,
data: {
first_name: firstName,
last_name: lastName,
email,
org_id: orgId,
first_assistant_id: firstAssistantId,
last_assistant_id: lastAssistantId,
first_widget_id: firstWidgetId,
last_widget_id: lastWidgetId,
},
});
$.export("$summary", `Successfully created contact with ID \`${response.data?.id}\``);
return response;
},
};
11 changes: 11 additions & 0 deletions components/insighto_ai/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const BASE_URL = "https://api.insighto.ai";
const VERSION_PATH = "/api/v1";
const LAST_CREATED_AT = "lastCreatedAt";
const DEFAULT_MAX = 600;

export default {
BASE_URL,
VERSION_PATH,
DEFAULT_MAX,
LAST_CREATED_AT,
};
39 changes: 39 additions & 0 deletions components/insighto_ai/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ConfigurationError } from "@pipedream/platform";

function emptyStrToUndefined(value) {
const trimmed = typeof(value) === "string" && value.trim();
return trimmed === ""
? undefined
: value;
}

function parse(value) {
const valueToParse = emptyStrToUndefined(value);
if (typeof(valueToParse) === "object" || valueToParse === undefined) {
return valueToParse;
}
try {
return JSON.parse(valueToParse);
} catch (e) {
throw new ConfigurationError("Make sure the custom expression contains a valid object");
}
}

async function iterate(iterations) {
const items = [];
for await (const item of iterations) {
items.push(item);
}
return items;
}

function getNestedProperty(obj, propertyString) {
const properties = propertyString.split(".");
return properties.reduce((prev, curr) => prev && prev[curr], obj);
}

export default {
parse,
iterate,
getNestedProperty,
};
Loading