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
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import specific from "../../specific.app.mjs";

export default {
key: "specific-create-conversation",
name: "Create Conversation",
description: "Create a new conversation. [See the documentation](https://public-api.specific.app/docs/mutations/createConversation)",
version: "0.0.1",
type: "action",
props: {
specific,
content: {
type: "string",
label: "Content",
description: "Conversation content as String or ProseMirror document.",
reloadProps: true,
},
insertedAt: {
propDefinition: [
specific,
"insertedAt",
],
optional: true,
},
assignee: {
type: "string",
label: "Assignee",
description: "The user's email.",
optional: true,
},
sourceId: {
propDefinition: [
specific,
"sourceId",
],
optional: true,
},
companyId: {
propDefinition: [
specific,
"companyId",
],
optional: true,
},
contactId: {
propDefinition: [
specific,
"contactId",
],
optional: true,
},
sourceUrl: {
type: "string",
label: "Source URL",
description: "Source url where the conversation was gathered.",
optional: true,
},
},
async additionalProps() {
const props = {};
if (this.content) {
const { data: { customFields } } = await this.specific.query({
model: "customFields",
where: "{type: {equals: conversation }}",
fields: "name",
});
for (const { name } of customFields) {
props[`customField-${name}`] = {
type: "string",
label: name,
description: `Custom Field: ${name}`,
optional: true,
};
}
}
return props;
},
async run({ $ }) {
const {
specific,
...data
} = this;

const customFields = this.specific.parseCustomFields(data);

const response = await specific.mutation({
$,
model: "createConversation",
data: `{
${this.assignee
? `assignee: {
connectOrIgnore: {
email: "${this.assignee}"
}
}`
: ""}
${this.companyId
? `company: {
connect: {
id: "${this.companyId}"
}
}`
: ""}
${this.contactId
? `contact: {
connect: {
id: "${this.contactId}"
}
}`
: ""}
content: "${this.content}"
${customFields
? `customFields: ${customFields}`
: ""}
${this.insertedAt
? `insertedAt: "${this.insertedAt}"`
: ""}
${this.sourceId
? `source: {
connect: {
id: "${this.sourceId}"
}
}`
: ""}
${this.sourceUrl
? `sourceUrl: "${this.sourceUrl}"`
: ""}
}`,
fields: `
customFields
id
insertedAt
name
plainText
sourceUrl
assignee {
email
fullName
id
}
company {
contactsCount
customFields
id
name
visitorId
}
contact {
customFields
email
id
name
visitorId
}
source {
id
name
}`,
on: "Conversation",
});

if (response.errors) throw new Error(response.errors[0].message);

$.export("$summary", `Successfully created conversation for user ID: ${response.data?.createConversation?.id}`);
return response;
},
};

34 changes: 34 additions & 0 deletions components/specific/actions/find-company/find-company.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import specific from "../../specific.app.mjs";

export default {
key: "specific-find-company",
name: "Find Company",
description: "Retrieve details of a specified company. [See the documentation](https://public-api.specific.app/docs/types/Query)",
version: "0.0.1",
type: "action",
props: {
specific,
companyId: {
propDefinition: [
specific,
"companyId",
],
},
},
async run({ $ }) {
const response = await this.specific.query({
$,
model: "companies",
where: `{id: {equals: "${this.companyId}"}}`,
fields: `id
name
customFields
visitorId
contactsCount`,
on: "Company",
});

$.export("$summary", `Successfully retrieved details for company ID: ${this.companyId}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import specific from "../../specific.app.mjs";

export default {
key: "specific-update-create-contact",
name: "Update or Create Contact",
description: "Modify an existing contact's details or create a new one if the specified contact does not exist. [See the documentation](https://public-api.specific.app/docs/types/contact)",
version: "0.0.1",
type: "action",
props: {
specific,
contactEmail: {
propDefinition: [
specific,
"contactEmail",
],
reloadProps: true,
},
companyId: {
propDefinition: [
specific,
"companyId",
],
optional: true,
},
name: {
type: "string",
label: "Name",
description: "Contact's name.",
optional: true,
},
email: {
type: "string",
label: "New Email",
description: "New email to update",
optional: true,
},
},
async additionalProps() {
const props = {};
if (this.content) {
const { data: { customFields } } = await this.specific.query({
model: "customFields",
where: "{type: {equals: contact }}",
fields: "name",
});
for (const { name } of customFields) {
props[`customField-${name}`] = {
type: "string",
label: name,
description: `Custom Field: ${name}`,
optional: true,
};
}
}
return props;
},
async run({ $ }) {
const {
specific,
...data
} = this;

const customFields = this.specific.parseCustomFields(data);

const response = await specific.mutation({
$,
model: "createOrUpdateContact",
on: "CreatedOrUpdatedContacts",
data: `{
${this.companyId
? `company: {
connect: {
id: "${this.companyId}"
}
}`
: ""}
${customFields
? `customFields: ${customFields}`
: ""}
${this.email
? `email: "${this.email}"`
: ""}
${this.name
? `name: "${this.name}"`
: ""}
}`,
where: `{email: "${this.contactEmail}"}`,
fields: `
contacts {
id
name
email
visitorId
customFields
company {
contactsCount
customFields
id
name
visitorId
}
}`,
});

if (response.errors) throw new Error(response.errors[0].message);

$.export("$summary", `Successfully updated or created contact with email ${this.contactEmail}`);
return response;
},
};

8 changes: 8 additions & 0 deletions components/specific/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const stringifyObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return JSON.stringify(obj);
}
return obj;
Comment on lines +2 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhance robustness by handling other types of objects and edge cases.

The function currently only handles arrays and returns the object as is for other types. Consider enhancing it to handle other types of objects and edge cases.

export const stringifyObject = (obj) => {
  if (!obj) return undefined;

  if (Array.isArray(obj) || typeof obj === 'object') {
    return JSON.stringify(obj);
  }
  return String(obj);
};

Committable suggestion was skipped due to low confidence.

};
8 changes: 6 additions & 2 deletions components/specific/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/specific",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Specific Components",
"main": "specific.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
}
}
}

Loading