Skip to content
Merged
6 changes: 3 additions & 3 deletions apps/docs/content/docs/integrations/lemlist.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Retrieves campaign activities and steps performed, including email opens, clicks

| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `type` | string | No | Filter by activity type \(e.g., emailOpened, emailClicked, emailReplied, paused\) |
| `type` | string | No | Filter by activity type \(e.g., emailsOpened, emailsClicked, emailsReplied, emailsBounced, paused\) |
| `campaignId` | string | No | Filter by campaign ID \(e.g., "cam_abc123def456"\) |
| `leadId` | string | No | Filter by lead ID \(e.g., "lea_abc123def456"\) |
| `isFirst` | boolean | No | Filter for first activity only |
Expand Down Expand Up @@ -97,8 +97,8 @@ Sends an email to a contact through the Lemlist inbox.
| `sendUserId` | string | Yes | Identifier for the user sending the message \(e.g., "usr_abc123def456"\) |
| `sendUserEmail` | string | Yes | Email address of the sender \(e.g., "sales@company.com"\) |
| `sendUserMailboxId` | string | Yes | Mailbox identifier for the sender \(e.g., "mbx_abc123def456"\) |
| `contactId` | string | Yes | Recipient contact identifier \(e.g., "con_abc123def456"\) |
| `leadId` | string | Yes | Associated lead identifier \(e.g., "lea_abc123def456"\) |
| `contactId` | string | No | Recipient contact identifier \(e.g., "ctc_abc123def456"\). Provide this or the lead ID. |
| `leadId` | string | No | Associated lead identifier \(e.g., "lea_abc123def456"\). Provide this or the contact ID. |
| `subject` | string | Yes | Email subject line |
| `message` | string | Yes | Email message body in HTML format |
| `cc` | json | No | Array of CC email addresses |
Expand Down
6 changes: 6 additions & 0 deletions apps/docs/content/docs/integrations/wealthbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ Read content from a Wealthbox note
| `output` | object | Note data and metadata |
| ↳ `content` | string | Formatted note information |
| ↳ `note` | object | Raw note data from Wealthbox |
| ↳ `notes` | array | Notes in the returned page when no ID is given \(list request\) |
| ↳ `metadata` | object | Operation metadata |
| ↳ `itemId` | string | ID of the note |
| ↳ `noteId` | string | ID of the note |
| ↳ `totalItems` | number | Number of items in the returned page \(list requests only\) |
| ↳ `itemType` | string | Type of item \(note\) |

</ReferenceDetails>
Expand Down Expand Up @@ -112,9 +114,11 @@ Read content from a Wealthbox contact
| `output` | object | Contact data and metadata |
| ↳ `content` | string | Formatted contact information |
| ↳ `contact` | object | Raw contact data from Wealthbox |
| ↳ `contacts` | array | Contacts in the returned page when no ID is given \(list request\) |
| ↳ `metadata` | object | Operation metadata |
| ↳ `itemId` | string | ID of the contact |
| ↳ `contactId` | string | ID of the contact |
| ↳ `totalItems` | number | Number of items in the returned page \(list requests only\) |
| ↳ `itemType` | string | Type of item \(contact\) |

</ReferenceDetails>
Expand Down Expand Up @@ -169,9 +173,11 @@ Read content from a Wealthbox task
| `output` | object | Task data and metadata |
| ↳ `content` | string | Formatted task information |
| ↳ `task` | object | Raw task data from Wealthbox |
| ↳ `tasks` | array | Tasks in the returned page when no ID is given \(list request\) |
| ↳ `metadata` | object | Operation metadata |
| ↳ `itemId` | string | ID of the task |
| ↳ `taskId` | string | ID of the task |
| ↳ `totalItems` | number | Number of items in the returned page \(list requests only\) |
| ↳ `itemType` | string | Type of item \(task\) |

</ReferenceDetails>
Expand Down
6 changes: 2 additions & 4 deletions apps/sim/blocks/blocks/lemlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,14 @@ export const LemlistBlock: BlockConfig = {
id: 'contactId',
title: 'Contact ID',
type: 'short-input',
placeholder: 'Recipient contact ID',
required: { field: 'operation', value: 'send_email' },
placeholder: 'Recipient contact ID (or provide the lead ID)',
condition: { field: 'operation', value: 'send_email' },
},
{
id: 'leadId',
title: 'Lead ID',
type: 'short-input',
placeholder: 'Associated lead ID',
required: { field: 'operation', value: 'send_email' },
placeholder: 'Associated lead ID (or provide the contact ID)',
condition: { field: 'operation', value: 'send_email' },
},
{
Expand Down
153 changes: 153 additions & 0 deletions apps/sim/blocks/blocks/wealthbox.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { describe, expect, it } from 'vitest'
import { WealthboxBlock } from '@/blocks/blocks/wealthbox'
import { wealthboxReadContactTool } from '@/tools/wealthbox/read_contact'
import { wealthboxReadNoteTool } from '@/tools/wealthbox/read_note'
import { wealthboxReadTaskTool } from '@/tools/wealthbox/read_task'
import { wealthboxWriteTaskTool } from '@/tools/wealthbox/write_task'

function mapParams(params: Record<string, unknown>, context?: { operation: string }) {
const mapper = WealthboxBlock.tools.config?.params
if (!mapper) throw new Error('Wealthbox block has no params mapper')
return { ...params, ...mapper(params, context) }
}

function taskBody(params: Record<string, unknown>) {
const body = wealthboxWriteTaskTool.request.body
if (!body) throw new Error('Write task tool has no request body')
const optionalString = (value: unknown) => (typeof value === 'string' ? value : undefined)
return body({
accessToken: 'token',
operation: 'write_task',
title: optionalString(params.title),
dueDate: optionalString(params.dueDate),
description: optionalString(params.description),
contactId: optionalString(params.contactId),
})
}

describe('Wealthbox Write Task', () => {
it('sends the block Content field as the task description', () => {
const params = mapParams({
operation: 'write_task',
oauthCredential: 'cred',
title: 'Call client',
dueDate: '2026-01-05 11:00 AM -0500',
content: 'Review the portfolio',
contactId: '42',
})

expect(taskBody(params)).toMatchObject({
name: 'Call client',
description: 'Review the portfolio',
linked_to: [{ id: 42, type: 'Contact' }],
})
})

it('keeps the model description on an agent tool call', () => {
const params = mapParams(
{
oauthCredential: 'cred',
title: 'Call client',
dueDate: '2026-01-05 11:00 AM -0500',
description: 'From the model',
},
{ operation: 'write_task' }
)

expect(taskBody(params)).toMatchObject({ description: 'From the model' })
})
})

describe('Wealthbox Read Note without a note ID', () => {
it('returns the listed notes and keeps the raw list body under note', async () => {
const transform = wealthboxReadNoteTool.transformResponse
if (!transform) throw new Error('Read note tool has no transformResponse')

const notes = [{ id: 1, content: 'Spoke with the client' }]
const result = await transform(Response.json({ status_updates: notes }))

expect(result.output).toMatchObject({
notes,
note: { status_updates: notes },
metadata: { totalItems: 1 },
})
})
})

function readUrl(
tool: typeof wealthboxReadTaskTool,
operation: 'read_task' | 'read_contact',
params: Record<string, unknown>
) {
const url = tool.request.url
if (typeof url !== 'function') throw new Error('Read tool has no URL builder')
const id = (value: unknown) => (typeof value === 'string' ? value : undefined)
return url({
accessToken: 'token',
operation,
taskId: id(params.taskId),
contactId: id(params.contactId),
})
}

describe('Wealthbox reads without an ID', () => {
it('still requires a task ID on the canvas', () => {
expect(() =>
mapParams({ operation: 'read_task', oauthCredential: 'cred', taskId: '' })
).toThrow('Task ID is required')
})

it('still requires a contact ID on the canvas', () => {
expect(() =>
mapParams({ operation: 'read_contact', oauthCredential: 'cred', contactId: '' })
).toThrow('Contact ID is required')
})

it('lists tasks on an agent call with no task ID', () => {
const params = mapParams({ oauthCredential: 'cred' }, { operation: 'read_task' })

expect(readUrl(wealthboxReadTaskTool, 'read_task', params)).toBe(
'https://api.crmworkspace.com/v1/tasks'
)
})

it('lists contacts on an agent call with no contact ID', () => {
const params = mapParams({ oauthCredential: 'cred' }, { operation: 'read_contact' })

expect(readUrl(wealthboxReadContactTool, 'read_contact', params)).toBe(
'https://api.crmworkspace.com/v1/contacts'
)
})
})

describe('Wealthbox Write Task with a stale Read Task ID', () => {
it('drops a stored task ID on an agent call too', () => {
const params = mapParams(
{ oauthCredential: 'cred', title: 'Call client', dueDate: 'tomorrow', taskId: '999' },
{ operation: 'write_task' }
)

expect(params.taskId).toBeUndefined()
})

it('creates the task instead of posting to the stale task path', () => {
const params = mapParams({
operation: 'write_task',
oauthCredential: 'cred',
title: 'Call client',
dueDate: '2026-01-05 11:00 AM -0500',
contactId: '42',
taskId: '999',
})
const url = wealthboxWriteTaskTool.request.url
if (typeof url !== 'function') throw new Error('Write task tool has no URL builder')

expect(
url({
accessToken: 'token',
operation: 'write_task',
taskId: typeof params.taskId === 'string' ? params.taskId : undefined,
})
).toBe('https://api.crmworkspace.com/v1/tasks')
})
})
17 changes: 12 additions & 5 deletions apps/sim/blocks/blocks/wealthbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { WealthboxIcon } from '@/components/icons'
import { getScopesForService } from '@/lib/oauth/utils'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { isToolCall, mapperOperation } from '@/blocks/utils'
import { isToolCall, mapperOperation, toolCallArg } from '@/blocks/utils'

const CONTACT_FIELD = ['contactId', 'manualContactId'] as const

Expand All @@ -22,7 +22,7 @@ export const WealthboxBlock: BlockConfig = {
defaultTitle: 'Wealthbox',
sentences: {
byOperation: {
read_note: [{ text: 'Read note', field: 'noteId', core: true }],
read_note: ['Read notes', { text: ', or note', field: 'noteId' }],
write_note: [
{ text: 'Write note', field: 'content', core: true },
{ text: 'on contact', field: CONTACT_FIELD },
Expand Down Expand Up @@ -246,13 +246,20 @@ Return ONLY the date/time string - no explanations, no quotes, no extra text.`,
taskId: taskId.trim(),
}
}
if (operation === 'write_task' || operation === 'write_note') {
if (operation === 'write_task') {
const content = typeof params.content === 'string' ? params.content.trim() : ''
const description = toolCallArg(context, params.description) || content || undefined
const taskParams = {
...baseParams,
...(description ? { description } : {}),
taskId: undefined,
}
if (!contactId?.trim()) {
if (isToolCall(context)) return baseParams
if (isToolCall(context)) return taskParams
throw new Error('Contact ID is required for this operation')
}
return {
...baseParams,
...taskParams,
contactId: contactId.trim(),
}
}
Expand Down
5 changes: 3 additions & 2 deletions apps/sim/lib/webhooks/providers/lemlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export const lemlistHandler: WebhookProviderHandler = {
webhookId: webhook.id,
})

const lemlistApiUrl = 'https://api.lemlist.com/api/hooks'
const lemlistApiUrl = new URL('https://api.lemlist.com/api/hooks')
if (campaignId) lemlistApiUrl.searchParams.set('campaignId', String(campaignId))

const requestBody: Record<string, unknown> = {
targetUrl: notificationUrl,
Expand All @@ -69,7 +70,7 @@ export const lemlistHandler: WebhookProviderHandler = {
requestBody.campaignId = campaignId
}

const lemlistResponse = await outboundFetch(lemlistApiUrl, {
const lemlistResponse = await outboundFetch(lemlistApiUrl.toString(), {
method: 'POST',
headers: {
Authorization: `Basic ${authString}`,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/attio/assert_record.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createLogger } from '@sim/logger'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'
import type { AttioAssertRecordParams, AttioAssertRecordResponse } from './types'
import { RECORD_OUTPUT_PROPERTIES } from './types'

Expand Down Expand Up @@ -49,7 +50,7 @@ export const attioAssertRecordTool: ToolConfig<AttioAssertRecordParams, AttioAss

request: {
url: (params) =>
`https://api.attio.com/v2/objects/${params.objectType.trim()}/records?matching_attribute=${params.matchingAttribute.trim()}`,
`https://api.attio.com/v2/objects/${safeUrlPathSegment(params.objectType, 'objectType')}/records?matching_attribute=${encodeURIComponent(params.matchingAttribute.trim())}`,
method: 'PUT',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/attio/create_attribute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createLogger } from '@sim/logger'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'
import type { AttioCreateAttributeParams, AttioCreateAttributeResponse } from './types'
import { ATTRIBUTE_OUTPUT_PROPERTIES } from './types'

Expand Down Expand Up @@ -92,7 +93,7 @@ export const attioCreateAttributeTool: ToolConfig<

request: {
url: (params) =>
`https://api.attio.com/v2/${params.target.trim()}/${params.identifier.trim()}/attributes`,
`https://api.attio.com/v2/${safeUrlPathSegment(params.target, 'target')}/${safeUrlPathSegment(params.identifier, 'identifier')}/attributes`,
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand Down
4 changes: 3 additions & 1 deletion apps/sim/tools/attio/create_list_entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createLogger } from '@sim/logger'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'
import type { AttioCreateListEntryParams, AttioCreateListEntryResponse } from './types'
import { LIST_ENTRY_OUTPUT_PROPERTIES } from './types'

Expand Down Expand Up @@ -53,7 +54,8 @@ export const attioCreateListEntryTool: ToolConfig<
},

request: {
url: (params) => `https://api.attio.com/v2/lists/${params.list.trim()}/entries`,
url: (params) =>
`https://api.attio.com/v2/lists/${safeUrlPathSegment(params.list, 'list')}/entries`,
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand Down
4 changes: 3 additions & 1 deletion apps/sim/tools/attio/create_record.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createLogger } from '@sim/logger'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'
import type { AttioCreateRecordParams, AttioCreateRecordResponse } from './types'
import { RECORD_OBJECT_OUTPUT } from './types'

Expand Down Expand Up @@ -39,7 +40,8 @@ export const attioCreateRecordTool: ToolConfig<AttioCreateRecordParams, AttioCre
},

request: {
url: (params) => `https://api.attio.com/v2/objects/${params.objectType.trim()}/records`,
url: (params) =>
`https://api.attio.com/v2/objects/${safeUrlPathSegment(params.objectType, 'objectType')}/records`,
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand Down
4 changes: 3 additions & 1 deletion apps/sim/tools/attio/delete_comment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createLogger } from '@sim/logger'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'
import type { AttioDeleteCommentParams, AttioDeleteCommentResponse } from './types'

const logger = createLogger('AttioDeleteComment')
Expand Down Expand Up @@ -34,7 +35,8 @@ export const attioDeleteCommentTool: ToolConfig<
},

request: {
url: (params) => `https://api.attio.com/v2/comments/${params.commentId.trim()}`,
url: (params) =>
`https://api.attio.com/v2/comments/${safeUrlPathSegment(params.commentId, 'commentId')}`,
method: 'DELETE',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/attio/delete_list_entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createLogger } from '@sim/logger'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'
import type { AttioDeleteListEntryParams, AttioDeleteListEntryResponse } from './types'

const logger = createLogger('AttioDeleteListEntry')
Expand Down Expand Up @@ -41,7 +42,7 @@ export const attioDeleteListEntryTool: ToolConfig<

request: {
url: (params) =>
`https://api.attio.com/v2/lists/${params.list.trim()}/entries/${params.entryId.trim()}`,
`https://api.attio.com/v2/lists/${safeUrlPathSegment(params.list, 'list')}/entries/${safeUrlPathSegment(params.entryId, 'entryId')}`,
method: 'DELETE',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand Down
Loading
Loading