From 56078b4e0215b2d6313a9d2b3b89ae4936cac7f7 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Fri, 7 Jul 2023 14:35:17 +0200 Subject: [PATCH] :bug: (share) Enable back empty public ID for self-hosted version Closes #576 --- apps/viewer/src/components/TypebotPageV3.tsx | 18 ++++++++---------- .../src/features/chat/api/sendMessage.ts | 4 ++-- apps/viewer/src/pages/[[...publicId]].tsx | 9 ++++++++- packages/embeds/js/package.json | 2 +- packages/embeds/js/src/components/Bot.tsx | 4 ++-- .../bubbles/audio/components/AudioBubble.tsx | 9 ++++++++- .../js/src/queries/getInitialChatReplyQuery.ts | 4 ++-- packages/embeds/react/package.json | 2 +- 8 files changed, 32 insertions(+), 20 deletions(-) diff --git a/apps/viewer/src/components/TypebotPageV3.tsx b/apps/viewer/src/components/TypebotPageV3.tsx index 4e54c238f..1af33aca8 100644 --- a/apps/viewer/src/components/TypebotPageV3.tsx +++ b/apps/viewer/src/components/TypebotPageV3.tsx @@ -5,11 +5,11 @@ import { SEO } from './Seo' export type TypebotPageProps = { url: string - typebot?: Pick + typebot: Pick } export const TypebotPageV3 = ({ url, typebot }: TypebotPageProps) => { - const { asPath, push, query } = useRouter() + const { asPath, push } = useRouter() const background = typebot?.theme.general.background @@ -36,15 +36,13 @@ export const TypebotPageV3 = ({ url, typebot }: TypebotPageProps) => { : '#fff', }} > - {typebot && ( - - )} + diff --git a/apps/viewer/src/features/chat/api/sendMessage.ts b/apps/viewer/src/features/chat/api/sendMessage.ts index d16407ad8..079fa994f 100644 --- a/apps/viewer/src/features/chat/api/sendMessage.ts +++ b/apps/viewer/src/features/chat/api/sendMessage.ts @@ -125,10 +125,10 @@ export const sendMessage = publicProcedure ) const startSession = async (startParams?: StartParams, userId?: string) => { - if (!startParams?.typebot) + if (!startParams) throw new TRPCError({ code: 'BAD_REQUEST', - message: 'No typebot provided in startParams', + message: 'StartParams are missing', }) const typebot = await getTypebot(startParams, userId) diff --git a/apps/viewer/src/pages/[[...publicId]].tsx b/apps/viewer/src/pages/[[...publicId]].tsx index be1fefd46..bb46f7afe 100644 --- a/apps/viewer/src/pages/[[...publicId]].tsx +++ b/apps/viewer/src/pages/[[...publicId]].tsx @@ -94,7 +94,14 @@ const getTypebotFromPublicId = async ( const publishedTypebot = await prisma.publicTypebot.findFirst({ where: { typebot: { publicId: publicId ?? '' } }, include: { - typebot: { select: { name: true, isClosed: true, isArchived: true } }, + typebot: { + select: { + name: true, + isClosed: true, + isArchived: true, + publicId: true, + }, + }, }, }) if (isNotDefined(publishedTypebot)) return null diff --git a/packages/embeds/js/package.json b/packages/embeds/js/package.json index 963876bf1..2f6806283 100644 --- a/packages/embeds/js/package.json +++ b/packages/embeds/js/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/js", - "version": "0.0.67", + "version": "0.0.68", "description": "Javascript library to display typebots on your website", "type": "module", "main": "dist/index.js", diff --git a/packages/embeds/js/src/components/Bot.tsx b/packages/embeds/js/src/components/Bot.tsx index 71293dc65..49dbf3b08 100644 --- a/packages/embeds/js/src/components/Bot.tsx +++ b/packages/embeds/js/src/components/Bot.tsx @@ -1,6 +1,6 @@ import { LiteBadge } from './LiteBadge' import { createEffect, createSignal, onCleanup, onMount, Show } from 'solid-js' -import { isNotEmpty } from '@typebot.io/lib' +import { isNotDefined, isNotEmpty } from '@typebot.io/lib' import { getInitialChatReplyQuery } from '@/queries/getInitialChatReplyQuery' import { ConversationContainer } from './ConversationContainer' import { setIsMobile } from '@/utils/isMobileSignal' @@ -92,7 +92,7 @@ export const Bot = (props: BotProps & { class?: string }) => { } createEffect(() => { - if (!props.typebot || isInitialized()) return + if (isNotDefined(props.typebot) || isInitialized()) return initializeBot().then() }) diff --git a/packages/embeds/js/src/features/blocks/bubbles/audio/components/AudioBubble.tsx b/packages/embeds/js/src/features/blocks/bubbles/audio/components/AudioBubble.tsx index ac21b0f9e..f798fbb87 100644 --- a/packages/embeds/js/src/features/blocks/bubbles/audio/components/AudioBubble.tsx +++ b/packages/embeds/js/src/features/blocks/bubbles/audio/components/AudioBubble.tsx @@ -20,6 +20,14 @@ export const AudioBubble = (props: Props) => { typingTimeout = setTimeout(() => { setIsTyping(false) setTimeout(() => { + const audioElement = ref?.querySelector('audio') + if (audioElement) { + try { + audioElement.play() + } catch (e) { + console.warn('Could not autoplay the audio:', e) + } + } props.onTransitionEnd(ref?.offsetTop) }, showAnimationDuration) }, typingDuration) @@ -49,7 +57,6 @@ export const AudioBubble = (props: Props) => { (isTyping() ? 'opacity-0' : 'opacity-100') } style={{ height: isTyping() ? '32px' : 'revert' }} - autoplay controls /> diff --git a/packages/embeds/js/src/queries/getInitialChatReplyQuery.ts b/packages/embeds/js/src/queries/getInitialChatReplyQuery.ts index 2edab12e0..14b856de2 100644 --- a/packages/embeds/js/src/queries/getInitialChatReplyQuery.ts +++ b/packages/embeds/js/src/queries/getInitialChatReplyQuery.ts @@ -1,7 +1,7 @@ import { InitialChatReply } from '@/types' import { guessApiHost } from '@/utils/guessApiHost' import type { SendMessageInput, StartParams } from '@typebot.io/schemas' -import { isNotEmpty, sendRequest } from '@typebot.io/lib' +import { isNotDefined, isNotEmpty, sendRequest } from '@typebot.io/lib' export async function getInitialChatReplyQuery({ typebot, @@ -13,7 +13,7 @@ export async function getInitialChatReplyQuery({ }: StartParams & { apiHost?: string }) { - if (!typebot) + if (isNotDefined(typebot)) throw new Error('Typebot ID is required to get initial messages') return sendRequest({ diff --git a/packages/embeds/react/package.json b/packages/embeds/react/package.json index 0790d2fc9..450650743 100644 --- a/packages/embeds/react/package.json +++ b/packages/embeds/react/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/react", - "version": "0.0.67", + "version": "0.0.68", "description": "React library to display typebots on your website", "main": "dist/index.js", "types": "dist/index.d.ts",