Skip to content

Commit 0b96440

Browse files
authored
New Components - whatconverts (#16872)
* new components * pnpm-lock.yaml
1 parent 0e7dd4a commit 0b96440

File tree

11 files changed

+614
-20
lines changed

11 files changed

+614
-20
lines changed

components/whatconverts/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
import whatconverts from "../../whatconverts.app.mjs";
2+
3+
export default {
4+
key: "whatconverts-find-lead",
5+
name: "Find Lead",
6+
description: "Find a lead in WhatConverts. [See the documentation](https://www.whatconverts.com/api/leads/#get-all-leads)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
whatconverts,
11+
accountId: {
12+
propDefinition: [
13+
whatconverts,
14+
"accountId",
15+
],
16+
},
17+
profileId: {
18+
propDefinition: [
19+
whatconverts,
20+
"profileId",
21+
(c) => ({
22+
accountId: c.accountId,
23+
}),
24+
],
25+
},
26+
leadType: {
27+
propDefinition: [
28+
whatconverts,
29+
"leadType",
30+
],
31+
},
32+
leadStatus: {
33+
type: "string",
34+
label: "Lead Status",
35+
description: "Lead status to return for this request",
36+
options: [
37+
"repeat",
38+
"unique",
39+
],
40+
optional: true,
41+
},
42+
startDate: {
43+
type: "string",
44+
label: "Start Date",
45+
description: "Start date for this request in date or date/time ISO 8601 format (UTC); `2015-11-10` or `2015-11-10T00:00:00Z`. Date range can include up to 400 days.",
46+
optional: true,
47+
},
48+
endDate: {
49+
type: "string",
50+
label: "End Date",
51+
description: "End date for this request in date or date/time ISO 8601 format (UTC); `2015-11-10` or `2015-11-10T00:00:00Z`. Date range can include up to 400 days.",
52+
optional: true,
53+
},
54+
order: {
55+
type: "string",
56+
label: "Order",
57+
description: "Order in which to return the leads by date created",
58+
options: [
59+
"asc",
60+
"desc",
61+
],
62+
optional: true,
63+
},
64+
quotable: {
65+
type: "string",
66+
label: "Quotable",
67+
description: "Quotable type to return for this request",
68+
options: [
69+
"yes",
70+
"no",
71+
"pending",
72+
"not_set",
73+
],
74+
optional: true,
75+
},
76+
quoteValue: {
77+
type: "string",
78+
label: "Quote Value",
79+
description: "Return leads that have a quote value",
80+
options: [
81+
"has_value",
82+
"no_value",
83+
],
84+
optional: true,
85+
},
86+
salesValue: {
87+
type: "string",
88+
label: "Sales Value",
89+
description: "Return leads that have a sales value",
90+
options: [
91+
"has_value",
92+
"no_value",
93+
],
94+
optional: true,
95+
},
96+
phoneNumber: {
97+
type: "string",
98+
label: "Phone Number",
99+
description: "Return leads for the contacts that have this E.164 formatted phone number",
100+
optional: true,
101+
},
102+
emailAddress: {
103+
type: "string",
104+
label: "Email Address",
105+
description: "Return leads for the contact that have this email address",
106+
optional: true,
107+
},
108+
spam: {
109+
type: "boolean",
110+
label: "Spam",
111+
description: "If `true` will return only spam leads",
112+
optional: true,
113+
},
114+
duplicate: {
115+
type: "boolean",
116+
label: "Duplicate",
117+
description: "If true will return only duplicate leads",
118+
optional: true,
119+
},
120+
leadSource: {
121+
type: "string",
122+
label: "Lead Source",
123+
description: "Return leads that have this lead source",
124+
optional: true,
125+
},
126+
leadMedium: {
127+
type: "string",
128+
label: "Lead Medium",
129+
description: "Return leads that have this lead medium",
130+
optional: true,
131+
},
132+
leadCampaign: {
133+
type: "string",
134+
label: "Lead Campaign",
135+
description: "Return leads that have this lead campaign",
136+
optional: true,
137+
},
138+
leadContent: {
139+
type: "string",
140+
label: "Lead Content",
141+
description: "Return leads that have this lead content",
142+
optional: true,
143+
},
144+
leadKeyword: {
145+
type: "string",
146+
label: "Lead Keyword",
147+
description: "Return leads that have this lead keyword",
148+
optional: true,
149+
},
150+
maxResults: {
151+
type: "integer",
152+
label: "Max Results",
153+
description: "The maximum number of results to return. Default: 100, Maximum: 2500",
154+
optional: true,
155+
default: 100,
156+
},
157+
},
158+
async run({ $ }) {
159+
const { leads } = await this.whatconverts.listLeads({
160+
$,
161+
params: {
162+
profile_id: this.profileId,
163+
lead_type: this.leadType,
164+
lead_status: this.leadStatus,
165+
start_date: this.startDate,
166+
end_date: this.endDate,
167+
order: this.order,
168+
quotable: this.quotable,
169+
quote_value: this.quoteValue,
170+
sales_value: this.salesValue,
171+
phone_number: this.phoneNumber,
172+
email_address: this.emailAddress,
173+
spam: this.spam,
174+
duplicate: this.duplicate,
175+
lead_source: this.leadSource,
176+
lead_medium: this.leadMedium,
177+
lead_campaign: this.leadCampaign,
178+
lead_content: this.leadContent,
179+
lead_keyword: this.leadKeyword,
180+
leads_per_page: this.maxResults,
181+
},
182+
});
183+
184+
$.export("$summary", `Found ${leads.length} lead${leads.length === 1
185+
? ""
186+
: "s"}`);
187+
return leads;
188+
},
189+
};

components/whatconverts/app/whatconverts.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

components/whatconverts/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "@pipedream/whatconverts",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream WhatConverts Components",
5-
"main": "dist/app/whatconverts.app.mjs",
5+
"main": "whatconverts.app.mjs",
66
"keywords": [
77
"pipedream",
88
"whatconverts"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/whatconverts",
1211
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1517
}
1618
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import whatconverts from "../../whatconverts.app.mjs";
2+
import {
3+
ConfigurationError, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
4+
} from "@pipedream/platform";
5+
6+
export default {
7+
props: {
8+
whatconverts,
9+
db: "$.service.db",
10+
timer: {
11+
type: "$.interface.timer",
12+
default: {
13+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
14+
},
15+
},
16+
accountId: {
17+
propDefinition: [
18+
whatconverts,
19+
"accountId",
20+
],
21+
},
22+
profileId: {
23+
propDefinition: [
24+
whatconverts,
25+
"profileId",
26+
(c) => ({
27+
accountId: c.accountId,
28+
}),
29+
],
30+
},
31+
leadType: {
32+
propDefinition: [
33+
whatconverts,
34+
"leadType",
35+
],
36+
},
37+
},
38+
methods: {
39+
_getLastTs() {
40+
return this.db.get("lastTs") || 0;
41+
},
42+
_setLastTs(lastTs) {
43+
this.db.set("lastTs", lastTs);
44+
},
45+
getParams() {
46+
return {
47+
account_id: this.accountId,
48+
profile_id: this.profileId,
49+
lead_type: this.leadType,
50+
order: "desc",
51+
};
52+
},
53+
getResourceKey() {
54+
return "leads";
55+
},
56+
isSorted() {
57+
return true;
58+
},
59+
async processEvent(max) {
60+
const lastTs = this._getLastTs();
61+
let maxTs = lastTs;
62+
const fn = this.getResourceFn();
63+
const params = this.getParams();
64+
const resourceKey = this.getResourceKey();
65+
const tsField = this.getTsField();
66+
const isSorted = this.isSorted();
67+
68+
const results = this.whatconverts.paginate({
69+
fn,
70+
params,
71+
resourceKey,
72+
max,
73+
});
74+
75+
for await (const item of results) {
76+
const ts = Date.parse(item[tsField]);
77+
if (ts > lastTs) {
78+
const meta = this.generateMeta(item);
79+
this.$emit(item, meta);
80+
maxTs = Math.max(maxTs, ts);
81+
} else if (isSorted) {
82+
break;
83+
}
84+
}
85+
86+
this._setLastTs(maxTs);
87+
},
88+
getResourceFn() {
89+
throw new ConfigurationError("getResourceFn is not implemented");
90+
},
91+
getTsField() {
92+
throw new ConfigurationError("getTsField is not implemented");
93+
},
94+
generateMeta() {
95+
throw new ConfigurationError("generateMeta is not implemented");
96+
},
97+
},
98+
hooks: {
99+
async deploy() {
100+
await this.processEvent(25);
101+
},
102+
},
103+
async run() {
104+
await this.processEvent();
105+
},
106+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "whatconverts-new-lead-added",
7+
name: "New Lead Added",
8+
description: "Emit new event when a new lead is added",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getResourceFn() {
15+
return this.whatconverts.listLeads;
16+
},
17+
getTsField() {
18+
return "date_created";
19+
},
20+
generateMeta(item) {
21+
return {
22+
id: item.lead_id,
23+
summary: `New Lead ID: ${item.lead_id}`,
24+
ts: Date.parse(item.date_created),
25+
};
26+
},
27+
},
28+
sampleEmit,
29+
};

0 commit comments

Comments
 (0)