Skip to content

Commit b399c80

Browse files
authored
New Components - salespype (#15525)
* salespype init * new components * pnpm-lock.yaml * remove duplicate semicolon
1 parent 95a3fbd commit b399c80

File tree

10 files changed

+517
-7
lines changed

10 files changed

+517
-7
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import salespype from "../../salespype.app.mjs";
2+
3+
export default {
4+
key: "salespype-add-contact-to-campaign",
5+
name: "Add Contact to Campaign",
6+
description: "Adds a contact to a campaign. [See the documentation](https://documenter.getpostman.com/view/5101444/2s93Y3u1Eb#4b2f8b3e-155d-4485-9a25-4f7d98d04b53)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
salespype,
11+
campaignId: {
12+
propDefinition: [
13+
salespype,
14+
"campaignId",
15+
],
16+
},
17+
contactId: {
18+
propDefinition: [
19+
salespype,
20+
"contactId",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.salespype.addContactToCampaign({
26+
$,
27+
campaignId: this.campaignId,
28+
contactId: this.contactId,
29+
});
30+
$.export("$summary", `Added contact ${this.contactId} to campaign ${this.campaignId}`);
31+
return response;
32+
},
33+
};
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import salespype from "../../salespype.app.mjs";
2+
3+
export default {
4+
key: "salespype-create-contact",
5+
name: "Create Contact",
6+
description: "Creates a new contact in Salespype. [See the documentation](https://documenter.getpostman.com/view/5101444/2s93Y3u1Eb#0a9f8441-c7fa-48dc-b02b-0117037d86ab)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
salespype,
11+
firstName: {
12+
type: "string",
13+
label: "First Name",
14+
description: "The first name of the contact",
15+
},
16+
lastName: {
17+
type: "string",
18+
label: "Last Name",
19+
description: "The last name of the contact",
20+
},
21+
email: {
22+
type: "string",
23+
label: "Email",
24+
description: "The email address of the contact",
25+
},
26+
address: {
27+
type: "string",
28+
label: "Address",
29+
description: "The address of the contact",
30+
optional: true,
31+
},
32+
city: {
33+
type: "string",
34+
label: "City",
35+
description: "The city of the contact",
36+
optional: true,
37+
},
38+
state: {
39+
type: "string",
40+
label: "State",
41+
description: "The state of the contact",
42+
optional: true,
43+
},
44+
zip: {
45+
type: "string",
46+
label: "ZIP Code",
47+
description: "The ZIP code of the contact",
48+
optional: true,
49+
},
50+
country: {
51+
type: "string",
52+
label: "Country",
53+
description: "The country of the contact",
54+
optional: true,
55+
},
56+
companyName: {
57+
type: "string",
58+
label: "Company Name",
59+
description: "The company name of the contact",
60+
optional: true,
61+
},
62+
birthDate: {
63+
type: "string",
64+
label: "Birthdate",
65+
description: "The birthdate of the contact",
66+
optional: true,
67+
},
68+
},
69+
async run({ $ }) {
70+
const contact = await this.salespype.createContact({
71+
$,
72+
data: {
73+
firstName: this.firstName,
74+
lastName: this.lastName,
75+
email: this.email,
76+
address: this.address,
77+
city: this.city,
78+
state: this.state,
79+
zip: this.zip,
80+
country: this.country,
81+
companyName: this.companyName,
82+
birthDate: this.birthDate,
83+
},
84+
});
85+
$.export("$summary", `Created contact ${this.firstName} ${this.lastName} (${this.email})`);
86+
return contact;
87+
},
88+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import salespype from "../../salespype.app.mjs";
2+
3+
export default {
4+
key: "salespype-create-task",
5+
name: "Create Task",
6+
description: "Creates a new task in Salespype. [See the documentation](https://documenter.getpostman.com/view/5101444/2s93Y3u1Eb#a9c6449a-b844-465c-a342-deea01e52c3f)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
salespype,
11+
contactId: {
12+
propDefinition: [
13+
salespype,
14+
"contactId",
15+
],
16+
},
17+
task: {
18+
type: "string",
19+
label: "Task",
20+
description: "The task description",
21+
},
22+
taskTypeId: {
23+
propDefinition: [
24+
salespype,
25+
"taskTypeId",
26+
],
27+
},
28+
date: {
29+
type: "string",
30+
label: "Date",
31+
description: "The date for the task. E.g. `2021-02-20`",
32+
},
33+
time: {
34+
type: "string",
35+
label: "Time",
36+
description: "The time for the task. E.g. `34:00:34`",
37+
},
38+
duration: {
39+
type: "string",
40+
label: "Duration",
41+
description: "The duration of the task. E.g. `34:00:34`",
42+
},
43+
note: {
44+
type: "string",
45+
label: "Note",
46+
description: "Additional notes for the task",
47+
},
48+
},
49+
async run({ $ }) {
50+
const {
51+
task, message,
52+
} = await this.salespype.createTask({
53+
$,
54+
contactId: this.contactId,
55+
data: {
56+
task: this.task,
57+
taskTypeId: this.taskTypeId,
58+
date: this.date,
59+
time: this.time,
60+
duration: this.duration,
61+
note: this.note,
62+
},
63+
});
64+
65+
if (message) {
66+
throw new Error(`${message}`);
67+
}
68+
69+
$.export("$summary", `Created task '${this.task}' with ID ${task.id}`);
70+
return task;
71+
},
72+
};

components/salespype/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/salespype",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Salespype Components",
55
"main": "salespype.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.3",
17+
"md5": "^2.3.0"
1418
}
15-
}
19+
}
Lines changed: 135 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,142 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "salespype",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
contactId: {
8+
type: "string",
9+
label: "Contact ID",
10+
description: "The unique identifier of the contact",
11+
async options({ page }) {
12+
const { contacts } = await this.listContacts({
13+
params: {
14+
page: page + 1,
15+
},
16+
});
17+
return contacts?.map(({
18+
id: value, fullName: label,
19+
}) => ({
20+
value,
21+
label,
22+
})) || [];
23+
},
24+
},
25+
campaignId: {
26+
type: "string",
27+
label: "Campaign ID",
28+
description: "The unique identifier of the campaign",
29+
async options({ page }) {
30+
const { campaigns } = await this.listCampaigns({
31+
params: {
32+
page: page + 1,
33+
},
34+
});
35+
return campaigns?.map(({
36+
id: value, title: label,
37+
}) => ({
38+
value,
39+
label,
40+
})) || [];
41+
},
42+
},
43+
taskTypeId: {
44+
type: "string",
45+
label: "Task Type ID",
46+
description: "The unique identifier of the task type",
47+
async options() {
48+
const { taskTypes } = await this.listTaskTypes();
49+
return taskTypes?.map(({
50+
id: value, task: label,
51+
}) => ({
52+
value,
53+
label,
54+
})) || [];
55+
},
56+
},
57+
},
558
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
59+
_baseUrl() {
60+
return "https://api.pypepro.io/crm/v1";
61+
},
62+
_makeRequest({
63+
$ = this,
64+
path,
65+
...otherOpts
66+
}) {
67+
return axios($, {
68+
url: `${this._baseUrl()}${path}`,
69+
headers: {
70+
apikey: this.$auth.api_token,
71+
},
72+
...otherOpts,
73+
});
74+
},
75+
listContacts(opts = {}) {
76+
return this._makeRequest({
77+
path: "/contacts/list",
78+
...opts,
79+
});
80+
},
81+
listCampaigns(opts = {}) {
82+
return this._makeRequest({
83+
path: "/campaigns",
84+
...opts,
85+
});
86+
},
87+
listTaskTypes(opts = {}) {
88+
return this._makeRequest({
89+
path: "/tasks/types",
90+
...opts,
91+
});
92+
},
93+
createContact(opts = {}) {
94+
return this._makeRequest({
95+
method: "POST",
96+
path: "/contacts",
97+
...opts,
98+
});
99+
},
100+
addContactToCampaign({
101+
campaignId, contactId, ...opts
102+
}) {
103+
return this._makeRequest({
104+
method: "POST",
105+
path: `/campaigns/${campaignId}/contacts/${contactId}`,
106+
...opts,
107+
});
108+
},
109+
createTask({
110+
contactId, ...opts
111+
}) {
112+
return this._makeRequest({
113+
method: "POST",
114+
path: `/tasks/contacts/${contactId}`,
115+
...opts,
116+
});
117+
},
118+
async *paginate({
119+
fn, params, resourceKey, max,
120+
}) {
121+
params = {
122+
...params,
123+
page: 0,
124+
};
125+
let totalPages, count = 0;
126+
do {
127+
params.page++;
128+
const results = await fn({
129+
params,
130+
});
131+
const items = results[resourceKey];
132+
for (const item of items) {
133+
yield item;
134+
if (max && ++count >= max) {
135+
return;
136+
}
137+
}
138+
totalPages = results.totalPages;
139+
} while (params.page < totalPages);
9140
},
10141
},
11142
};

0 commit comments

Comments
 (0)