-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from brevia-ai/feat/209-pagina-embeddings-chatbot
Add Share page to chatbot Settings
- Loading branch information
Showing
4 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<template> | ||
<component :is="'link'" v-if="shouldPreloadIframe" rel="preload" :href="iframeSrc" as="fetch" /> | ||
<div class="flex flex-col space-y-6"> | ||
<h1 class="text-2xl font-semibold mb-4 border-b-primary border-b-2">Embed</h1> | ||
|
||
<template v-if="!chatbotIframeEnabled"> | ||
<p class="text-lg"><Icon name="ph:warning-circle-bold" class="text-2xl text-pink-700" /> {{ $t('CHATBOT_IFRAME_DISABLED') }}</p> | ||
<button class="mx-auto px-5 py-1.5 button rounded-lg" @click="enableChatbotIframe"> | ||
<Icon name="ph:check-square-fill" /> | ||
<span>{{ $t('ENABLE') }}</span> | ||
</button> | ||
</template> | ||
|
||
<p class="text-lg">{{ $t('ADD_CHATBOT_IFRAME') }}:</p> | ||
<code ref="codeArea" class="w-full flex-1 bg-slate-300 p-2 rounded-md"> | ||
<iframe<br /> | ||
  src="{{ protocol }}//{{ host }}/chatbot-iframe/{{ uuid }}"<br /> | ||
  style="height: 30rem; width: 24rem" <br /> | ||
><br /> | ||
</iframe> | ||
</code> | ||
<button class="mx-auto px-5 py-1.5 button rounded-lg" @click="copyCode"> | ||
<Icon :name="!copiedToClip ? 'ph:copy-bold' : 'ph:copy-simple-fill'" /> | ||
<span v-if="!copiedToClip">{{ $t('COPY') }}</span> | ||
<span v-else>{{ $t('COPY') }}!</span> | ||
</button> | ||
<template v-if="chatbotIframeEnabled"> | ||
<p v-if="chatbotIframeEnabled" class="text-lg">{{ $t('BUBBLE_TRY_CHATBOT') }}</p> | ||
<div class="absolute bottom-12 right-6 flex flex-col space-y-6"> | ||
<Transition name="iframe" appear> | ||
<div v-if="iframeVisible" class="shadow-md border-0.5 border-slate-700 rounded-md bg-white z-50"> | ||
<h1 class="pl-6 py-0.5 shadow-sm text-xl font-bold">{{ name }}</h1> | ||
<iframe class="h-[30rem] w-96 rounded-md center" :src="iframeSrc" sandbox="allow-same-origin allow-scripts allow-forms"> </iframe> | ||
</div> | ||
</Transition> | ||
<div class="flex flex-row self-end"> | ||
<button | ||
class="bg-primary text-white rounded-full transform hover:scale-110 transition duration-300 hover:opacity-95" | ||
@click="iframeVisible = !iframeVisible" | ||
> | ||
<Icon :name="!iframeVisible ? 'ph:chat-circle-text-bold' : 'ph:arrow-down-bold'" class="text-3xl m-4" /> | ||
</button> | ||
</div> | ||
</div> | ||
</template> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const props = defineProps({ | ||
uuid: { type: String, default: '' }, | ||
name: { type: String, default: '' }, | ||
}); | ||
const host = window.location.host; | ||
const protocol = window.location.protocol; | ||
const iframeSrc = ref('/chatbot-iframe/' + props.uuid); | ||
const iframeVisible = ref(false); | ||
const shouldPreloadIframe = ref(true); | ||
const codeArea = ref(); | ||
const copiedToClip = ref(false); | ||
const statesStore = useStatesStore(); | ||
const collection = statesStore.collection as any; | ||
const chatbotIframeEnabled = computed(() => !!collection.cmetadata?.brevia_app?.public_iframe); | ||
onMounted(() => { | ||
setTimeout(() => { | ||
shouldPreloadIframe.value = false; | ||
}, 5000); | ||
}); | ||
const copyCode = () => { | ||
navigator.clipboard.writeText(codeArea.value.textContent).then(() => { | ||
copiedToClip.value = true; | ||
setTimeout(() => (copiedToClip.value = false), 500); | ||
}); | ||
}; | ||
const enableChatbotIframe = async () => { | ||
const brevia_app = collection.cmetadata.brevia_app || {}; | ||
brevia_app.public_iframe = true; | ||
collection.cmetadata.brevia_app = brevia_app; | ||
const integration = useIntegration(); | ||
await $fetch(`/api/${integration}/collections/${statesStore?.collection?.uuid}`, { | ||
method: 'PATCH', | ||
body: collection, | ||
}); | ||
statesStore.collection = collection; | ||
}; | ||
</script> | ||
|
||
<style> | ||
.iframe-leave { | ||
scale: 100%; | ||
} | ||
.iframe-enter { | ||
scale: 0%; | ||
} | ||
.iframe-leave-to { | ||
scale: 0%; | ||
transform-origin: bottom right; | ||
} | ||
.iframe-enter-to { | ||
scale: 100%; | ||
transform-origin: bottom right; | ||
} | ||
.iframe-leave-active, | ||
.iframe-enter-active { | ||
transition: scale 0.5s ease; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters