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

@@ -14,6 +14,7 @@ export const processTelemetryEvent = authenticatedProcedure
path: '/t/process',
description:
"Only used for the cloud version of Typebot. It's the way it processes telemetry events and inject it to thrid-party services.",
tags: ['Telemetry'],
},
})
.input(
@@ -26,19 +27,19 @@ export const processTelemetryEvent = authenticatedProcedure
message: z.literal('Events injected'),
})
)
.query(async ({ input: { events }, ctx: { user } }) => {
.mutation(async ({ input: { events }, ctx: { user } }) => {
if (user.email !== env.ADMIN_EMAIL)
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'Only app admin can process telemetry events',
})
if (!env.POSTHOG_API_KEY)
if (!env.NEXT_PUBLIC_POSTHOG_KEY)
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'Server does not have POSTHOG_API_KEY configured',
})
const client = new PostHog(env.POSTHOG_API_KEY, {
host: 'https://eu.posthog.com',
const client = new PostHog(env.NEXT_PUBLIC_POSTHOG_KEY, {
host: env.NEXT_PUBLIC_POSTHOG_HOST,
})
events.forEach(async (event) => {

View File

@@ -0,0 +1,34 @@
import { env } from '@typebot.io/env'
import posthog from 'posthog-js'
export const initPostHogIfEnabled = () => {
if (typeof window === 'undefined') return
const posthogKey = env.NEXT_PUBLIC_POSTHOG_KEY
if (!posthogKey) return
posthog.init(posthogKey, {
api_host: env.NEXT_PUBLIC_POSTHOG_HOST,
loaded: (posthog) => {
if (process.env.NODE_ENV === 'development') posthog.debug()
},
capture_pageview: false,
capture_pageleave: false,
autocapture: false,
})
}
export const identifyUser = (userId: string) => {
if (!posthog.__loaded) return
posthog.identify(userId)
}
export const getFeatureFlags = () => {
return posthog.__loaded &&
posthog.isFeatureEnabled('whatsApp', { send_event: false })
? ['whatsApp']
: []
}
export { posthog }