Skip to content

Commit 5561c97

Browse files
authored
New Components - zendesk_sell (#14583)
* new sources * new actions * pnpm-lock.yaml
1 parent 9241d4c commit 5561c97

File tree

10 files changed

+595
-8
lines changed

10 files changed

+595
-8
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import zendeskSell from "../../zendesk_sell.app.mjs";
2+
3+
export default {
4+
key: "zendesk_sell-create-contact",
5+
name: "Create Contact",
6+
description: "Creates a new contact. [See the documentation](https://developer.zendesk.com/api-reference/sales-crm/resources/contacts/#create-a-contact).",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
zendeskSell,
11+
isOrganization: {
12+
propDefinition: [
13+
zendeskSell,
14+
"isOrganization",
15+
],
16+
reloadProps: true,
17+
},
18+
status: {
19+
propDefinition: [
20+
zendeskSell,
21+
"status",
22+
],
23+
},
24+
title: {
25+
propDefinition: [
26+
zendeskSell,
27+
"title",
28+
],
29+
},
30+
description: {
31+
propDefinition: [
32+
zendeskSell,
33+
"description",
34+
],
35+
},
36+
email: {
37+
propDefinition: [
38+
zendeskSell,
39+
"email",
40+
],
41+
},
42+
phone: {
43+
propDefinition: [
44+
zendeskSell,
45+
"phone",
46+
],
47+
},
48+
},
49+
async additionalProps() {
50+
const props = {};
51+
if (this.isOrganization) {
52+
props.name = {
53+
type: "string",
54+
label: "Name",
55+
description: "Name of the contact",
56+
};
57+
} else {
58+
props.firstName = {
59+
type: "string",
60+
label: "First Name",
61+
description: "First name of the contact",
62+
};
63+
props.lastName = {
64+
type: "string",
65+
label: "Last Name",
66+
description: "Last name of the contact",
67+
};
68+
}
69+
return props;
70+
},
71+
async run({ $ }) {
72+
const response = await this.zendeskSell.createContact({
73+
$,
74+
data: {
75+
data: {
76+
is_organization: this.isOrganization,
77+
name: this.name,
78+
first_name: this.firstName,
79+
last_name: this.lastName,
80+
customer_status: this.status,
81+
title: this.title,
82+
description: this.description,
83+
email: this.email,
84+
phone: this.phone,
85+
},
86+
},
87+
});
88+
$.export("$summary", `Successfully created contact with ID ${response.data.id}`);
89+
return response;
90+
},
91+
};
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import zendeskSell from "../../zendesk_sell.app.mjs";
2+
3+
export default {
4+
key: "zendesk_sell-create-lead",
5+
name: "Create Lead",
6+
description: "Creates a new lead. [See the documentation](https://developer.zendesk.com/api-reference/sales-crm/resources/leads/#create-a-lead).",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
zendeskSell,
11+
isOrganization: {
12+
propDefinition: [
13+
zendeskSell,
14+
"isOrganization",
15+
],
16+
description: "Indicator of whether or not this lead refers to an organization or an individual",
17+
reloadProps: true,
18+
},
19+
status: {
20+
propDefinition: [
21+
zendeskSell,
22+
"status",
23+
],
24+
description: "The status of the lead",
25+
},
26+
title: {
27+
propDefinition: [
28+
zendeskSell,
29+
"title",
30+
],
31+
description: "The lead’s job title",
32+
},
33+
description: {
34+
propDefinition: [
35+
zendeskSell,
36+
"description",
37+
],
38+
description: "The lead’s description",
39+
},
40+
email: {
41+
propDefinition: [
42+
zendeskSell,
43+
"email",
44+
],
45+
description: "The lead’s email address",
46+
},
47+
phone: {
48+
propDefinition: [
49+
zendeskSell,
50+
"phone",
51+
],
52+
description: "The lead’s phone number",
53+
},
54+
},
55+
async additionalProps() {
56+
const props = {};
57+
if (this.isOrganization) {
58+
props.name = {
59+
type: "string",
60+
label: "Name",
61+
description: "Name of the lead",
62+
};
63+
} else {
64+
props.firstName = {
65+
type: "string",
66+
label: "First Name",
67+
description: "First name of the lead",
68+
};
69+
props.lastName = {
70+
type: "string",
71+
label: "Last Name",
72+
description: "Last name of the lead",
73+
};
74+
}
75+
return props;
76+
},
77+
async run({ $ }) {
78+
const response = await this.zendeskSell.createLead({
79+
$,
80+
data: {
81+
data: {
82+
first_name: this.firstName,
83+
last_name: this.lastName,
84+
organization_name: this.name,
85+
status: this.status,
86+
title: this.title,
87+
description: this.description,
88+
email: this.email,
89+
phone: this.phone,
90+
},
91+
},
92+
});
93+
$.export("$summary", `Successfully created lead with ID ${response.data.id}`);
94+
return response;
95+
},
96+
};
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import zendeskSell from "../../zendesk_sell.app.mjs";
2+
3+
export default {
4+
key: "zendesk_sell-create-task",
5+
name: "Create Task",
6+
description: "Creates a new task. [See the documentation](https://developer.zendesk.com/api-reference/sales-crm/resources/tasks/#create-a-task).",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
zendeskSell,
11+
resourceType: {
12+
type: "string",
13+
label: "Resource Type",
14+
description: "Name of the resource type the task is attached to",
15+
options: [
16+
"contact",
17+
"lead",
18+
"deal",
19+
],
20+
reloadProps: true,
21+
},
22+
contactId: {
23+
propDefinition: [
24+
zendeskSell,
25+
"contactId",
26+
],
27+
hidden: true,
28+
},
29+
leadId: {
30+
propDefinition: [
31+
zendeskSell,
32+
"leadId",
33+
],
34+
hidden: true,
35+
},
36+
dealId: {
37+
propDefinition: [
38+
zendeskSell,
39+
"dealId",
40+
],
41+
hidden: true,
42+
},
43+
content: {
44+
type: "string",
45+
label: "Content",
46+
description: "Content of the task",
47+
},
48+
completed: {
49+
type: "boolean",
50+
label: "Completed",
51+
description: "Indicator of whether the task is completed or not",
52+
optional: true,
53+
},
54+
dueDate: {
55+
type: "string",
56+
label: "Due Date",
57+
description: "Date and time the task is due in UTC (ISO8601 format)",
58+
optional: true,
59+
},
60+
},
61+
async additionalProps(props) {
62+
props.contactId.hidden = this.resourceType !== "contact";
63+
props.leadId.hidden = this.resourceType !== "lead";
64+
props.dealId.hidden = this.resourceType !== "deal";
65+
return {};
66+
},
67+
async run({ $ }) {
68+
const response = await this.zendeskSell.createTask({
69+
$,
70+
data: {
71+
data: {
72+
resource_type: this.resourceType,
73+
resource_id: this.resourceType === "contact"
74+
? this.contactId
75+
: this.resourceType === "lead"
76+
? this.leadId
77+
: this.dealId,
78+
content: this.content,
79+
completed: this.completed,
80+
due_date: this.dueDate,
81+
},
82+
},
83+
});
84+
return response;
85+
},
86+
};

components/zendesk_sell/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/zendesk_sell",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Zendesk Sell Components",
55
"main": "zendesk_sell.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.3"
1417
}
15-
}
18+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import zendeskSell from "../../zendesk_sell.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
4+
export default {
5+
props: {
6+
zendeskSell,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
hooks: {
16+
async deploy() {
17+
await this.processEvent(25);
18+
},
19+
},
20+
methods: {
21+
_getLastTs() {
22+
return this.db.get("lastTs") || 0;
23+
},
24+
_setLastTs(lastTs) {
25+
this.db.set("lastTs", lastTs);
26+
},
27+
getTsField() {
28+
return "created_at";
29+
},
30+
getParams() {
31+
return {
32+
sort_by: `${this.getTsField()}:desc`,
33+
};
34+
},
35+
generateMeta(item) {
36+
return {
37+
id: item.id,
38+
summary: this.getSummary(item),
39+
ts: Date.parse(item[this.getTsField()]),
40+
};
41+
},
42+
getResourceFn() {
43+
throw new Error("getResourceFn is not implemented");
44+
},
45+
getSummary() {
46+
throw new Error("getSummary is not implemented");
47+
},
48+
async processEvent(max) {
49+
const lastTs = this._getLastTs();
50+
const fn = this.getResourceFn();
51+
const params = this.getParams();
52+
const tsField = this.getTsField();
53+
54+
const results = this.zendeskSell.paginate({
55+
fn,
56+
params,
57+
max,
58+
});
59+
60+
const items = [];
61+
for await (const result of results) {
62+
const { data: item } = result;
63+
const ts = Date.parse(item[tsField]);
64+
if (ts >= lastTs) {
65+
items.push(item);
66+
} else {
67+
break;
68+
}
69+
}
70+
71+
if (!items?.length) {
72+
return;
73+
}
74+
75+
this._setLastTs(Date.parse(items[0][tsField]));
76+
77+
items.forEach((item) => {
78+
const meta = this.generateMeta(item);
79+
this.$emit(item, meta);
80+
});
81+
},
82+
},
83+
async run() {
84+
await this.processEvent();
85+
},
86+
};

0 commit comments

Comments
 (0)