Skip to content

Commit eb5e7fc

Browse files
authored
New Components - specific (#12926)
* specific init * [Components] specific #12906 Sources - New Contact (Instant) - New Conversation (Instant) Actions - Create Conversation - Update Create Contact - Find Company * some changes * pnpm update
1 parent aa0557b commit eb5e7fc

File tree

12 files changed

+647
-8
lines changed

12 files changed

+647
-8
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import specific from "../../specific.app.mjs";
2+
3+
export default {
4+
key: "specific-create-conversation",
5+
name: "Create Conversation",
6+
description: "Create a new conversation. [See the documentation](https://public-api.specific.app/docs/mutations/createConversation)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
specific,
11+
content: {
12+
type: "string",
13+
label: "Content",
14+
description: "Conversation content as String or ProseMirror document.",
15+
reloadProps: true,
16+
},
17+
insertedAt: {
18+
propDefinition: [
19+
specific,
20+
"insertedAt",
21+
],
22+
optional: true,
23+
},
24+
assignee: {
25+
type: "string",
26+
label: "Assignee",
27+
description: "The user's email.",
28+
optional: true,
29+
},
30+
sourceId: {
31+
propDefinition: [
32+
specific,
33+
"sourceId",
34+
],
35+
optional: true,
36+
},
37+
companyId: {
38+
propDefinition: [
39+
specific,
40+
"companyId",
41+
],
42+
optional: true,
43+
},
44+
contactId: {
45+
propDefinition: [
46+
specific,
47+
"contactId",
48+
],
49+
optional: true,
50+
},
51+
sourceUrl: {
52+
type: "string",
53+
label: "Source URL",
54+
description: "Source url where the conversation was gathered.",
55+
optional: true,
56+
},
57+
},
58+
async additionalProps() {
59+
const props = {};
60+
if (this.content) {
61+
const { data: { customFields } } = await this.specific.query({
62+
model: "customFields",
63+
where: "{type: {equals: conversation }}",
64+
fields: "name",
65+
});
66+
for (const { name } of customFields) {
67+
props[`customField-${name}`] = {
68+
type: "string",
69+
label: name,
70+
description: `Custom Field: ${name}`,
71+
optional: true,
72+
};
73+
}
74+
}
75+
return props;
76+
},
77+
async run({ $ }) {
78+
const {
79+
specific,
80+
...data
81+
} = this;
82+
83+
const customFields = this.specific.parseCustomFields(data);
84+
85+
const response = await specific.mutation({
86+
$,
87+
model: "createConversation",
88+
data: `{
89+
${this.assignee
90+
? `assignee: {
91+
connectOrIgnore: {
92+
email: "${this.assignee}"
93+
}
94+
}`
95+
: ""}
96+
${this.companyId
97+
? `company: {
98+
connect: {
99+
id: "${this.companyId}"
100+
}
101+
}`
102+
: ""}
103+
${this.contactId
104+
? `contact: {
105+
connect: {
106+
id: "${this.contactId}"
107+
}
108+
}`
109+
: ""}
110+
content: "${this.content}"
111+
${customFields
112+
? `customFields: ${customFields}`
113+
: ""}
114+
${this.insertedAt
115+
? `insertedAt: "${this.insertedAt}"`
116+
: ""}
117+
${this.sourceId
118+
? `source: {
119+
connect: {
120+
id: "${this.sourceId}"
121+
}
122+
}`
123+
: ""}
124+
${this.sourceUrl
125+
? `sourceUrl: "${this.sourceUrl}"`
126+
: ""}
127+
}`,
128+
fields: `
129+
customFields
130+
id
131+
insertedAt
132+
name
133+
plainText
134+
sourceUrl
135+
assignee {
136+
email
137+
fullName
138+
id
139+
}
140+
company {
141+
contactsCount
142+
customFields
143+
id
144+
name
145+
visitorId
146+
}
147+
contact {
148+
customFields
149+
email
150+
id
151+
name
152+
visitorId
153+
}
154+
source {
155+
id
156+
name
157+
}`,
158+
on: "Conversation",
159+
});
160+
161+
if (response.errors) throw new Error(response.errors[0].message);
162+
163+
$.export("$summary", `Successfully created conversation for user ID: ${response.data?.createConversation?.id}`);
164+
return response;
165+
},
166+
};
167+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import specific from "../../specific.app.mjs";
2+
3+
export default {
4+
key: "specific-find-company",
5+
name: "Find Company",
6+
description: "Retrieve details of a specified company. [See the documentation](https://public-api.specific.app/docs/types/Query)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
specific,
11+
companyId: {
12+
propDefinition: [
13+
specific,
14+
"companyId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.specific.query({
20+
$,
21+
model: "companies",
22+
where: `{id: {equals: "${this.companyId}"}}`,
23+
fields: `id
24+
name
25+
customFields
26+
visitorId
27+
contactsCount`,
28+
on: "Company",
29+
});
30+
31+
$.export("$summary", `Successfully retrieved details for company ID: ${this.companyId}`);
32+
return response;
33+
},
34+
};
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import specific from "../../specific.app.mjs";
2+
3+
export default {
4+
key: "specific-update-create-contact",
5+
name: "Update or Create Contact",
6+
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)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
specific,
11+
contactEmail: {
12+
propDefinition: [
13+
specific,
14+
"contactEmail",
15+
],
16+
reloadProps: true,
17+
},
18+
companyId: {
19+
propDefinition: [
20+
specific,
21+
"companyId",
22+
],
23+
optional: true,
24+
},
25+
name: {
26+
type: "string",
27+
label: "Name",
28+
description: "Contact's name.",
29+
optional: true,
30+
},
31+
email: {
32+
type: "string",
33+
label: "New Email",
34+
description: "New email to update",
35+
optional: true,
36+
},
37+
},
38+
async additionalProps() {
39+
const props = {};
40+
if (this.content) {
41+
const { data: { customFields } } = await this.specific.query({
42+
model: "customFields",
43+
where: "{type: {equals: contact }}",
44+
fields: "name",
45+
});
46+
for (const { name } of customFields) {
47+
props[`customField-${name}`] = {
48+
type: "string",
49+
label: name,
50+
description: `Custom Field: ${name}`,
51+
optional: true,
52+
};
53+
}
54+
}
55+
return props;
56+
},
57+
async run({ $ }) {
58+
const {
59+
specific,
60+
...data
61+
} = this;
62+
63+
const customFields = this.specific.parseCustomFields(data);
64+
65+
const response = await specific.mutation({
66+
$,
67+
model: "createOrUpdateContact",
68+
on: "CreatedOrUpdatedContacts",
69+
data: `{
70+
${this.companyId
71+
? `company: {
72+
connect: {
73+
id: "${this.companyId}"
74+
}
75+
}`
76+
: ""}
77+
${customFields
78+
? `customFields: ${customFields}`
79+
: ""}
80+
${this.email
81+
? `email: "${this.email}"`
82+
: ""}
83+
${this.name
84+
? `name: "${this.name}"`
85+
: ""}
86+
}`,
87+
where: `{email: "${this.contactEmail}"}`,
88+
fields: `
89+
contacts {
90+
id
91+
name
92+
email
93+
visitorId
94+
customFields
95+
company {
96+
contactsCount
97+
customFields
98+
id
99+
name
100+
visitorId
101+
}
102+
}`,
103+
});
104+
105+
if (response.errors) throw new Error(response.errors[0].message);
106+
107+
$.export("$summary", `Successfully updated or created contact with email ${this.contactEmail}`);
108+
return response;
109+
},
110+
};
111+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const stringifyObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return JSON.stringify(obj);
6+
}
7+
return obj;
8+
};

components/specific/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/specific",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Specific Components",
55
"main": "specific.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
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+
}
19+

0 commit comments

Comments
 (0)