Skip to content

Commit bb9625a

Browse files
committed
actions updates
1 parent a7c1195 commit bb9625a

File tree

6 files changed

+163
-77
lines changed

6 files changed

+163
-77
lines changed

components/instantly/actions/add-lead-campaign/add-lead-campaign.mjs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import instantly from "../../instantly.app.mjs";
33

44
export default {
55
key: "instantly-add-lead-campaign",
6-
name: "Add Lead to Campaign",
7-
description: "Adds a lead to a campaign for tracking or further actions. [See the documentation](https://developer.instantly.ai/lead/add-leads-to-a-campaign)",
8-
version: "0.0.1",
6+
name: "Add Leads to Campaign",
7+
description: "Adds a lead or leads to a campaign for tracking or further actions. [See the documentation](https://developer.instantly.ai/api/v2/lead/moveleads)",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
instantly,
12-
leads: {
12+
leadIds: {
1313
propDefinition: [
1414
instantly,
15-
"leads",
15+
"leadIds",
1616
],
1717
},
1818
campaignId: {
@@ -21,30 +21,42 @@ export default {
2121
"campaignId",
2222
],
2323
},
24-
skipIfInWorkspace: {
25-
type: "boolean",
26-
label: "Skip if in Workspace",
27-
description: "Skip lead if it exists in any campaigns in the workspace",
28-
optional: true,
29-
},
3024
skipIfInCampaign: {
3125
type: "boolean",
3226
label: "Skip if in Campaign",
3327
description: "Skip lead if it exists in the campaign",
3428
optional: true,
3529
},
30+
waitForCompletion: {
31+
type: "boolean",
32+
label: "Wait for Completion",
33+
description: "Set to `true` to poll the API in 3-second intervals until the background job is completed",
34+
optional: true,
35+
},
3636
},
3737
async run({ $ }) {
38-
const response = await this.instantly.addLeadsToCampaign({
38+
let response = await this.instantly.addLeadsToCampaign({
3939
$,
4040
data: {
41-
leads: parseObject(this.leads),
42-
campaign_id: this.campaignId,
43-
skip_if_in_workspace: this.skipIfInWorkspace,
44-
skip_if_in_campaign: this.skipIfInCampaign,
41+
ids: parseObject(this.leadIds),
42+
to_campaign_id: this.campaignId,
43+
check_duplicates_in_campaigns: this.skipIfInCampaign,
4544
},
4645
});
47-
$.export("$summary", `Added ${response.leads_uploaded} leads to campaign ${this.campaignId}`);
46+
47+
if (this.waitForCompletion) {
48+
const jobId = response.id;
49+
const timer = (ms) => new Promise((res) => setTimeout(res, ms));
50+
while (response.status === "pending" || response.status === "in-progress") {
51+
response = await this.instantly.getBackgroundJob({
52+
$,
53+
jobId,
54+
});
55+
await timer(3000);
56+
}
57+
}
58+
59+
$.export("$summary", `Added ${this.leadIds.length} lead(s) to campaign ${this.campaignId}`);
4860
return response;
4961
},
5062
};

components/instantly/actions/add-tags-campaign/add-tags-campaign.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import instantly from "../../instantly.app.mjs";
44
export default {
55
key: "instantly-add-tags-campaign",
66
name: "Add Tags to Campaign",
7-
description: "Adds tags to a specific campaign. [See the documentation](https://developer.instantly.ai/tags/assign-or-unassign-a-tag)",
8-
version: "0.0.1",
7+
description: "Adds tags to a specific campaign. [See the documentation](https://developer.instantly.ai/api/v2/customtag/toggletagresource)",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
instantly,
@@ -15,6 +15,7 @@ export default {
1515
"campaignId",
1616
],
1717
type: "string[]",
18+
description: "The campaign IDs to assign tags to",
1819
},
1920
tagIds: {
2021
propDefinition: [
@@ -34,7 +35,7 @@ export default {
3435
resource_ids: parseObject(this.campaignIds),
3536
},
3637
});
37-
$.export("$summary", response.message);
38+
$.export("$summary", "Successfully added tags to campaign(s)");
3839
return response;
3940
},
4041
};

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ 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/lead/update-lead-status)",
8-
version: "0.0.1",
7+
description: "Updates the status of a lead in a campaign. [See the documentation](https://developer.instantly.ai/api/v2/customtag/toggletagresource)",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
instantly,
@@ -18,8 +18,14 @@ export default {
1818
email: {
1919
propDefinition: [
2020
instantly,
21-
"email",
21+
"leadIds",
22+
() => ({
23+
valueKey: "email",
24+
}),
2225
],
26+
type: "string",
27+
label: "Lead Email",
28+
description: "Email address of the lead to update",
2329
},
2430
newStatus: {
2531
propDefinition: [
@@ -33,12 +39,12 @@ export default {
3339
const response = await this.instantly.updateLeadStatus({
3440
$,
3541
data: {
36-
email: this.email,
37-
new_status: this.newStatus,
42+
lead_email: this.email,
43+
interest_value: this.newStatus,
3844
campaign_id: this.campaignId,
3945
},
4046
});
41-
$.export("$summary", `Updated lead ${this.email} to status '${this.newStatus}'`);
47+
$.export("$summary", `Updated status of lead: ${this.email}`);
4248
return response;
4349
} catch ({ response }) {
4450
throw new ConfigurationError(response.data.error);

components/instantly/common/constants.mjs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,36 @@ export const EVENT_TYPE_OPTIONS = [
6464
];
6565

6666
export const NEW_STATUS_OPTIONS = [
67-
"Active",
68-
"Completed",
69-
"Unsubscribed",
70-
"Interested",
71-
"Meeting Booked",
72-
"Meeting Completed",
73-
"Closed",
74-
"Out of Office",
75-
"Not Interested",
76-
"Wrong Person",
67+
{
68+
label: "Out of Office",
69+
value: "0",
70+
},
71+
{
72+
label: "Interested",
73+
value: "1",
74+
},
75+
{
76+
label: "Meeting Booked",
77+
value: "2",
78+
},
79+
{
80+
label: "Meeting Completed",
81+
value: "3",
82+
},
83+
{
84+
label: "Closed",
85+
value: "4",
86+
},
87+
{
88+
label: "Not Interested",
89+
value: "-1",
90+
},
91+
{
92+
label: "Wrong Person",
93+
value: "-2",
94+
},
95+
{
96+
label: "Lost",
97+
value: "-3",
98+
},
7799
];

components/instantly/instantly.app.mjs

Lines changed: 85 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,79 @@ export default {
1313
type: "string",
1414
label: "Campaign ID",
1515
description: "The ID of the campaign",
16-
async options({ page }) {
17-
const campaigns = await this.listCampaigns({
16+
async options({ prevContext }) {
17+
const {
18+
items, next_starting_after: next,
19+
} = await this.listCampaigns({
1820
params: {
1921
limit: LIMIT,
20-
skip: LIMIT * page,
22+
starting_after: prevContext?.next,
2123
},
2224
});
23-
return campaigns.map(({
24-
id: value, name: label,
25-
}) => ({
26-
label,
27-
value,
28-
}));
25+
return {
26+
options: items?.map(({
27+
id: value, name: label,
28+
}) => ({
29+
label,
30+
value,
31+
})) || [],
32+
context: {
33+
next,
34+
},
35+
};
2936
},
3037
},
3138
tagIds: {
3239
type: "string[]",
33-
label: "Tags Id",
34-
description: "List of tag Ids to add",
35-
async options({ page }) {
36-
const { data } = await this.listTags({
40+
label: "Tags ID",
41+
description: "List of tag IDs to add",
42+
async options({ prevContext }) {
43+
const {
44+
items, next_starting_after: next,
45+
} = await this.listTags({
3746
params: {
3847
limit: LIMIT,
39-
skip: LIMIT * page,
48+
starting_after: prevContext?.next,
4049
},
4150
});
42-
return data.map(({
43-
id: value, label,
44-
}) => ({
45-
label,
46-
value,
47-
}));
51+
return {
52+
options: items?.map(({
53+
id: value, label,
54+
}) => ({
55+
label,
56+
value,
57+
})) || [],
58+
context: {
59+
next,
60+
},
61+
};
4862
},
4963
},
50-
leads: {
64+
leadIds: {
5165
type: "string[]",
52-
label: "Leads",
53-
description: "An array of lead objects to add to the campaign. **Example: [{ \"email\":\"[email protected]\", \"first_name\":\"John\", \"last_name\":\"Doe\", \"company_name\":\"Instantly\", \"personalization\":\"Loved your latest post\", \"phone\":\"123456789\", \"website\":\"instantly.ai\", \"custom_variables\":{ \"favorite_restaurant\":\"Chipotle\", \"language\":\"English\"}}]**",
66+
label: "Lead IDs",
67+
description: "The array of lead IDs to include",
68+
async options({
69+
prevContext, valueKey = "id",
70+
}) {
71+
const {
72+
items, next_starting_after: next,
73+
} = await this.listLeads({
74+
params: {
75+
limit: LIMIT,
76+
starting_after: prevContext?.next,
77+
},
78+
});
79+
return {
80+
options: items?.map((lead) => ({
81+
label: (`${lead?.first_name} ${lead?.last_name}`).trim(),
82+
value: lead[valueKey],
83+
})) || [],
84+
context: {
85+
next,
86+
},
87+
};
88+
},
5489
},
5590
skipIfInWorkspace: {
5691
type: "boolean",
@@ -70,67 +105,77 @@ export default {
70105
description: "Type of event to filter",
71106
options: EVENT_TYPE_OPTIONS,
72107
},
73-
email: {
74-
type: "string",
75-
label: "Lead Email",
76-
description: "Email address of the lead",
77-
},
78108
newStatus: {
79109
type: "string",
80110
label: "New Status",
81-
description: "New status to assign to the lead",
111+
description: "Lead interest status. It can be either a static value, or a custom status interest value.",
82112
options: NEW_STATUS_OPTIONS,
83113
},
84114
},
85115
methods: {
86116
_baseUrl() {
87-
return "https://api.instantly.ai/api/v1";
117+
return "https://api.instantly.ai/api/v2";
88118
},
89-
_params(params = {}) {
119+
_headers(headers = {}) {
90120
return {
91-
...params,
92-
api_key: `${this.$auth.api_key}`,
121+
...headers,
122+
Authorization: `Bearer ${this.$auth.api_key}`,
93123
};
94124
},
95125
_makeRequest({
96-
$ = this, params, path, ...opts
126+
$ = this, headers, path, ...opts
97127
}) {
98128
return axios($, {
99129
url: this._baseUrl() + path,
100-
params: this._params(params),
130+
headers: this._headers(headers),
101131
...opts,
102132
});
103133
},
104134
listCampaigns(opts = {}) {
105135
return this._makeRequest({
106-
path: "/campaign/list",
136+
path: "/campaigns",
107137
...opts,
108138
});
109139
},
110140
listTags(opts = {}) {
111141
return this._makeRequest({
112-
path: "/custom-tag",
142+
path: "/custom-tags",
143+
...opts,
144+
});
145+
},
146+
listLeads(opts = {}) {
147+
return this._makeRequest({
148+
method: "POST",
149+
path: "/leads/list",
150+
...opts,
151+
});
152+
},
153+
getBackgroundJob({
154+
jobId, ...opts
155+
}) {
156+
return this._makeRequest({
157+
path: `/background-jobs/${jobId}`,
113158
...opts,
114159
});
115160
},
116161
addTagsToCampaign(opts = {}) {
117162
return this._makeRequest({
118163
method: "POST",
119-
path: "/custom-tag/toggle-tag-resource",
164+
path: "/custom-tags/toggle-resource",
120165
...opts,
121166
});
122167
},
123168
addLeadsToCampaign(opts = {}) {
124169
return this._makeRequest({
125170
method: "POST",
126-
path: "/lead/add",
171+
path: "/leads/move",
127172
...opts,
128173
});
129174
},
130175
updateLeadStatus(opts = {}) {
131176
return this._makeRequest({
132177
method: "POST",
133-
path: "/lead/update/status",
178+
path: "/leads/update-interest-status",
134179
...opts,
135180
});
136181
},

0 commit comments

Comments
 (0)