Add WhatsApp integration beta test (#722)

Related to #401
This commit is contained in:
Baptiste Arnaud
2023-08-29 10:01:28 +02:00
parent 036b407a11
commit b852b4af0b
136 changed files with 6694 additions and 5383 deletions

View File

@@ -0,0 +1,29 @@
import { publicProcedure } from '@/helpers/server/trpc'
import { TRPCError } from '@trpc/server'
import { env } from '@typebot.io/env'
import { z } from 'zod'
export const subscribePreviewWebhook = publicProcedure
.meta({
openapi: {
method: 'GET',
path: '/whatsapp/preview/webhook',
summary: 'WhatsApp',
},
})
.input(
z.object({
'hub.challenge': z.string(),
'hub.verify_token': z.string(),
})
)
.output(z.number())
.query(
async ({
input: { 'hub.challenge': challenge, 'hub.verify_token': token },
}) => {
if (token !== env.ENCRYPTION_SECRET)
throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Unauthorized' })
return Number(challenge)
}
)