📝 Add env WHATSAPP_CLOUD_API_URL to possible change https://gr… (#1170)
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>
This commit is contained in:
committed by
Baptiste Arnaud
parent
ef05b71869
commit
47af9a9a59
@@ -5,6 +5,7 @@ import prisma from '@typebot.io/lib/prisma'
|
||||
import { decrypt } from '@typebot.io/lib/api/encryption/decrypt'
|
||||
import { TRPCError } from '@trpc/server'
|
||||
import { WhatsAppCredentials } from '@typebot.io/schemas/features/whatsapp'
|
||||
import { env } from '@typebot.io/env'
|
||||
|
||||
const inputSchema = z.object({
|
||||
credentialsId: z.string().optional(),
|
||||
@@ -22,7 +23,7 @@ export const getPhoneNumber = authenticatedProcedure
|
||||
message: 'Credentials not found',
|
||||
})
|
||||
const { display_phone_number } = (await got(
|
||||
`https://graph.facebook.com/v17.0/${credentials.phoneNumberId}`,
|
||||
`${env.WHATSAPP_CLOUD_API_URL}/v17.0/${credentials.phoneNumberId}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${credentials.systemUserAccessToken}`,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { TRPCError } from '@trpc/server'
|
||||
import { WhatsAppCredentials } from '@typebot.io/schemas/features/whatsapp'
|
||||
import prisma from '@typebot.io/lib/prisma'
|
||||
import { decrypt } from '@typebot.io/lib/api/encryption/decrypt'
|
||||
import { env } from '@typebot.io/env'
|
||||
|
||||
const inputSchema = z.object({
|
||||
token: z.string().optional(),
|
||||
@@ -28,7 +29,7 @@ export const getSystemTokenInfo = authenticatedProcedure
|
||||
const {
|
||||
data: { expires_at, scopes, app_id, application },
|
||||
} = (await got(
|
||||
`https://graph.facebook.com/v17.0/debug_token?input_token=${credentials.systemUserAccessToken}`,
|
||||
`${env.WHATSAPP_CLOUD_API_URL}/v17.0/debug_token?input_token=${credentials.systemUserAccessToken}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${credentials.systemUserAccessToken}`,
|
||||
|
||||
@@ -10,6 +10,7 @@ import { isReadWorkspaceFobidden } from '@/features/workspace/helpers/isReadWork
|
||||
import { WhatsAppCredentials } from '@typebot.io/schemas/features/whatsapp'
|
||||
import got from 'got'
|
||||
import { decrypt } from '@typebot.io/lib/api/encryption/decrypt'
|
||||
import { env } from '@typebot.io/env'
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
if (req.method === 'GET') {
|
||||
@@ -61,7 +62,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
)) as WhatsAppCredentials['data']
|
||||
|
||||
const { body } = await got.get({
|
||||
url: `https://graph.facebook.com/v17.0/${mediaId}`,
|
||||
url: `${env.WHATSAPP_CLOUD_API_URL}/v17.0/${mediaId}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${credentialsData.systemUserAccessToken}`,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user