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
91 changes: 91 additions & 0 deletions components/zendesk_sell/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import zendeskSell from "../../zendesk_sell.app.mjs";

export default {
key: "zendesk_sell-create-contact",
name: "Create Contact",
description: "Creates a new contact. [See the documentation](https://developer.zendesk.com/api-reference/sales-crm/resources/contacts/#create-a-contact).",
type: "action",
version: "0.0.1",
props: {
zendeskSell,
isOrganization: {
propDefinition: [
zendeskSell,
"isOrganization",
],
reloadProps: true,
},
status: {
propDefinition: [
zendeskSell,
"status",
],
},
title: {
propDefinition: [
zendeskSell,
"title",
],
},
description: {
propDefinition: [
zendeskSell,
"description",
],
},
email: {
propDefinition: [
zendeskSell,
"email",
],
},
phone: {
propDefinition: [
zendeskSell,
"phone",
],
},
},
async additionalProps() {
const props = {};
if (this.isOrganization) {
props.name = {
type: "string",
label: "Name",
description: "Name of the contact",
};
} else {
props.firstName = {
type: "string",
label: "First Name",
description: "First name of the contact",
};
props.lastName = {
type: "string",
label: "Last Name",
description: "Last name of the contact",
};
}
return props;
},
async run({ $ }) {
const response = await this.zendeskSell.createContact({
$,
data: {
data: {
is_organization: this.isOrganization,
name: this.name,
first_name: this.firstName,
last_name: this.lastName,
customer_status: this.status,
title: this.title,
description: this.description,
email: this.email,
phone: this.phone,
},
},
});
$.export("$summary", `Successfully created contact with ID ${response.data.id}`);
return response;
},
};
96 changes: 96 additions & 0 deletions components/zendesk_sell/actions/create-lead/create-lead.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import zendeskSell from "../../zendesk_sell.app.mjs";

export default {
key: "zendesk_sell-create-lead",
name: "Create Lead",
description: "Creates a new lead. [See the documentation](https://developer.zendesk.com/api-reference/sales-crm/resources/leads/#create-a-lead).",
type: "action",
version: "0.0.1",
props: {
zendeskSell,
isOrganization: {
propDefinition: [
zendeskSell,
"isOrganization",
],
description: "Indicator of whether or not this lead refers to an organization or an individual",
reloadProps: true,
},
status: {
propDefinition: [
zendeskSell,
"status",
],
description: "The status of the lead",
},
title: {
propDefinition: [
zendeskSell,
"title",
],
description: "The lead’s job title",
},
description: {
propDefinition: [
zendeskSell,
"description",
],
description: "The lead’s description",
},
email: {
propDefinition: [
zendeskSell,
"email",
],
description: "The lead’s email address",
},
phone: {
propDefinition: [
zendeskSell,
"phone",
],
description: "The lead’s phone number",
},
},
async additionalProps() {
const props = {};
if (this.isOrganization) {
props.name = {
type: "string",
label: "Name",
description: "Name of the lead",
};
} else {
props.firstName = {
type: "string",
label: "First Name",
description: "First name of the lead",
};
props.lastName = {
type: "string",
label: "Last Name",
description: "Last name of the lead",
};
}
return props;
},
async run({ $ }) {
const response = await this.zendeskSell.createLead({
$,
data: {
data: {
first_name: this.firstName,
last_name: this.lastName,
organization_name: this.name,
status: this.status,
title: this.title,
description: this.description,
email: this.email,
phone: this.phone,
},
},
});
$.export("$summary", `Successfully created lead with ID ${response.data.id}`);
return response;
},
};
86 changes: 86 additions & 0 deletions components/zendesk_sell/actions/create-task/create-task.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import zendeskSell from "../../zendesk_sell.app.mjs";

export default {
key: "zendesk_sell-create-task",
name: "Create Task",
description: "Creates a new task. [See the documentation](https://developer.zendesk.com/api-reference/sales-crm/resources/tasks/#create-a-task).",
type: "action",
version: "0.0.1",
props: {
zendeskSell,
resourceType: {
type: "string",
label: "Resource Type",
description: "Name of the resource type the task is attached to",
options: [
"contact",
"lead",
"deal",
],
reloadProps: true,
},
contactId: {
propDefinition: [
zendeskSell,
"contactId",
],
hidden: true,
},
leadId: {
propDefinition: [
zendeskSell,
"leadId",
],
hidden: true,
},
dealId: {
propDefinition: [
zendeskSell,
"dealId",
],
hidden: true,
},
content: {
type: "string",
label: "Content",
description: "Content of the task",
},
completed: {
type: "boolean",
label: "Completed",
description: "Indicator of whether the task is completed or not",
optional: true,
},
dueDate: {
type: "string",
label: "Due Date",
description: "Date and time the task is due in UTC (ISO8601 format)",
optional: true,
},
},
async additionalProps(props) {
props.contactId.hidden = this.resourceType !== "contact";
props.leadId.hidden = this.resourceType !== "lead";
props.dealId.hidden = this.resourceType !== "deal";
return {};
},
async run({ $ }) {
const response = await this.zendeskSell.createTask({
$,
data: {
data: {
resource_type: this.resourceType,
resource_id: this.resourceType === "contact"
? this.contactId
: this.resourceType === "lead"
? this.leadId
: this.dealId,
content: this.content,
completed: this.completed,
due_date: this.dueDate,
},
},
});
return response;
},
};
7 changes: 5 additions & 2 deletions components/zendesk_sell/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/zendesk_sell",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Zendesk Sell Components",
"main": "zendesk_sell.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
86 changes: 86 additions & 0 deletions components/zendesk_sell/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import zendeskSell from "../../zendesk_sell.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
props: {
zendeskSell,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
hooks: {
async deploy() {
await this.processEvent(25);
},
},
methods: {
_getLastTs() {
return this.db.get("lastTs") || 0;
},
_setLastTs(lastTs) {
this.db.set("lastTs", lastTs);
},
getTsField() {
return "created_at";
},
getParams() {
return {
sort_by: `${this.getTsField()}:desc`,
};
},
generateMeta(item) {
return {
id: item.id,
summary: this.getSummary(item),
ts: Date.parse(item[this.getTsField()]),
};
},
getResourceFn() {
throw new Error("getResourceFn is not implemented");
},
getSummary() {
throw new Error("getSummary is not implemented");
},
async processEvent(max) {
const lastTs = this._getLastTs();
const fn = this.getResourceFn();
const params = this.getParams();
const tsField = this.getTsField();

const results = this.zendeskSell.paginate({
fn,
params,
max,
});

const items = [];
for await (const result of results) {
const { data: item } = result;
const ts = Date.parse(item[tsField]);
if (ts >= lastTs) {
items.push(item);
} else {
break;
}
}

if (!items?.length) {
return;
}

this._setLastTs(Date.parse(items[0][tsField]));

items.forEach((item) => {
const meta = this.generateMeta(item);
this.$emit(item, meta);
});
},
},
async run() {
await this.processEvent();
},
};
Loading
Loading