2
0

Add attachments option to text input (#1608)

Closes #854
This commit is contained in:
Baptiste Arnaud
2024-06-26 10:13:38 +02:00
committed by GitHub
parent 80da7af4f1
commit 6db0464fd7
88 changed files with 2959 additions and 735 deletions

View File

@@ -13,6 +13,7 @@ const answerV1Schema = z.object({
export const answerSchema = z.object({
blockId: z.string(),
content: z.string(),
attachedFileUrls: z.array(z.string()).optional(),
})
export const answerInputSchema = answerV1Schema

View File

@@ -4,4 +4,8 @@ import { TextInputBlock } from './schema'
export const defaultTextInputOptions = {
isLong: false,
labels: { button: defaultButtonLabel, placeholder: 'Type your answer...' },
attachments: {
isEnabled: false,
visibility: 'Auto',
},
} as const satisfies TextInputBlock['options']

View File

@@ -1,6 +1,7 @@
import { z } from '../../../../zod'
import { optionBaseSchema, blockBaseSchema } from '../../shared'
import { InputBlockType } from '../constants'
import { fileVisibilityOptions } from '../file/constants'
export const textInputOptionsBaseSchema = z.object({
labels: z
@@ -16,6 +17,13 @@ export const textInputOptionsSchema = textInputOptionsBaseSchema
.merge(
z.object({
isLong: z.boolean().optional(),
attachments: z
.object({
isEnabled: z.boolean().optional(),
saveVariableId: z.string().optional(),
visibility: z.enum(fileVisibilityOptions).optional(),
})
.optional(),
})
)

View File

@@ -29,6 +29,23 @@ import { BubbleBlockType } from '../blocks/bubbles/constants'
import { clientSideActionSchema } from './clientSideAction'
import { ChatSession as ChatSessionFromPrisma } from '@typebot.io/prisma'
export const messageSchema = z.preprocess(
(val) => (typeof val === 'string' ? { type: 'text', text: val } : val),
z.discriminatedUnion('type', [
z.object({
type: z.literal('text'),
text: z.string(),
attachedFileUrls: z
.array(z.string())
.optional()
.describe(
'Can only be provided if current input block is a text input block that allows attachments'
),
}),
])
)
export type Message = z.infer<typeof messageSchema>
const chatSessionSchema = z.object({
id: z.string(),
createdAt: z.date(),
@@ -183,8 +200,7 @@ export const startChatInputSchema = z.object({
.describe(
"[Where to find my bot's public ID?](../how-to#how-to-find-my-publicid)"
),
message: z
.string()
message: messageSchema
.optional()
.describe(
"Only provide it if your flow starts with an input block and you'd like to directly provide an answer to it."
@@ -242,7 +258,7 @@ export const startPreviewChatInputSchema = z.object({
"[Where to find my bot's ID?](../how-to#how-to-find-my-typebotid)"
),
isStreamEnabled: z.boolean().optional().default(false),
message: z.string().optional(),
message: messageSchema.optional(),
isOnlyRegistering: z
.boolean()
.optional()

View File

@@ -115,13 +115,13 @@ export const incomingMessageSchema = z.discriminatedUnion('type', [
z.object({
from: z.string(),
type: z.literal('image'),
image: z.object({ id: z.string() }),
image: z.object({ id: z.string(), caption: z.string().optional() }),
timestamp: z.string(),
}),
z.object({
from: z.string(),
type: z.literal('video'),
video: z.object({ id: z.string() }),
video: z.object({ id: z.string(), caption: z.string().optional() }),
timestamp: z.string(),
}),
z.object({
@@ -133,7 +133,7 @@ export const incomingMessageSchema = z.discriminatedUnion('type', [
z.object({
from: z.string(),
type: z.literal('document'),
document: z.object({ id: z.string() }),
document: z.object({ id: z.string(), caption: z.string().optional() }),
timestamp: z.string(),
}),
z.object({