Skip to content

Commit 0742575

Browse files
committed
Salesloft app (AI-generated with improvements)
1 parent 87649cc commit 0742575

File tree

10 files changed

+409
-16
lines changed

10 files changed

+409
-16
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import salesloft from "../../salesloft.app.mjs";
2+
3+
export default {
4+
key: "salesloft-add-person-to-cadence",
5+
name: "Add Person to Cadence",
6+
description: "Adds a person to a cadence in Salesloft. [See the documentation](https://developers.salesloft.com/docs/api/cadence-memberships-create/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
salesloft,
11+
personId: {
12+
propDefinition: [
13+
salesloft,
14+
"personId",
15+
],
16+
},
17+
cadenceId: {
18+
propDefinition: [
19+
salesloft,
20+
"cadenceId",
21+
],
22+
},
23+
userId: {
24+
propDefinition: [
25+
salesloft,
26+
"userId",
27+
],
28+
},
29+
},
30+
async run({ $ }) {
31+
const response = await this.salesloft.addPersonToCadence({
32+
$,
33+
data: {
34+
person_id: this.personId,
35+
cadence_id: this.cadenceId,
36+
user_id: this.userId,
37+
},
38+
});
39+
40+
$.export("$summary", `Successfully added person ${this.personId} to cadence ${this.cadenceId}`);
41+
42+
return response;
43+
},
44+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import salesloft from "../../salesloft.app.mjs";
2+
3+
export default {
4+
key: "salesloft-create-note",
5+
name: "Create Note",
6+
description: "Creates a new note in Salesloft. [See the documentation](https://developers.salesloft.com/docs/api/notes-create/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
salesloft,
11+
content: {
12+
type: "string",
13+
label: "Content",
14+
description: "The content of the note",
15+
},
16+
associatedWithId: {
17+
type: "string",
18+
label: "Associated With ID",
19+
description: "The ID of the record this note is associated with (e.g., a person ID)",
20+
},
21+
associatedWithType: {
22+
type: "string",
23+
label: "Associated With Type",
24+
description: "The type of record this note is associated with",
25+
options: [
26+
"Person",
27+
"Account",
28+
],
29+
},
30+
skipActivities: {
31+
type: "boolean",
32+
label: "Skip Activities",
33+
description: "If true, no activities will be created for this note",
34+
optional: true,
35+
default: false,
36+
},
37+
},
38+
async run({ $ }) {
39+
const response = await this.salesloft.createNote({
40+
$,
41+
data: {
42+
content: this.content,
43+
associated_with_id: this.associatedWithId,
44+
associated_with_type: this.associatedWithType,
45+
skip_activities: this.skipActivities,
46+
},
47+
});
48+
49+
$.export("$summary", `Successfully created note for ${this.associatedWithType.toLowerCase()} ${this.associatedWithId}`);
50+
51+
return response;
52+
},
53+
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import salesloft from "../../salesloft.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "salesloft-create-person",
6+
name: "Create Person",
7+
description: "Creates a new person in Salesloft. [See the documentation](https://developers.salesloft.com/docs/api/people-create/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
salesloft,
12+
email: {
13+
type: "string",
14+
label: "Email",
15+
description: "The email address of the person",
16+
optional: true,
17+
},
18+
firstName: {
19+
type: "string",
20+
label: "First Name",
21+
description: "The first name of the person",
22+
optional: true,
23+
},
24+
lastName: {
25+
type: "string",
26+
label: "Last Name",
27+
description: "The last name of the person",
28+
optional: true,
29+
},
30+
phone: {
31+
type: "string",
32+
label: "Phone",
33+
description: "The phone number of the person",
34+
optional: true,
35+
},
36+
title: {
37+
type: "string",
38+
label: "Title",
39+
description: "The job title of the person",
40+
optional: true,
41+
},
42+
company: {
43+
type: "string",
44+
label: "Company",
45+
description: "The company name of the person",
46+
optional: true,
47+
},
48+
},
49+
async run({ $ }) {
50+
// Either email_address or phone/last_name must be provided as a unique lookup
51+
if (!this.email && !(this.phone && this.lastName)) {
52+
throw new ConfigurationError("Either `Email Address` or both `Phone` and `Last Name` must be provided");
53+
}
54+
55+
const response = await this.salesloft.createPerson({
56+
$,
57+
data: {
58+
email_address: this.email,
59+
first_name: this.firstName,
60+
last_name: this.lastName,
61+
phone: this.phone,
62+
title: this.title,
63+
company_name: this.company,
64+
},
65+
});
66+
67+
$.export("$summary", `Successfully created person "${response.first_name || response.email_address || response.id}"`);
68+
69+
return response;
70+
},
71+
};

components/salesloft/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
],
1010
"homepage": "https://pipedream.com/apps/salesloft",
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"dependencies": {
13+
"@pipedream/platform": "^1.5.1"
14+
},
1215
"publishConfig": {
1316
"access": "public"
1417
}
Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,130 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "salesloft",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
personId: {
8+
type: "string",
9+
label: "Person ID",
10+
description: "Select a person to add to the cadence or provide a person ID",
11+
async options({ page }) {
12+
const { data } = await this.listPeople({
13+
params: {
14+
per_page: 100,
15+
page: page + 1,
16+
},
17+
});
18+
return data?.map((person) => ({
19+
label: person.full_email_address ?? person.email_address ?? person.display_name,
20+
value: person.id,
21+
}));
22+
},
23+
},
24+
cadenceId: {
25+
type: "string",
26+
label: "Cadence ID",
27+
description: "Select a cadence or provide a cadence ID",
28+
async options({ page }) {
29+
const { data } = await this.listCadences({
30+
params: {
31+
per_page: 100,
32+
page: page + 1,
33+
},
34+
});
35+
return data?.map((cadence) => ({
36+
label: cadence.name,
37+
value: cadence.id,
38+
}));
39+
},
40+
},
41+
userId: {
42+
type: "string",
43+
label: "User ID",
44+
description: "Select a user who will own this cadence membership or provide a user ID. Defaults to the authenticated user if not provided.",
45+
optional: true,
46+
async options({ page }) {
47+
const { data } = await this.listUsers({
48+
params: {
49+
per_page: 100,
50+
page: page + 1,
51+
},
52+
});
53+
return data?.map((user) => ({
54+
label: user.name ?? user.email,
55+
value: user.id,
56+
}));
57+
},
58+
},
59+
},
560
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
61+
_apiUrl() {
62+
return "https://api.salesloft.com/v2";
63+
},
64+
_makeRequest({
65+
$ = this,
66+
path,
67+
...args
68+
}) {
69+
return axios($, {
70+
url: `${this._apiUrl()}${path}`,
71+
headers: {
72+
Authorization: `Bearer ${this.$auth.api_key}`,
73+
},
74+
...args,
75+
});
76+
},
77+
async createPerson(args = {}) {
78+
return this._makeRequest({
79+
path: "/people",
80+
method: "POST",
81+
...args,
82+
});
83+
},
84+
async addPersonToCadence(args = {}) {
85+
return this._makeRequest({
86+
path: "/cadence_memberships",
87+
method: "POST",
88+
...args,
89+
});
90+
},
91+
async createNote(args = {}) {
92+
return this._makeRequest({
93+
path: "/notes",
94+
method: "POST",
95+
...args,
96+
});
97+
},
98+
async createWebhookSubscription(args = {}) {
99+
return this._makeRequest({
100+
path: "/webhook_subscriptions",
101+
method: "POST",
102+
...args,
103+
});
104+
},
105+
async deleteWebhookSubscription(subscriptionId) {
106+
return this._makeRequest({
107+
path: `/webhook_subscriptions/${subscriptionId}`,
108+
method: "DELETE",
109+
});
110+
},
111+
async listPeople(args = {}) {
112+
return this._makeRequest({
113+
path: "/people",
114+
...args,
115+
});
116+
},
117+
async listCadences(args = {}) {
118+
return this._makeRequest({
119+
path: "/cadences",
120+
...args,
121+
});
122+
},
123+
async listUsers(args = {}) {
124+
return this._makeRequest({
125+
path: "/users",
126+
...args,
127+
});
9128
},
10129
},
11130
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import common from "../common/webhook.mjs";
2+
3+
export default {
4+
...common,
5+
key: "salesloft-cadence-updated-instant",
6+
name: "Cadence Updated (Instant)",
7+
description: "Emit new event when a cadence is updated in Salesloft. [See the documentation](https://developers.salesloft.com/docs/api/webhook-subscriptions/)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventType() {
14+
return "cadence_updated";
15+
},
16+
getSummary(data) {
17+
return `Cadence updated: ${data.name || data.id}`;
18+
},
19+
},
20+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { v4 as uuid } from "uuid";
2+
3+
export default {
4+
props: {
5+
salesloft: {
6+
type: "app",
7+
app: "salesloft",
8+
},
9+
db: "$.service.db",
10+
},
11+
methods: {
12+
_getWebhookId() {
13+
return this.db.get("webhookId");
14+
},
15+
_setWebhookId(webhookId) {
16+
this.db.set("webhookId", webhookId);
17+
},
18+
generateMeta(data) {
19+
const { id } = data;
20+
return {
21+
id: id || uuid(),
22+
summary: this.getSummary(data),
23+
ts: Date.now(),
24+
};
25+
},
26+
},
27+
hooks: {
28+
async activate() {
29+
const response = await this.salesloft.createWebhookSubscription({
30+
data: {
31+
callback_url: this.http.endpoint,
32+
event_type: this.getEventType(),
33+
},
34+
});
35+
this._setWebhookId(response.id);
36+
},
37+
async deactivate() {
38+
const webhookId = this._getWebhookId();
39+
if (webhookId) {
40+
await this.salesloft.deleteWebhookSubscription(webhookId);
41+
}
42+
},
43+
},
44+
async run(event) {
45+
const { body } = event;
46+
const meta = this.generateMeta(body);
47+
this.$emit(body, meta);
48+
},
49+
};

0 commit comments

Comments
 (0)