<!-- 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 -->
31 lines
710 B
TypeScript
31 lines
710 B
TypeScript
import { env } from '@typebot.io/env'
|
|
import got from 'got'
|
|
|
|
type Props = {
|
|
mediaId: string
|
|
systemUserAccessToken: string
|
|
}
|
|
|
|
export const downloadMedia = async ({
|
|
mediaId,
|
|
systemUserAccessToken,
|
|
}: Props): Promise<{ file: Buffer; mimeType: string }> => {
|
|
const { body } = await got.get({
|
|
url: `${env.WHATSAPP_CLOUD_API_URL}/v17.0/${mediaId}`,
|
|
headers: {
|
|
Authorization: `Bearer ${systemUserAccessToken}`,
|
|
},
|
|
})
|
|
|
|
const parsedBody = JSON.parse(body) as { url: string; mime_type: string }
|
|
|
|
return {
|
|
file: await got(parsedBody.url, {
|
|
headers: {
|
|
Authorization: `Bearer ${systemUserAccessToken}`,
|
|
},
|
|
}).buffer(),
|
|
mimeType: parsedBody.mime_type,
|
|
}
|
|
}
|