Skip to content

Commit e8d7ca4

Browse files
committed
source updates
1 parent bb9625a commit e8d7ca4

File tree

9 files changed

+221
-181
lines changed

9 files changed

+221
-181
lines changed

components/instantly/actions/update-lead-status/update-lead-status.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import instantly from "../../instantly.app.mjs";
44
export default {
55
key: "instantly-update-lead-status",
66
name: "Update Lead Status",
7-
description: "Updates the status of a lead in a campaign. [See the documentation](https://developer.instantly.ai/api/v2/customtag/toggletagresource)",
7+
description: "Updates the interest status of a lead in a campaign. [See the documentation](https://developer.instantly.ai/api/v2/customtag/toggletagresource)",
88
version: "0.0.2",
99
type: "action",
1010
props: {

components/instantly/common/constants.mjs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,5 @@
11
export const LIMIT = 100;
22

3-
export const EVENT_TYPE_OPTIONS = [
4-
{
5-
label: "Email Sent",
6-
value: "email_sent",
7-
},
8-
{
9-
label: "Email Bounced",
10-
value: "email_bounced",
11-
},
12-
{
13-
label: "Email Opened",
14-
value: "email_opened",
15-
},
16-
{
17-
label: "Email Link Clicked",
18-
value: "email_link_clicked",
19-
},
20-
{
21-
label: "Reply Received",
22-
value: "reply_received",
23-
},
24-
{
25-
label: "Lead Unsubscribed",
26-
value: "lead_unsubscribed",
27-
},
28-
{
29-
label: "Campaign Completed",
30-
value: "campaign_completed",
31-
},
32-
{
33-
label: "Account Error",
34-
value: "account_error",
35-
},
36-
{
37-
label: "Lead Not Interested",
38-
value: "lead_not_interested",
39-
},
40-
{
41-
label: "Lead Neutral",
42-
value: "lead_neutral",
43-
},
44-
{
45-
label: "Lead Meeting Booked",
46-
value: "lead_meeting_booked",
47-
},
48-
{
49-
label: "Lead Meeting Completed",
50-
value: "lead_meeting_completed",
51-
},
52-
{
53-
label: "Lead Closed",
54-
value: "lead_closed",
55-
},
56-
{
57-
label: "Lead Out of Office",
58-
value: "lead_out_of_office",
59-
},
60-
{
61-
label: "Lead Wrong Person",
62-
value: "lead_wrong_person",
63-
},
64-
];
65-
663
export const NEW_STATUS_OPTIONS = [
674
{
685
label: "Out of Office",

components/instantly/instantly.app.mjs

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { axios } from "@pipedream/platform";
22
import {
3-
EVENT_TYPE_OPTIONS,
43
LIMIT,
54
NEW_STATUS_OPTIONS,
65
} from "./common/constants.mjs";
@@ -87,24 +86,6 @@ export default {
8786
};
8887
},
8988
},
90-
skipIfInWorkspace: {
91-
type: "boolean",
92-
label: "Skip if in Workspace",
93-
description: "Skip lead if it exists in any campaigns in the workspace",
94-
optional: true,
95-
},
96-
skipIfInCampaign: {
97-
type: "boolean",
98-
label: "Skip if in Campaign",
99-
description: "Skip lead if it exists in the campaign",
100-
optional: true,
101-
},
102-
eventType: {
103-
type: "string",
104-
label: "Event Type",
105-
description: "Type of event to filter",
106-
options: EVENT_TYPE_OPTIONS,
107-
},
10889
newStatus: {
10990
type: "string",
11091
label: "New Status",
@@ -150,6 +131,18 @@ export default {
150131
...opts,
151132
});
152133
},
134+
listEmails(opts = {}) {
135+
return this._makeRequest({
136+
path: "/emails",
137+
...opts,
138+
});
139+
},
140+
listBackgroundJobs(opts = {}) {
141+
return this._makeRequest({
142+
path: "/background-jobs",
143+
...opts,
144+
});
145+
},
153146
getBackgroundJob({
154147
jobId, ...opts
155148
}) {
@@ -179,19 +172,32 @@ export default {
179172
...opts,
180173
});
181174
},
182-
createWebhook(opts = {}) {
183-
return this._makeRequest({
184-
method: "POST",
185-
path: "/webhook/subscribe",
186-
...opts,
187-
});
188-
},
189-
deleteWebhook(opts = {}) {
190-
return this._makeRequest({
191-
method: "POST",
192-
path: "/webhook/unsubscribe",
193-
...opts,
194-
});
175+
async *paginate({
176+
fn, args = {}, max,
177+
}) {
178+
const optsKey = args?.data
179+
? "data"
180+
: "params";
181+
182+
args[optsKey] = {
183+
...args[optsKey],
184+
limit: LIMIT,
185+
};
186+
187+
let count = 0;
188+
189+
do {
190+
const {
191+
items, next_starting_after: next,
192+
} = await fn(args);
193+
for (const item of items) {
194+
yield item;
195+
if (max && ++count >= max) {
196+
return;
197+
}
198+
}
199+
args[optsKey].starting_after = next;
200+
} while (args[optsKey].next);
195201
},
196202
},
197203
};
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import instantly from "../../instantly.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
4+
export default {
5+
props: {
6+
instantly,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
methods: {
16+
_getLastTs() {
17+
return this.db.get("lastTs") || 0;
18+
},
19+
_setLastTs(lastTs) {
20+
this.db.set("lastTs", lastTs);
21+
},
22+
getArgs() {
23+
return {};
24+
},
25+
generateMeta(item) {
26+
return {
27+
id: item.id,
28+
summary: this.getSummary(item),
29+
ts: Date.parse(item[this.getTsField()]),
30+
};
31+
},
32+
async processEvent(max) {
33+
const lastTs = this._getLastTs();
34+
let maxTs = lastTs;
35+
36+
const resourceFn = this.getResourceFn();
37+
const args = this.getArgs();
38+
const tsField = this.getTsField();
39+
const isSortedDesc = args?.sort_order === "desc";
40+
41+
const items = this.instantly.paginate({
42+
fn: resourceFn,
43+
args,
44+
max: isSortedDesc && max,
45+
});
46+
47+
let results = [];
48+
for await (const item of items) {
49+
const ts = Date.parse(item[tsField]);
50+
if (ts >= lastTs) {
51+
results.push(item);
52+
maxTs = Math.max(ts, maxTs);
53+
} else if (isSortedDesc) {
54+
break;
55+
}
56+
}
57+
58+
if (!results.length) {
59+
return;
60+
}
61+
62+
if (max && !isSortedDesc) {
63+
results = results.slice(-1 * max).reverse();
64+
}
65+
66+
results.forEach((item) => {
67+
const meta = this.generateMeta(item);
68+
this.$emit(item, meta);
69+
});
70+
71+
this._setLastTs(maxTs);
72+
},
73+
getResourceFn() {
74+
throw new Error("getResourceFn is not implemented");
75+
},
76+
getTsField() {
77+
throw new Error("getTsField is not implemented");
78+
},
79+
getSummary() {
80+
throw new Error("getSummary is not implemented");
81+
},
82+
},
83+
hooks: {
84+
async deploy() {
85+
await this.processEvent(25);
86+
},
87+
},
88+
async run() {
89+
await this.processEvent();
90+
},
91+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "instantly-new-background-job-completed",
6+
name: "New Background Job Completed",
7+
description: "Emit new event when a new background job has completed. [See the documentation](https://developer.instantly.ai/api/v2/backgroundjob/listbackgroundjob)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getResourceFn() {
14+
return this.instantly.listBackgroundJobs;
15+
},
16+
getArgs() {
17+
return {
18+
params: {
19+
status: "success,failed",
20+
sort_column: "updated_at",
21+
sort_order: "desc",
22+
},
23+
};
24+
},
25+
getTsField() {
26+
return "updated_at";
27+
},
28+
getSummary(item) {
29+
return `Background Job Completed with ID: ${item.id}`;
30+
},
31+
},
32+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "instantly-new-email-received",
6+
name: "New Email Received",
7+
description: "Emit new event when a new email is received. [See the documentation](https://developer.instantly.ai/api/v2/email/listemail)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getResourceFn() {
14+
return this.instantly.listEmails;
15+
},
16+
getArgs() {
17+
return {
18+
params: {
19+
email_type: "received",
20+
sort_order: "desc",
21+
},
22+
};
23+
},
24+
getTsField() {
25+
return "timestamp_created";
26+
},
27+
getSummary(item) {
28+
return `New Email with ID: ${item.id}`;
29+
},
30+
},
31+
};

components/instantly/sources/new-event-instant/new-event-instant.mjs

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

0 commit comments

Comments
 (0)