Skip to content

Commit e055ddc

Browse files
author
aadamgough
committed
fixed typeform
1 parent 086982c commit e055ddc

File tree

5 files changed

+158
-60
lines changed

5 files changed

+158
-60
lines changed

apps/sim/blocks/blocks/typeform.ts

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,76 @@ export const TypeformBlock: BlockConfig<TypeformResponse> = {
199199
{
200200
id: 'operations',
201201
title: 'JSON Patch Operations',
202-
type: 'long-input',
203-
placeholder: 'JSON array of patch operations (RFC 6902)',
202+
type: 'code',
203+
language: 'json',
204+
placeholder: '[{"op": "replace", "path": "/title", "value": "New Title"}]',
204205
condition: { field: 'operation', value: 'typeform_update_form' },
205206
required: true,
207+
wandConfig: {
208+
enabled: true,
209+
maintainHistory: true,
210+
prompt: `You are an expert at creating JSON Patch operations (RFC 6902) for Typeform forms.
211+
Generate ONLY the JSON array of patch operations based on the user's request.
212+
The output MUST be a valid JSON array, starting with [ and ending with ].
213+
214+
Current operations: {context}
215+
216+
### JSON PATCH OPERATIONS
217+
Each operation is an object with:
218+
- "op": The operation type ("add", "remove", "replace", "move", "copy", "test")
219+
- "path": JSON pointer to the target location (e.g., "/title", "/fields/0", "/settings/language")
220+
- "value": The new value (required for "add", "replace", "copy", "test")
221+
- "from": Source path (required for "move" and "copy")
222+
223+
### COMMON TYPEFORM PATHS
224+
- /title - Form title
225+
- /settings/language - Form language (e.g., "en", "es", "fr")
226+
- /settings/is_public - Whether form is public (true/false)
227+
- /settings/show_progress_bar - Show progress bar (true/false)
228+
- /fields - Array of form fields
229+
- /fields/- - Add to end of fields array
230+
- /fields/0 - First field
231+
- /welcome_screens - Array of welcome screens
232+
- /thankyou_screens - Array of thank you screens
233+
- /theme/href - Theme URL reference
234+
235+
### FIELD OBJECT STRUCTURE
236+
{
237+
"type": "short_text" | "long_text" | "email" | "number" | "multiple_choice" | "yes_no" | "rating" | "date" | "dropdown" | "file_upload",
238+
"title": "Question text",
239+
"ref": "unique_reference_id",
240+
"properties": { ... },
241+
"validations": { "required": true/false }
242+
}
243+
244+
### EXAMPLES
245+
246+
**Change form title:**
247+
[{"op": "replace", "path": "/title", "value": "My Updated Form"}]
248+
249+
**Add a new text field:**
250+
[{"op": "add", "path": "/fields/-", "value": {"type": "short_text", "title": "What is your name?", "ref": "name_field", "validations": {"required": true}}}]
251+
252+
**Add multiple choice field:**
253+
[{"op": "add", "path": "/fields/-", "value": {"type": "multiple_choice", "title": "Select your favorite color", "ref": "color_field", "properties": {"choices": [{"label": "Red"}, {"label": "Blue"}, {"label": "Green"}]}}}]
254+
255+
**Remove first field:**
256+
[{"op": "remove", "path": "/fields/0"}]
257+
258+
**Update form settings:**
259+
[{"op": "replace", "path": "/settings/language", "value": "es"}, {"op": "replace", "path": "/settings/is_public", "value": false}]
260+
261+
**Multiple operations:**
262+
[
263+
{"op": "replace", "path": "/title", "value": "Customer Feedback Form"},
264+
{"op": "add", "path": "/fields/-", "value": {"type": "rating", "title": "Rate your experience", "ref": "rating_field", "properties": {"steps": 5}}},
265+
{"op": "replace", "path": "/settings/show_progress_bar", "value": true}
266+
]
267+
268+
Do not include any explanations, markdown formatting, or other text outside the JSON array.`,
269+
placeholder: 'Describe how you want to update the form...',
270+
generationType: 'json-object',
271+
},
206272
},
207273
...getTrigger('typeform_webhook').subBlocks,
208274
],
@@ -322,6 +388,9 @@ export const TypeformBlock: BlockConfig<TypeformResponse> = {
322388
fields: { type: 'json', description: 'Form fields array' },
323389
welcome_screens: { type: 'json', description: 'Welcome screens array' },
324390
thankyou_screens: { type: 'json', description: 'Thank you screens array' },
391+
created_at: { type: 'string', description: 'Form creation timestamp' },
392+
last_updated_at: { type: 'string', description: 'Form last update timestamp' },
393+
published_at: { type: 'string', description: 'Form publication timestamp' },
325394
_links: { type: 'json', description: 'Related resource links' },
326395
// Delete form outputs
327396
deleted: { type: 'boolean', description: 'Whether the form was deleted' },

apps/sim/tools/typeform/create_form.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ export const createFormTool: ToolConfig<TypeformCreateFormParams, TypeformCreate
9898

9999
return {
100100
success: true,
101-
output: data,
101+
output: {
102+
...data,
103+
welcome_screens: data.welcome_screens || [],
104+
thankyou_screens: data.thankyou_screens || [],
105+
fields: data.fields || [],
106+
},
102107
}
103108
},
104109

@@ -115,9 +120,29 @@ export const createFormTool: ToolConfig<TypeformCreateFormParams, TypeformCreate
115120
type: 'string',
116121
description: 'Form type',
117122
},
123+
settings: {
124+
type: 'object',
125+
description: 'Form settings object',
126+
},
127+
theme: {
128+
type: 'object',
129+
description: 'Theme reference',
130+
},
131+
workspace: {
132+
type: 'object',
133+
description: 'Workspace reference',
134+
},
118135
fields: {
119136
type: 'array',
120-
description: 'Array of created form fields',
137+
description: 'Array of created form fields (empty if none added)',
138+
},
139+
welcome_screens: {
140+
type: 'array',
141+
description: 'Array of welcome screens (empty if none configured)',
142+
},
143+
thankyou_screens: {
144+
type: 'array',
145+
description: 'Array of thank you screens',
121146
},
122147
_links: {
123148
type: 'object',

apps/sim/tools/typeform/get_form.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ export const getFormTool: ToolConfig<TypeformGetFormParams, TypeformGetFormRespo
3737

3838
return {
3939
success: true,
40-
output: data,
40+
output: {
41+
...data,
42+
welcome_screens: data.welcome_screens || [],
43+
thankyou_screens: data.thankyou_screens || [],
44+
fields: data.fields || [],
45+
},
4146
}
4247
},
4348

@@ -72,12 +77,24 @@ export const getFormTool: ToolConfig<TypeformGetFormParams, TypeformGetFormRespo
7277
},
7378
welcome_screens: {
7479
type: 'array',
75-
description: 'Array of welcome screens',
80+
description: 'Array of welcome screens (empty if none configured)',
7681
},
7782
thankyou_screens: {
7883
type: 'array',
7984
description: 'Array of thank you screens',
8085
},
86+
created_at: {
87+
type: 'string',
88+
description: 'Form creation timestamp (ISO 8601 format)',
89+
},
90+
last_updated_at: {
91+
type: 'string',
92+
description: 'Form last update timestamp (ISO 8601 format)',
93+
},
94+
published_at: {
95+
type: 'string',
96+
description: 'Form publication timestamp (ISO 8601 format)',
97+
},
8198
_links: {
8299
type: 'object',
83100
description: 'Related resource links including public form URL',

apps/sim/tools/typeform/types.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,7 @@ export interface TypeformUpdateFormParams {
221221

222222
export interface TypeformUpdateFormResponse extends ToolResponse {
223223
output: {
224-
id: string
225-
title: string
226-
type: string
227-
created_at: string
228-
last_updated_at: string
229-
settings: Record<string, any>
230-
theme: Record<string, any>
231-
workspace?: {
232-
href: string
233-
}
234-
fields: Array<Record<string, any>>
235-
thankyou_screens?: Array<Record<string, any>>
236-
_links: Record<string, any>
237-
[key: string]: any
224+
message: string
238225
}
239226
}
240227

apps/sim/tools/typeform/update_form.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,54 +44,54 @@ export const updateFormTool: ToolConfig<TypeformUpdateFormParams, TypeformUpdate
4444
},
4545

4646
transformResponse: async (response: Response) => {
47-
const data = await response.json()
47+
// Check if response has content
48+
const text = await response.text()
4849

50+
// Handle empty responses
51+
if (!text || text.trim() === '') {
52+
if (response.ok) {
53+
// Success with no content (e.g., 204 No Content)
54+
return {
55+
success: true,
56+
output: {
57+
message: 'Form updated successfully',
58+
},
59+
}
60+
}
61+
throw new Error(`Request failed with status ${response.status}: ${response.statusText}`)
62+
}
63+
64+
// Try to parse as JSON
65+
let data: any
66+
try {
67+
data = JSON.parse(text)
68+
} catch {
69+
// If response is not OK and not JSON, throw with the raw text
70+
if (!response.ok) {
71+
throw new Error(`Request failed with status ${response.status}: ${text.slice(0, 200)}`)
72+
}
73+
throw new Error(`Invalid JSON response: ${text.slice(0, 200)}`)
74+
}
75+
76+
// Handle error responses from Typeform API
77+
if (!response.ok) {
78+
const errorMessage = data.description || data.message || data.error || JSON.stringify(data)
79+
throw new Error(`Typeform API error (${response.status}): ${errorMessage}`)
80+
}
81+
82+
// Return simple success message (Typeform PATCH returns minimal/no content on success)
4983
return {
5084
success: true,
51-
output: data,
85+
output: {
86+
message: 'Form updated successfully',
87+
},
5288
}
5389
},
5490

5591
outputs: {
56-
id: {
57-
type: 'string',
58-
description: 'Updated form unique identifier',
59-
},
60-
title: {
92+
message: {
6193
type: 'string',
62-
description: 'Form title',
63-
},
64-
type: {
65-
type: 'string',
66-
description: 'Form type',
67-
},
68-
settings: {
69-
type: 'object',
70-
description: 'Form settings',
71-
},
72-
theme: {
73-
type: 'object',
74-
description: 'Theme reference',
75-
},
76-
workspace: {
77-
type: 'object',
78-
description: 'Workspace reference',
79-
},
80-
fields: {
81-
type: 'array',
82-
description: 'Array of form fields',
83-
},
84-
welcome_screens: {
85-
type: 'array',
86-
description: 'Array of welcome screens',
87-
},
88-
thankyou_screens: {
89-
type: 'array',
90-
description: 'Array of thank you screens',
91-
},
92-
_links: {
93-
type: 'object',
94-
description: 'Related resource links',
94+
description: 'Success confirmation message',
9595
},
9696
},
9797
}

0 commit comments

Comments
 (0)