@ -1,5 +1,5 @@
|
||||
import { env } from '@typebot.io/env'
|
||||
import got from 'got'
|
||||
import ky from 'ky'
|
||||
|
||||
type Props = {
|
||||
mediaId: string
|
||||
@ -10,21 +10,24 @@ 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, {
|
||||
const { url, mime_type } = await ky
|
||||
.get(`${env.WHATSAPP_CLOUD_API_URL}/v17.0/${mediaId}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${systemUserAccessToken}`,
|
||||
},
|
||||
}).buffer(),
|
||||
mimeType: parsedBody.mime_type,
|
||||
})
|
||||
.json<{ url: string; mime_type: string }>()
|
||||
|
||||
return {
|
||||
file: Buffer.from(
|
||||
await ky
|
||||
.get(url, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${systemUserAccessToken}`,
|
||||
},
|
||||
})
|
||||
.arrayBuffer()
|
||||
),
|
||||
mimeType: mime_type,
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
import { convertMessageToWhatsAppMessage } from './convertMessageToWhatsAppMessage'
|
||||
import { sendWhatsAppMessage } from './sendWhatsAppMessage'
|
||||
import * as Sentry from '@sentry/nextjs'
|
||||
import { HTTPError } from 'got'
|
||||
import { HTTPError } from 'ky'
|
||||
import { convertInputToWhatsAppMessages } from './convertInputToWhatsAppMessage'
|
||||
import { isNotDefined } from '@typebot.io/lib/utils'
|
||||
import { computeTypingDuration } from '../computeTypingDuration'
|
||||
@ -141,7 +141,7 @@ export const sendChatReplyToWhatsApp = async ({
|
||||
Sentry.captureException(err, { extra: { message } })
|
||||
console.log('Failed to send message:', JSON.stringify(message, null, 2))
|
||||
if (err instanceof HTTPError)
|
||||
console.log('HTTPError', err.response.statusCode, err.response.body)
|
||||
console.log('HTTPError', err.response.status, await err.response.text())
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,7 +172,11 @@ export const sendChatReplyToWhatsApp = async ({
|
||||
Sentry.captureException(err, { extra: { message } })
|
||||
console.log('Failed to send message:', JSON.stringify(message, null, 2))
|
||||
if (err instanceof HTTPError)
|
||||
console.log('HTTPError', err.response.statusCode, err.response.body)
|
||||
console.log(
|
||||
'HTTPError',
|
||||
err.response.status,
|
||||
await err.response.text()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -253,7 +257,11 @@ const executeClientSideAction =
|
||||
Sentry.captureException(err, { extra: { message } })
|
||||
console.log('Failed to send message:', JSON.stringify(message, null, 2))
|
||||
if (err instanceof HTTPError)
|
||||
console.log('HTTPError', err.response.statusCode, err.response.body)
|
||||
console.log(
|
||||
'HTTPError',
|
||||
err.response.status,
|
||||
await err.response.text()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import {
|
||||
WhatsAppSendingMessage,
|
||||
} from '@typebot.io/schemas/features/whatsapp'
|
||||
import { env } from '@typebot.io/env'
|
||||
import got from 'got'
|
||||
import ky from 'ky'
|
||||
|
||||
type Props = {
|
||||
to: string
|
||||
@ -16,7 +16,7 @@ export const sendWhatsAppMessage = async ({
|
||||
message,
|
||||
credentials,
|
||||
}: Props) =>
|
||||
got.post(
|
||||
ky.post(
|
||||
`${env.WHATSAPP_CLOUD_API_URL}/v17.0/${credentials.phoneNumberId}/messages`,
|
||||
{
|
||||
headers: {
|
||||
|
Reference in New Issue
Block a user