2
0
Files
bot/packages/bot-engine/whatsapp/sendWhatsAppMessage.ts
Baptiste Arnaud d96f384e02 ♻️ Migrate from got to ky (#1416)
Closes #1415
2024-04-05 09:01:16 +02:00

32 lines
659 B
TypeScript

import {
WhatsAppCredentials,
WhatsAppSendingMessage,
} from '@typebot.io/schemas/features/whatsapp'
import { env } from '@typebot.io/env'
import ky from 'ky'
type Props = {
to: string
message: WhatsAppSendingMessage
credentials: WhatsAppCredentials['data']
}
export const sendWhatsAppMessage = async ({
to,
message,
credentials,
}: Props) =>
ky.post(
`${env.WHATSAPP_CLOUD_API_URL}/v17.0/${credentials.phoneNumberId}/messages`,
{
headers: {
Authorization: `Bearer ${credentials.systemUserAccessToken}`,
},
json: {
messaging_product: 'whatsapp',
to,
...message,
},
}
)