<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced file visibility options for uploaded files, allowing users to set files as public or private. - Added a new API endpoint for retrieving temporary URLs for files, enhancing file accessibility. - Expanded file upload documentation to include information on file visibility settings. - Updated URL validation to support URLs with port numbers and "http://localhost". - **Enhancements** - Improved media download functionality by replacing the `got` library with a custom `downloadMedia` function. - Enhanced bot flow continuation and session start logic to support a wider range of reply types, including WhatsApp media messages. - **Bug Fixes** - Adjusted file path and URL construction in the `generateUploadUrl` function to correctly reflect file visibility settings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import { z } from '../../../../zod'
|
|
import { optionBaseSchema, blockBaseSchema } from '../../shared'
|
|
import { InputBlockType } from '../constants'
|
|
import { fileVisibilityOptions } from './constants'
|
|
|
|
const fileInputOptionsV5Schema = optionBaseSchema.merge(
|
|
z.object({
|
|
isRequired: z.boolean().optional(),
|
|
isMultipleAllowed: z.boolean().optional(),
|
|
labels: z
|
|
.object({
|
|
placeholder: z.string().optional(),
|
|
button: z.string().optional(),
|
|
clear: z.string().optional(),
|
|
skip: z.string().optional(),
|
|
})
|
|
.optional(),
|
|
sizeLimit: z.number().optional(),
|
|
visibility: z.enum(fileVisibilityOptions).optional(),
|
|
})
|
|
)
|
|
|
|
const fileInputOptionsSchemas = {
|
|
v5: fileInputOptionsV5Schema,
|
|
v6: fileInputOptionsV5Schema.omit({
|
|
sizeLimit: true,
|
|
}),
|
|
} as const
|
|
|
|
const fileInputBlockV5Schema = blockBaseSchema.merge(
|
|
z.object({
|
|
type: z.literal(InputBlockType.FILE),
|
|
options: fileInputOptionsSchemas.v5.optional(),
|
|
})
|
|
)
|
|
|
|
export const fileInputBlockSchemas = {
|
|
v5: fileInputBlockV5Schema.openapi({
|
|
title: 'File input v5',
|
|
ref: 'fileInputV5',
|
|
}),
|
|
v6: fileInputBlockV5Schema
|
|
.merge(
|
|
z.object({
|
|
options: fileInputOptionsSchemas.v6.optional(),
|
|
})
|
|
)
|
|
.openapi({
|
|
title: 'File',
|
|
ref: 'fileInput',
|
|
}),
|
|
}
|
|
|
|
const fileInputBlockSchema = z.union([
|
|
fileInputBlockSchemas.v5,
|
|
fileInputBlockSchemas.v6,
|
|
])
|
|
|
|
export type FileInputBlock = z.infer<typeof fileInputBlockSchema>
|
|
export type FileInputBlockV6 = z.infer<typeof fileInputBlockSchemas.v6>
|