⚡ (fileUpload) New visibility option: "Public", "Private" or "Auto" (#1196)
<!-- 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 -->
This commit is contained in:
@ -12,6 +12,7 @@ import { decrypt } from '@typebot.io/lib/api/encryption/decrypt'
|
||||
import { saveStateToDatabase } from '../saveStateToDatabase'
|
||||
import prisma from '@typebot.io/lib/prisma'
|
||||
import { isDefined } from '@typebot.io/lib/utils'
|
||||
import { Reply } from '../types'
|
||||
|
||||
type Props = {
|
||||
receivedMessage: WhatsAppIncomingMessage
|
||||
@ -43,10 +44,6 @@ export const resumeWhatsAppFlow = async ({
|
||||
const isPreview = workspaceId === undefined || credentialsId === undefined
|
||||
|
||||
const { typebot } = session?.state.typebotsQueue[0] ?? {}
|
||||
const messageContent = await getIncomingMessageContent({
|
||||
message: receivedMessage,
|
||||
typebotId: typebot?.id,
|
||||
})
|
||||
|
||||
const credentials = await getCredentials({ credentialsId, isPreview })
|
||||
|
||||
@ -57,6 +54,13 @@ export const resumeWhatsAppFlow = async ({
|
||||
}
|
||||
}
|
||||
|
||||
const reply = await getIncomingMessageContent({
|
||||
message: receivedMessage,
|
||||
typebotId: typebot?.id,
|
||||
workspaceId,
|
||||
accessToken: credentials?.systemUserAccessToken,
|
||||
})
|
||||
|
||||
const isSessionExpired =
|
||||
session &&
|
||||
isDefined(session.state.expiryTimeout) &&
|
||||
@ -64,13 +68,13 @@ export const resumeWhatsAppFlow = async ({
|
||||
|
||||
const resumeResponse =
|
||||
session && !isSessionExpired
|
||||
? await continueBotFlow(messageContent, {
|
||||
? await continueBotFlow(reply, {
|
||||
version: 2,
|
||||
state: { ...session.state, whatsApp: { contact } },
|
||||
})
|
||||
: workspaceId
|
||||
? await startWhatsAppSession({
|
||||
incomingMessage: messageContent,
|
||||
incomingMessage: reply,
|
||||
workspaceId,
|
||||
credentials: { ...credentials, id: credentialsId as string },
|
||||
contact,
|
||||
@ -128,10 +132,14 @@ export const resumeWhatsAppFlow = async ({
|
||||
const getIncomingMessageContent = async ({
|
||||
message,
|
||||
typebotId,
|
||||
workspaceId,
|
||||
accessToken,
|
||||
}: {
|
||||
message: WhatsAppIncomingMessage
|
||||
typebotId?: string
|
||||
}): Promise<string | undefined> => {
|
||||
workspaceId?: string
|
||||
accessToken: string
|
||||
}): Promise<Reply> => {
|
||||
switch (message.type) {
|
||||
case 'text':
|
||||
return message.text.body
|
||||
@ -151,10 +159,7 @@ const getIncomingMessageContent = async ({
|
||||
if (message.type === 'audio') mediaId = message.audio.id
|
||||
if (message.type === 'document') mediaId = message.document.id
|
||||
if (!mediaId) return
|
||||
return (
|
||||
env.NEXTAUTH_URL +
|
||||
`/api/typebots/${typebotId}/whatsapp/media/${mediaId}`
|
||||
)
|
||||
return { type: 'whatsapp media', mediaId, workspaceId, accessToken }
|
||||
case 'location':
|
||||
return `${message.location.latitude}, ${message.location.longitude}`
|
||||
}
|
||||
|
Reference in New Issue
Block a user