Skip to content

Commit e9f409d

Browse files
committed
fix(sendgrid): fix active field coercion, add pagination, tighten output typing
- Fix active field for create_template_version being sent as the string "true"/"false" instead of the SendGrid-required int 0/1 - Add missing authMode: ApiKey on SendGridBlock - Add pageToken/nextPageToken pagination support to list_templates and list_all_lists (SendGrid page_token cursor, parsed from _metadata.next) - Fix nullable output fields to use ?? null / ?? [] with optional: true across get_contact, search_contacts, remove_contacts_from_list, create_template_version, add_contact, send_mail - Remove dead data.templates fallback in list_templates (API only ever returns result) - Remove unused UpdateContactParams/UpdateListParams/UpdateTemplateParams dead types; make CreateTemplateParams.generation optional to match actual tool behavior
1 parent 220da44 commit e9f409d

10 files changed

Lines changed: 132 additions & 55 deletions

File tree

apps/sim/blocks/blocks/sendgrid.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SendgridIcon } from '@/components/icons'
22
import type { BlockConfig, BlockMeta } from '@/blocks/types'
3-
import { IntegrationType } from '@/blocks/types'
3+
import { AuthMode, IntegrationType } from '@/blocks/types'
44
import { normalizeFileInput } from '@/blocks/utils'
55
import type { SendMailResult } from '@/tools/sendgrid/types'
66

@@ -13,6 +13,7 @@ export const SendGridBlock: BlockConfig<SendMailResult> = {
1313
docsLink: 'https://docs.sim.ai/integrations/sendgrid',
1414
category: 'tools',
1515
integrationType: IntegrationType.Email,
16+
authMode: AuthMode.ApiKey,
1617
bgColor: '#1A82E2',
1718
icon: SendgridIcon,
1819

@@ -387,6 +388,14 @@ Return ONLY the JSON array.`,
387388
condition: { field: 'operation', value: 'list_all_lists' },
388389
mode: 'advanced',
389390
},
391+
{
392+
id: 'listPageToken',
393+
title: 'Page Token',
394+
type: 'short-input',
395+
placeholder: 'Page token from a previous response',
396+
condition: { field: 'operation', value: 'list_all_lists' },
397+
mode: 'advanced',
398+
},
390399
// Template fields
391400
{
392401
id: 'templateName',
@@ -434,6 +443,14 @@ Return ONLY the JSON array.`,
434443
condition: { field: 'operation', value: 'list_templates' },
435444
mode: 'advanced',
436445
},
446+
{
447+
id: 'templatePageToken',
448+
title: 'Page Token',
449+
type: 'short-input',
450+
placeholder: 'Page token from a previous response',
451+
condition: { field: 'operation', value: 'list_templates' },
452+
mode: 'advanced',
453+
},
437454
{
438455
id: 'versionName',
439456
title: 'Version Name',
@@ -579,7 +596,10 @@ Return ONLY the HTML content.`,
579596
templateGenerations,
580597
listPageSize,
581598
templatePageSize,
599+
listPageToken,
600+
templatePageToken,
582601
attachments,
602+
active,
583603
...rest
584604
} = params
585605

@@ -599,7 +619,10 @@ Return ONLY the HTML content.`,
599619
...(templateGenerations && { generations: templateGenerations }),
600620
...(listPageSize && { pageSize: listPageSize }),
601621
...(templatePageSize && { pageSize: templatePageSize }),
622+
...(listPageToken && { pageToken: listPageToken }),
623+
...(templatePageToken && { pageToken: templatePageToken }),
602624
...(normalizedAttachments && { attachments: normalizedAttachments }),
625+
...(active !== undefined && { active: active === 'true' ? 1 : 0 }),
603626
}
604627
},
605628
},
@@ -637,12 +660,14 @@ Return ONLY the HTML content.`,
637660
listName: { type: 'string', description: 'List name' },
638661
listId: { type: 'string', description: 'List ID' },
639662
listPageSize: { type: 'number', description: 'Page size for listing lists' },
663+
listPageToken: { type: 'string', description: 'Page token for listing lists' },
640664
// Template inputs
641665
templateName: { type: 'string', description: 'Template name' },
642666
templateId: { type: 'string', description: 'Template ID' },
643667
generation: { type: 'string', description: 'Template generation' },
644668
templateGenerations: { type: 'string', description: 'Filter templates by generation' },
645669
templatePageSize: { type: 'number', description: 'Page size for listing templates' },
670+
templatePageToken: { type: 'string', description: 'Page token for listing templates' },
646671
versionName: { type: 'string', description: 'Template version name' },
647672
templateSubject: { type: 'string', description: 'Template subject' },
648673
htmlContent: { type: 'string', description: 'HTML content' },
@@ -677,6 +702,10 @@ Return ONLY the HTML content.`,
677702
templates: { type: 'json', description: 'Array of templates' },
678703
generation: { type: 'string', description: 'Template generation' },
679704
versions: { type: 'json', description: 'Array of template versions' },
705+
nextPageToken: {
706+
type: 'string',
707+
description: 'Token for the next page of results (list_all_lists, list_templates)',
708+
},
680709
// Template version outputs
681710
templateId: { type: 'string', description: 'Template ID' },
682711
active: { type: 'boolean', description: 'Whether template version is active' },

apps/sim/tools/sendgrid/add_contact.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const sendGridAddContactTool: ToolConfig<AddContactParams, ContactResult>
9999
return {
100100
success: true,
101101
output: {
102-
jobId: data.job_id,
102+
jobId: data.job_id ?? null,
103103
email: params?.email || '',
104104
firstName: params?.firstName,
105105
lastName: params?.lastName,
@@ -110,10 +110,14 @@ export const sendGridAddContactTool: ToolConfig<AddContactParams, ContactResult>
110110
},
111111

112112
outputs: {
113-
jobId: { type: 'string', description: 'Job ID for tracking the async contact creation' },
113+
jobId: {
114+
type: 'string',
115+
description: 'Job ID for tracking the async contact creation',
116+
optional: true,
117+
},
114118
email: { type: 'string', description: 'Contact email address' },
115-
firstName: { type: 'string', description: 'Contact first name' },
116-
lastName: { type: 'string', description: 'Contact last name' },
119+
firstName: { type: 'string', description: 'Contact first name', optional: true },
120+
lastName: { type: 'string', description: 'Contact last name', optional: true },
117121
message: { type: 'string', description: 'Status message' },
118122
},
119123
}

apps/sim/tools/sendgrid/create_template_version.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ export const sendGridCreateTemplateVersionTool: ToolConfig<
101101
name: data.name,
102102
subject: data.subject,
103103
active: data.active === 1,
104-
htmlContent: data.html_content,
105-
plainContent: data.plain_content,
106-
updatedAt: data.updated_at,
104+
htmlContent: data.html_content ?? null,
105+
plainContent: data.plain_content ?? null,
106+
updatedAt: data.updated_at ?? null,
107107
},
108108
}
109109
},
@@ -114,8 +114,8 @@ export const sendGridCreateTemplateVersionTool: ToolConfig<
114114
name: { type: 'string', description: 'Version name' },
115115
subject: { type: 'string', description: 'Email subject' },
116116
active: { type: 'boolean', description: 'Whether this version is active' },
117-
htmlContent: { type: 'string', description: 'HTML content' },
118-
plainContent: { type: 'string', description: 'Plain text content' },
119-
updatedAt: { type: 'string', description: 'Last update timestamp' },
117+
htmlContent: { type: 'string', description: 'HTML content', optional: true },
118+
plainContent: { type: 'string', description: 'Plain text content', optional: true },
119+
updatedAt: { type: 'string', description: 'Last update timestamp', optional: true },
120120
},
121121
}

apps/sim/tools/sendgrid/get_contact.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,24 @@ export const sendGridGetContactTool: ToolConfig<GetContactParams, ContactResult>
4747
lastName: data.last_name,
4848
createdAt: data.created_at,
4949
updatedAt: data.updated_at,
50-
listIds: data.list_ids,
51-
customFields: data.custom_fields,
50+
listIds: data.list_ids ?? [],
51+
customFields: data.custom_fields ?? null,
5252
},
5353
}
5454
},
5555

5656
outputs: {
5757
id: { type: 'string', description: 'Contact ID' },
5858
email: { type: 'string', description: 'Contact email address' },
59-
firstName: { type: 'string', description: 'Contact first name' },
60-
lastName: { type: 'string', description: 'Contact last name' },
61-
createdAt: { type: 'string', description: 'Creation timestamp' },
62-
updatedAt: { type: 'string', description: 'Last update timestamp' },
63-
listIds: { type: 'json', description: 'Array of list IDs the contact belongs to' },
64-
customFields: { type: 'json', description: 'Custom field values' },
59+
firstName: { type: 'string', description: 'Contact first name', optional: true },
60+
lastName: { type: 'string', description: 'Contact last name', optional: true },
61+
createdAt: { type: 'string', description: 'Creation timestamp', optional: true },
62+
updatedAt: { type: 'string', description: 'Last update timestamp', optional: true },
63+
listIds: {
64+
type: 'json',
65+
description: 'Array of list IDs the contact belongs to',
66+
optional: true,
67+
},
68+
customFields: { type: 'json', description: 'Custom field values', optional: true },
6569
},
6670
}

apps/sim/tools/sendgrid/list_all_lists.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ export const sendGridListAllListsTool: ToolConfig<ListAllListsParams, ListsResul
1818
type: 'number',
1919
required: false,
2020
visibility: 'user-or-llm',
21-
description: 'Number of lists to return per page (default: 100)',
21+
description: 'Number of lists to return per page (default: 100, max: 1000)',
22+
},
23+
pageToken: {
24+
type: 'string',
25+
required: false,
26+
visibility: 'user-or-llm',
27+
description: 'Page token from a previous response (nextPageToken) to fetch the next page',
2228
},
2329
},
2430

@@ -28,6 +34,9 @@ export const sendGridListAllListsTool: ToolConfig<ListAllListsParams, ListsResul
2834
if (params.pageSize) {
2935
url.searchParams.append('page_size', params.pageSize.toString())
3036
}
37+
if (params.pageToken) {
38+
url.searchParams.append('page_token', params.pageToken)
39+
}
3140
return url.toString()
3241
},
3342
method: 'GET',
@@ -42,17 +51,35 @@ export const sendGridListAllListsTool: ToolConfig<ListAllListsParams, ListsResul
4251
throw new Error(error.errors?.[0]?.message || 'Failed to list all lists')
4352
}
4453

45-
const data = (await response.json()) as { result?: SendGridList[] }
54+
const data = (await response.json()) as {
55+
result?: SendGridList[]
56+
_metadata?: { next?: string }
57+
}
58+
59+
let nextPageToken: string | null = null
60+
if (data._metadata?.next) {
61+
try {
62+
nextPageToken = new URL(data._metadata.next).searchParams.get('page_token')
63+
} catch {
64+
nextPageToken = null
65+
}
66+
}
4667

4768
return {
4869
success: true,
4970
output: {
5071
lists: data.result || [],
72+
nextPageToken,
5173
},
5274
}
5375
},
5476

5577
outputs: {
5678
lists: { type: 'json', description: 'Array of lists' },
79+
nextPageToken: {
80+
type: 'string',
81+
description: 'Token to pass as pageToken to fetch the next page, if more results exist',
82+
optional: true,
83+
},
5784
},
5885
}

apps/sim/tools/sendgrid/list_templates.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ export const sendGridListTemplatesTool: ToolConfig<ListTemplatesParams, Template
2424
type: 'number',
2525
required: false,
2626
visibility: 'user-or-llm',
27-
description: 'Number of templates to return per page (default: 20)',
27+
description: 'Number of templates to return per page (default: 20, max: 200)',
28+
},
29+
pageToken: {
30+
type: 'string',
31+
required: false,
32+
visibility: 'user-or-llm',
33+
description: 'Page token from a previous response (nextPageToken) to fetch the next page',
2834
},
2935
},
3036

@@ -37,6 +43,9 @@ export const sendGridListTemplatesTool: ToolConfig<ListTemplatesParams, Template
3743
if (params.pageSize) {
3844
url.searchParams.append('page_size', params.pageSize.toString())
3945
}
46+
if (params.pageToken) {
47+
url.searchParams.append('page_token', params.pageToken)
48+
}
4049
return url.toString()
4150
},
4251
method: 'GET',
@@ -53,18 +62,33 @@ export const sendGridListTemplatesTool: ToolConfig<ListTemplatesParams, Template
5362

5463
const data = (await response.json()) as {
5564
result?: SendGridTemplate[]
56-
templates?: SendGridTemplate[]
65+
_metadata?: { next?: string }
66+
}
67+
68+
let nextPageToken: string | null = null
69+
if (data._metadata?.next) {
70+
try {
71+
nextPageToken = new URL(data._metadata.next).searchParams.get('page_token')
72+
} catch {
73+
nextPageToken = null
74+
}
5775
}
5876

5977
return {
6078
success: true,
6179
output: {
62-
templates: data.result || data.templates || [],
80+
templates: data.result || [],
81+
nextPageToken,
6382
},
6483
}
6584
},
6685

6786
outputs: {
6887
templates: { type: 'json', description: 'Array of templates' },
88+
nextPageToken: {
89+
type: 'string',
90+
description: 'Token to pass as pageToken to fetch the next page, if more results exist',
91+
optional: true,
92+
},
6993
},
7094
}

apps/sim/tools/sendgrid/remove_contacts_from_list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ export const sendGridRemoveContactsFromListTool: ToolConfig<
5656
return {
5757
success: true,
5858
output: {
59-
jobId: data.job_id,
59+
jobId: data.job_id ?? null,
6060
},
6161
}
6262
},
6363

6464
outputs: {
65-
jobId: { type: 'string', description: 'Job ID for the request' },
65+
jobId: { type: 'string', description: 'Job ID for the request', optional: true },
6666
},
6767
}

apps/sim/tools/sendgrid/search_contacts.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@ export const sendGridSearchContactsTool: ToolConfig<SearchContactsParams, Contac
5454
success: true,
5555
output: {
5656
contacts: data.result || [],
57-
contactCount: data.contact_count,
57+
contactCount: data.contact_count ?? null,
5858
},
5959
}
6060
},
6161

6262
outputs: {
6363
contacts: { type: 'json', description: 'Array of matching contacts' },
64-
contactCount: { type: 'number', description: 'Total number of contacts found' },
64+
contactCount: {
65+
type: 'number',
66+
description: 'Total number of contacts found',
67+
optional: true,
68+
},
6569
},
6670
}

apps/sim/tools/sendgrid/send_mail.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export const sendGridSendMailTool: ToolConfig<SendMailParams, SendMailResult> =
149149

150150
outputs: {
151151
success: { type: 'boolean', description: 'Whether the email was sent successfully' },
152-
messageId: { type: 'string', description: 'SendGrid message ID' },
152+
messageId: { type: 'string', description: 'SendGrid message ID', optional: true },
153153
to: { type: 'string', description: 'Recipient email address' },
154154
subject: { type: 'string', description: 'Email subject' },
155155
},

0 commit comments

Comments
 (0)