refs #1117 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Dynamically construct API URLs for WhatsApp features using environment variables for improved reliability and configurability. - Updated `sendWhatsAppMessage` function to use `env.WHATSAPP_CLOUD_API_URL` for URL construction, allowing for more dynamic configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Baptiste Arnaud <baptiste.arnaud95@gmail.com>
30 lines
641 B
TypeScript
30 lines
641 B
TypeScript
import got from 'got'
|
|
import {
|
|
WhatsAppCredentials,
|
|
WhatsAppSendingMessage,
|
|
} from '@typebot.io/schemas/features/whatsapp'
|
|
import { env } from '@typebot.io/env'
|
|
|
|
type Props = {
|
|
to: string
|
|
message: WhatsAppSendingMessage
|
|
credentials: WhatsAppCredentials['data']
|
|
}
|
|
|
|
export const sendWhatsAppMessage = async ({
|
|
to,
|
|
message,
|
|
credentials,
|
|
}: Props) =>
|
|
got.post({
|
|
url: `${env.WHATSAPP_CLOUD_API_URL}/v17.0/${credentials.phoneNumberId}/messages`,
|
|
headers: {
|
|
Authorization: `Bearer ${credentials.systemUserAccessToken}`,
|
|
},
|
|
json: {
|
|
messaging_product: 'whatsapp',
|
|
to,
|
|
...message,
|
|
},
|
|
})
|