2024-03-21 10:23:23 +01:00
|
|
|
import ky from 'ky'
|
2023-08-29 10:01:28 +02:00
|
|
|
import {
|
|
|
|
WhatsAppCredentials,
|
|
|
|
WhatsAppSendingMessage,
|
|
|
|
} from '@typebot.io/schemas/features/whatsapp'
|
2024-01-25 07:53:57 -03:00
|
|
|
import { env } from '@typebot.io/env'
|
2023-08-29 10:01:28 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
to: string
|
|
|
|
message: WhatsAppSendingMessage
|
|
|
|
credentials: WhatsAppCredentials['data']
|
|
|
|
}
|
|
|
|
|
|
|
|
export const sendWhatsAppMessage = async ({
|
|
|
|
to,
|
|
|
|
message,
|
|
|
|
credentials,
|
|
|
|
}: Props) =>
|
2024-03-21 10:23:23 +01:00
|
|
|
ky.post(
|
|
|
|
`${env.WHATSAPP_CLOUD_API_URL}/v17.0/${credentials.phoneNumberId}/messages`,
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
Authorization: `Bearer ${credentials.systemUserAccessToken}`,
|
|
|
|
},
|
|
|
|
json: {
|
|
|
|
messaging_product: 'whatsapp',
|
|
|
|
to,
|
|
|
|
...message,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|