Skip to content

Commit 81e04d4

Browse files
committed
address comments
1 parent 2a455ff commit 81e04d4

19 files changed

Lines changed: 513 additions & 134 deletions

apps/sim/blocks/blocks/instantly.ts

Lines changed: 397 additions & 44 deletions
Large diffs are not rendered by default.

apps/sim/blocks/registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ export const registry: Record<string, BlockConfig> = {
365365
incidentio: IncidentioBlock,
366366
infisical: InfisicalBlock,
367367
input_trigger: InputTriggerBlock,
368+
instantly: InstantlyBlock,
368369
intercom: IntercomBlock,
369370
intercom_v2: IntercomV2Block,
370-
instantly: InstantlyBlock,
371371
jina: JinaBlock,
372372
jira: JiraBlock,
373373
jira_service_management: JiraServiceManagementBlock,

apps/sim/lib/webhooks/providers/instantly.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ const SIM_WEBHOOK_TOKEN_HEADER = 'x-sim-webhook-token'
2222
export const instantlyHandler: WebhookProviderHandler = {
2323
verifyAuth({ request, requestId, providerConfig }: AuthContext): NextResponse | null {
2424
const secretToken = providerConfig.secretToken as string | undefined
25-
if (!secretToken) return null
25+
if (!secretToken) {
26+
logger.warn(`[${requestId}] Instantly webhook secret token is missing`)
27+
return new NextResponse('Unauthorized', { status: 401 })
28+
}
2629

2730
if (!verifyTokenAuth(request, secretToken, SIM_WEBHOOK_TOKEN_HEADER)) {
2831
logger.warn(`[${requestId}] Unauthorized Instantly webhook request`)
@@ -85,9 +88,9 @@ export const instantlyHandler: WebhookProviderHandler = {
8588
async createSubscription(ctx: SubscriptionContext): Promise<SubscriptionResult | undefined> {
8689
const { webhook, requestId } = ctx
8790
const providerConfig = getProviderConfig(webhook)
88-
const apiKey = providerConfig.apiKey as string | undefined
91+
const apiKey = providerConfig.triggerApiKey as string | undefined
8992
const triggerId = providerConfig.triggerId as string | undefined
90-
const campaignId = providerConfig.triggerCampaignId as string | undefined
93+
const campaignId = optionalId(providerConfig.triggerCampaignId)
9194

9295
if (!apiKey?.trim()) {
9396
throw new Error('Instantly API Key is required.')
@@ -119,8 +122,8 @@ export const instantlyHandler: WebhookProviderHandler = {
119122
},
120123
}
121124

122-
if (campaignId?.trim()) {
123-
requestBody.campaign = campaignId.trim()
125+
if (campaignId) {
126+
requestBody.campaign = campaignId
124127
}
125128

126129
logger.info(`[${requestId}] Creating Instantly webhook`, {
@@ -133,7 +136,7 @@ export const instantlyHandler: WebhookProviderHandler = {
133136
const response = await fetch(instantlyUrl('/api/v2/webhooks'), {
134137
method: 'POST',
135138
headers: {
136-
Authorization: `Bearer ${apiKey}`,
139+
Authorization: `Bearer ${apiKey.trim()}`,
137140
'Content-Type': 'application/json',
138141
},
139142
body: JSON.stringify(requestBody),
@@ -179,7 +182,7 @@ export const instantlyHandler: WebhookProviderHandler = {
179182

180183
try {
181184
const providerConfig = getProviderConfig(webhook)
182-
const apiKey = providerConfig.apiKey as string | undefined
185+
const apiKey = providerConfig.triggerApiKey as string | undefined
183186
const externalId = providerConfig.externalId as string | undefined
184187

185188
if (!apiKey?.trim() || !externalId?.trim()) {
@@ -193,11 +196,11 @@ export const instantlyHandler: WebhookProviderHandler = {
193196
}
194197

195198
const response = await fetch(
196-
instantlyUrl(`/api/v2/webhooks/${encodeURIComponent(externalId)}`),
199+
instantlyUrl(`/api/v2/webhooks/${encodeURIComponent(externalId.trim())}`),
197200
{
198201
method: 'DELETE',
199202
headers: {
200-
Authorization: `Bearer ${apiKey}`,
203+
Authorization: `Bearer ${apiKey.trim()}`,
201204
},
202205
}
203206
)
@@ -254,6 +257,13 @@ function toBooleanOrNull(value: unknown): boolean | null {
254257
return typeof value === 'boolean' ? value : null
255258
}
256259

260+
function optionalId(value: unknown): string | undefined {
261+
if (typeof value !== 'string') return undefined
262+
const trimmed = value.trim()
263+
if (trimmed === '' || trimmed === '-') return undefined
264+
return trimmed
265+
}
266+
257267
function isRecord(value: unknown): value is Record<string, unknown> {
258268
return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
259269
}

apps/sim/tools/instantly/activate_campaign.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
instantlyHeaders,
99
instantlyUrl,
1010
mapCampaign,
11+
parseInstantlyResponse,
1112
} from '@/tools/instantly/utils'
1213
import type { ToolConfig } from '@/tools/types'
1314

@@ -29,12 +30,12 @@ export const activateCampaignTool: ToolConfig<
2930
},
3031
},
3132
request: {
32-
url: (params) => instantlyUrl(`/api/v2/campaigns/${params.campaignId}/activate`),
33+
url: (params) => instantlyUrl(`/api/v2/campaigns/${params.campaignId.trim()}/activate`),
3334
method: 'POST',
3435
headers: instantlyHeaders,
3536
},
3637
transformResponse: async (response) => {
37-
const data: unknown = await response.json()
38+
const data = await parseInstantlyResponse(response)
3839
const campaign = mapCampaign(data)
3940

4041
return {

apps/sim/tools/instantly/create_campaign.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
instantlyHeaders,
1010
instantlyUrl,
1111
mapCampaign,
12+
parseInstantlyResponse,
1213
} from '@/tools/instantly/utils'
1314
import type { ToolConfig } from '@/tools/types'
1415

@@ -107,33 +108,18 @@ export const createCampaignTool: ToolConfig<
107108
campaign_schedule: params.campaign_schedule,
108109
sequences: params.sequences,
109110
pl_value: params.pl_value,
110-
is_evergreen: params.is_evergreen,
111111
email_gap: params.email_gap,
112-
random_wait_max: params.random_wait_max,
113112
text_only: params.text_only,
114-
first_email_text_only: params.first_email_text_only,
115113
email_list: params.email_list,
116114
daily_limit: params.daily_limit,
117115
stop_on_reply: params.stop_on_reply,
118-
email_tag_list: params.email_tag_list,
119116
link_tracking: params.link_tracking,
120117
open_tracking: params.open_tracking,
121-
stop_on_auto_reply: params.stop_on_auto_reply,
122118
daily_max_leads: params.daily_max_leads,
123-
prioritize_new_leads: params.prioritize_new_leads,
124-
match_lead_esp: params.match_lead_esp,
125-
stop_for_company: params.stop_for_company,
126-
insert_unsubscribe_header: params.insert_unsubscribe_header,
127-
allow_risky_contacts: params.allow_risky_contacts,
128-
disable_bounce_protect: params.disable_bounce_protect,
129-
cc_list: params.cc_list,
130-
bcc_list: params.bcc_list,
131-
owned_by: params.owned_by,
132-
ai_sdr_id: params.ai_sdr_id,
133119
}),
134120
},
135121
transformResponse: async (response) => {
136-
const data: unknown = await response.json()
122+
const data = await parseInstantlyResponse(response)
137123
const campaign = mapCampaign(data)
138124

139125
return {

apps/sim/tools/instantly/create_lead.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
instantlyUrl,
77
leadOutputs,
88
mapLead,
9+
parseInstantlyResponse,
910
} from '@/tools/instantly/utils'
1011
import type { ToolConfig } from '@/tools/types'
1112

@@ -118,6 +119,12 @@ export const createLeadTool: ToolConfig<InstantlyCreateLeadParams, InstantlyLead
118119
visibility: 'user-or-llm',
119120
description: 'Blocklist ID to check for the lead',
120121
},
122+
verify_leads_for_lead_finder: {
123+
type: 'boolean',
124+
required: false,
125+
visibility: 'user-or-llm',
126+
description: 'Whether to verify leads imported from Lead Finder',
127+
},
121128
verify_leads_on_import: {
122129
type: 'boolean',
123130
required: false,
@@ -160,7 +167,7 @@ export const createLeadTool: ToolConfig<InstantlyCreateLeadParams, InstantlyLead
160167
}),
161168
},
162169
transformResponse: async (response) => {
163-
const data: unknown = await response.json()
170+
const data = await parseInstantlyResponse(response)
164171
const lead = mapLead(data)
165172

166173
return {

apps/sim/tools/instantly/create_lead_list.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
instantlyUrl,
1010
leadListOutputs,
1111
mapLeadList,
12+
parseInstantlyResponse,
1213
} from '@/tools/instantly/utils'
1314
import type { ToolConfig } from '@/tools/types'
1415

@@ -53,7 +54,7 @@ export const createLeadListTool: ToolConfig<
5354
}),
5455
},
5556
transformResponse: async (response) => {
56-
const data: unknown = await response.json()
57+
const data = await parseInstantlyResponse(response)
5758
const leadList = mapLeadList(data)
5859

5960
return {

apps/sim/tools/instantly/delete_leads.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
instantlyBaseParamFields,
99
instantlyHeaders,
1010
instantlyUrl,
11+
parseInstantlyResponse,
1112
} from '@/tools/instantly/utils'
1213
import type { ToolConfig } from '@/tools/types'
1314

@@ -65,7 +66,7 @@ export const deleteLeadsTool: ToolConfig<InstantlyDeleteLeadsParams, InstantlyDe
6566
}),
6667
},
6768
transformResponse: async (response) => {
68-
const data: unknown = await response.json()
69+
const data = await parseInstantlyResponse(response)
6970
const result = asRecord(data)
7071

7172
return {

apps/sim/tools/instantly/get_lead.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
instantlyUrl,
66
leadOutputs,
77
mapLead,
8+
parseInstantlyResponse,
89
} from '@/tools/instantly/utils'
910
import type { ToolConfig } from '@/tools/types'
1011

@@ -23,12 +24,12 @@ export const getLeadTool: ToolConfig<InstantlyGetLeadParams, InstantlyLeadRespon
2324
},
2425
},
2526
request: {
26-
url: (params) => instantlyUrl(`/api/v2/leads/${params.leadId}`),
27+
url: (params) => instantlyUrl(`/api/v2/leads/${params.leadId.trim()}`),
2728
method: 'GET',
2829
headers: instantlyHeaders,
2930
},
3031
transformResponse: async (response) => {
31-
const data: unknown = await response.json()
32+
const data = await parseInstantlyResponse(response)
3233
const lead = mapLead(data)
3334

3435
return {

apps/sim/tools/instantly/list_campaigns.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
instantlyHeaders,
1111
instantlyUrl,
1212
mapCampaign,
13+
parseInstantlyResponse,
1314
} from '@/tools/instantly/utils'
1415
import type { ToolConfig } from '@/tools/types'
1516

@@ -74,7 +75,7 @@ export const listCampaignsTool: ToolConfig<
7475
headers: instantlyHeaders,
7576
},
7677
transformResponse: async (response) => {
77-
const data: unknown = await response.json()
78+
const data = await parseInstantlyResponse(response)
7879
const campaigns = getItems(data).map(mapCampaign)
7980

8081
return {

0 commit comments

Comments
 (0)