2
0

Add WhatsApp integration beta test (#722)

Related to #401
This commit is contained in:
Baptiste Arnaud
2023-08-29 10:01:28 +02:00
parent 036b407a11
commit b852b4af0b
136 changed files with 6694 additions and 5383 deletions

View File

@@ -0,0 +1,31 @@
import { env } from '@typebot.io/env'
import { Client } from 'minio'
export const deleteFilesFromBucket = async ({
urls,
}: {
urls: string[]
}): Promise<void> => {
if (!env.S3_ENDPOINT || !env.S3_ACCESS_KEY || !env.S3_SECRET_KEY)
throw new Error(
'S3 not properly configured. Missing one of those variables: S3_ENDPOINT, S3_ACCESS_KEY, S3_SECRET_KEY'
)
const minioClient = new Client({
endPoint: env.S3_ENDPOINT,
port: env.S3_PORT,
useSSL: env.S3_SSL ?? true,
accessKey: env.S3_ACCESS_KEY,
secretKey: env.S3_SECRET_KEY,
region: env.S3_REGION,
})
const bucket = env.S3_BUCKET ?? 'typebot'
return minioClient.removeObjects(
bucket,
urls
.filter((url) => url.includes(env.S3_ENDPOINT as string))
.map((url) => url.split(`/${bucket}/`)[1])
)
}

View File

@@ -24,9 +24,9 @@ export const generatePresignedUrl = ({
accessKeyId: env.S3_ACCESS_KEY,
secretAccessKey: env.S3_SECRET_KEY,
region: env.S3_REGION,
sslEnabled: env.S3_SSL,
sslEnabled: env.S3_SSL ?? true,
})
const protocol = env.S3_SSL ? 'https' : 'http'
const protocol = env.S3_SSL ?? true ? 'https' : 'http'
const s3 = new S3({
endpoint: new Endpoint(
`${protocol}://${env.S3_ENDPOINT}${env.S3_PORT ? `:${env.S3_PORT}` : ''}`

View File

@@ -104,7 +104,7 @@ const deleteFilesFromBucket = async ({
const minioClient = new Client({
endPoint: env.S3_ENDPOINT,
port: env.S3_PORT,
useSSL: env.S3_SSL,
useSSL: env.S3_SSL ?? true,
accessKey: env.S3_ACCESS_KEY,
secretKey: env.S3_SECRET_KEY,
region: env.S3_REGION,

View File

@@ -1,3 +1,3 @@
export * from './utils'
export * from './storage'
export * from './generatePresignedUrl'
export * from './encryption'

View File

@@ -0,0 +1,36 @@
import { env } from '@typebot.io/env'
import { Client } from 'minio'
type Props = {
fileName: string
file: Buffer
mimeType: string
}
export const uploadFileToBucket = async ({
fileName,
file,
mimeType,
}: Props): Promise<string> => {
if (!env.S3_ENDPOINT || !env.S3_ACCESS_KEY || !env.S3_SECRET_KEY)
throw new Error(
'S3 not properly configured. Missing one of those variables: S3_ENDPOINT, S3_ACCESS_KEY, S3_SECRET_KEY'
)
const minioClient = new Client({
endPoint: env.S3_ENDPOINT,
port: env.S3_PORT,
useSSL: env.S3_SSL,
accessKey: env.S3_ACCESS_KEY,
secretKey: env.S3_SECRET_KEY,
region: env.S3_REGION,
})
await minioClient.putObject(env.S3_BUCKET, fileName, file, {
'Content-Type': mimeType,
})
return `http${env.S3_SSL ? 's' : ''}://${env.S3_ENDPOINT}${
env.S3_PORT ? `:${env.S3_PORT}` : ''
}/${env.S3_BUCKET}/${fileName}`
}