2
0

📝 Add appropriate docs for new @typebot.io libs

This commit is contained in:
Baptiste Arnaud
2023-02-21 16:22:25 +01:00
parent 9b6fe6cd93
commit a4e3f4bf9c
6 changed files with 500 additions and 18 deletions

View File

@ -24,7 +24,13 @@ export const BubbleSettings = ({
const updatePreviewMessage = ( const updatePreviewMessage = (
previewMessage: BubbleProps['previewMessage'] previewMessage: BubbleProps['previewMessage']
) => { ) => {
onPreviewMessageChange(previewMessage) if (!previewMessage) return onPreviewMessageChange(undefined)
onPreviewMessageChange({
...previewMessage,
autoShowDelay: previewMessage?.autoShowDelay
? previewMessage.autoShowDelay * 1000
: undefined,
})
} }
const updateTheme = (theme: BubbleProps['theme']) => { const updateTheme = (theme: BubbleProps['theme']) => {

View File

@ -11,13 +11,15 @@ You can get the standard HTML and Javascript code by clicking on the "HTML & Jav
There, you can change the container dimensions. Here is a code example: There, you can change the container dimensions. Here is a code example:
```html ```html
<script src="https://unpkg.com/typebot-js@2.2"></script> <script type="module">
<typebot-standard style="width: 100%; height: 600px;"></typebot-standard> import Typebot from 'https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0.9/dist/web.js'
<script>
Typebot.initStandard({ Typebot.initStandard({
typebot: 'my-typebot', typebot: 'my-typebot',
}) })
</script> </script>
<typebot-standard style="width: 100%; height: 600px; "></typebot-standard>
``` ```
This code is creating a container with a 100% width (will match parent width) and 600px height. This code is creating a container with a 100% width (will match parent width) and 600px height.
@ -29,11 +31,13 @@ You can get the popup HTML and Javascript code by clicking on the "HTML & Javasc
Here is an example: Here is an example:
```html ```html
<script src="https://unpkg.com/typebot-js@2.2"></script> <script type="module">
<script> import Typebot from 'https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0.9/dist/web.js'
Typebot.initPopup({ Typebot.initPopup({
typebot: 'my-typebot', typebot: 'my-typebot',
autoShowDelay: 2000, apiHost: 'http://localhost:3001',
autoShowDelay: 3000,
}) })
</script> </script>
``` ```
@ -69,32 +73,37 @@ You can get the bubble HTML and Javascript code by clicking on the "HTML & Javas
Here is an example: Here is an example:
```html ```html
<script src="https://unpkg.com/typebot-js@2.2"></script> <script type="module">
<script> import Typebot from 'https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0.9/dist/web.js'
Typebot.initBubble({ Typebot.initBubble({
typebot: 'my-typebot', typebot: 'my-typebot',
previewMessage: {
message: 'I have a question for you!',
autoShowDelay: 5000,
avatarUrl: 'https://avatars.githubusercontent.com/u/16015833?v=4',
},
theme: {
button: { backgroundColor: '#0042DA', iconColor: '#FFFFFF' },
previewMessage: { backgroundColor: '#ffffff', textColor: 'black' },
chatWindow: { backgroundColor: '#ffffff' },
},
}) })
</script> </script>
``` ```
This code will automatically trigger the popup window after 3 seconds. This code will show the bubble and let a preview message appear after 5 seconds.
### Open or close the preview message ### Open or close the preview message
You can use these commands: You can use these commands:
```js ```js
Typebot.showMessage() Typebot.showPreviewMessage()
``` ```
```js ```js
Typebot.hideMessage() Typebot.hidePreviewMessage()
```
You can bind this command on a button element, for example:
```html
<button onclick="Typebot.showMessage()">Open message</button>
``` ```
### Open or close the typebot ### Open or close the typebot

View File

@ -0,0 +1,152 @@
---
sidebar_position: 5
---
# React
## Install
Make sure you install both `@typebot.io/js` and `@typebot.io/react` first.
```bash
npm install @typebot.io/js @typebot.io/react
```
## Standard
```tsx
import { Standard } from '@typebot.io/react'
const App = () => {
return (
<Standard
typebot="lead-generation-copy-3luzm6b"
style={{ width: '100%', height: '600px' }}
/>
)
}
```
This code is creating a container with a 100% width (will match parent width) and 600px height.
## Popup
```tsx
import { Popup } from '@typebot.io/react'
const App = () => {
return <Popup typebot="lead-generation-copy-3luzm6b" autoShowDelay={3000} />
}
```
This code will automatically trigger the popup window after 3 seconds.
### Open or Close a popup
You can use these commands:
```js
import { open } from '@typebot.io/react'
open()
```
```js
import { close } from '@typebot.io/react'
close()
```
```js
import { toggle } from '@typebot.io/react'
toggle()
```
## Bubble
```tsx
import { Bubble } from '@typebot.io/react'
const App = () => {
return (
<Bubble
typebot="lead-generation-copy-3luzm6b"
previewMessage={{
message: 'I have a question for you!',
autoShowDelay: 5000,
avatarUrl: 'https://avatars.githubusercontent.com/u/16015833?v=4',
}}
theme={{
button: { backgroundColor: '#0042DA', iconColor: '#FFFFFF' },
previewMessage: { backgroundColor: '#ffffff', textColor: 'black' },
}}
/>
)
}
```
This code will show the bubble and let a preview message appear after 5 seconds.
### Open or close the preview message
You can use these commands:
```js
import { showPreviewMessage } from '@typebot.io/react'
Typebot.showPreviewMessage()
```
```js
import { hidePreviewMessage } from '@typebot.io/react'
Typebot.hidePreviewMessage()
```
### Open or close the chat window
You can use these commands:
```js
import { open } from '@typebot.io/react'
open()
```
```js
import { close } from '@typebot.io/react'
close()
```
```js
import { toggle } from '@typebot.io/react'
toggle()
```
## Additional configuration
You can prefill the bot variable values in your embed code by adding the `prefilledVariables` option. Here is an example:
```tsx
import { Standard } from '@typebot.io/react'
const App = () => {
return (
<Standard
typebot="lead-generation-copy-3luzm6b"
style={{ width: '100%', height: '600px' }}
prefilledVariables={{
'Current URL': 'https://my-site/account',
'User name': 'John Doe',
}}
/>
)
}
```
It will prefill the `Current URL` variable with "https://my-site/account" and the `User name` variable with "John Doe". More info about variables: [here](/editor/variables).
Note that if your site URL contains query params (i.e. https://typebot.io?User%20name=John%20Doe), the variables will automatically be injected to the typebot. So you don't need to manually transfer query params to the bot embed configuration.

169
packages/js/README.md Normal file
View File

@ -0,0 +1,169 @@
# Typebot JS library
Frontend library to embed typebots from [Typebot](https://www.typebot.io/).
## Installation
### Using npm
To install, simply run:
```bash
npm install @typebot.io/js
```
### Directly in your HTML
```
<script type="module">
import Typebot from 'https://cdn.jsdelivr.net/npm/@typebot.io/js/dist/web.js'
Typebot.initStandard({
typebot: 'my-typebot',
})
</script>
<typebot-standard style="width: 100%; height: 600px; "></typebot-standard>
```
## Standard
You can get the standard HTML and Javascript code by clicking on the "HTML & Javascript" button in the "Share" tab of your typebot.
There, you can change the container dimensions. Here is a code example:
```html
<script type="module">
import Typebot from 'https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0.9/dist/web.js'
Typebot.initStandard({
typebot: 'my-typebot',
})
</script>
<typebot-standard style="width: 100%; height: 600px; "></typebot-standard>
```
This code is creating a container with a 100% width (will match parent width) and 600px height.
## Popup
You can get the popup HTML and Javascript code by clicking on the "HTML & Javascript" button in the "Share" tab of your typebot.
Here is an example:
```html
<script type="module">
import Typebot from 'https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0.9/dist/web.js'
Typebot.initPopup({
typebot: 'my-typebot',
apiHost: 'http://localhost:3001',
autoShowDelay: 3000,
})
</script>
```
This code will automatically trigger the popup window after 3 seconds.
### Open or Close a popup
You can use these commands:
```js
Typebot.open()
```
```js
Typebot.close()
```
```js
Typebot.toggle()
```
You can bind these commands on a button element, for example:
```html
<button onclick="Typebot.open()">Contact us</button>
```
## Bubble
You can get the bubble HTML and Javascript code by clicking on the "HTML & Javascript" button in the "Share" tab of your typebot.
Here is an example:
```html
<script type="module">
import Typebot from 'https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0.9/dist/web.js'
Typebot.initBubble({
typebot: 'my-typebot',
previewMessage: {
message: 'I have a question for you!',
autoShowDelay: 5000,
avatarUrl: 'https://avatars.githubusercontent.com/u/16015833?v=4',
},
theme: {
button: { backgroundColor: '#0042DA', iconColor: '#FFFFFF' },
previewMessage: { backgroundColor: '#ffffff', textColor: 'black' },
chatWindow: { backgroundColor: '#ffffff' },
},
})
</script>
```
This code will show the bubble and let a preview message appear after 5 seconds.
### Open or close the preview message
You can use these commands:
```js
Typebot.showPreviewMessage()
```
```js
Typebot.hidePreviewMessage()
```
### Open or close the typebot
You can use these commands:
```js
Typebot.open()
```
```js
Typebot.close()
```
```js
Typebot.toggle()
```
You can bind these commands on a button element, for example:
```html
<button onclick="Typebot.open()">Contact us</button>
```
## Additional configuration
You can prefill the bot variable values in your embed code by adding the `prefilledVariables` option. Here is an example:
```js
Typebot.initStandard({
typebot: 'my-typebot',
prefilledVariables: {
'Current URL': 'https://my-site/account',
'User name': 'John Doe',
},
})
```
It will prefill the `Current URL` variable with "https://my-site/account" and the `User name` variable with "John Doe". More info about variables: [here](/editor/variables).
Note that if your site URL contains query params (i.e. https://typebot.io?User%20name=John%20Doe), the variables will automatically be injected to the typebot. So you don't need to manually transfer query params to the bot embed configuration.

144
packages/react/README.md Normal file
View File

@ -0,0 +1,144 @@
## Install
```bash
npm install @typebot.io/js @typebot.io/react
```
## Standard
```tsx
import { Standard } from '@typebot.io/react'
const App = () => {
return (
<Standard
typebot="lead-generation-copy-3luzm6b"
style={{ width: '100%', height: '600px' }}
/>
)
}
```
This code is creating a container with a 100% width (will match parent width) and 600px height.
## Popup
```tsx
import { Popup } from '@typebot.io/react'
const App = () => {
return <Popup typebot="lead-generation-copy-3luzm6b" autoShowDelay={3000} />
}
```
This code will automatically trigger the popup window after 3 seconds.
### Open or Close a popup
You can use these commands:
```js
import { open } from '@typebot.io/react'
open()
```
```js
import { close } from '@typebot.io/react'
close()
```
```js
import { toggle } from '@typebot.io/react'
toggle()
```
## Bubble
```tsx
import { Bubble } from '@typebot.io/react'
const App = () => {
return (
<Bubble
typebot="lead-generation-copy-3luzm6b"
previewMessage={{
message: 'I have a question for you!',
autoShowDelay: 5000,
avatarUrl: 'https://avatars.githubusercontent.com/u/16015833?v=4',
}}
theme={{
button: { backgroundColor: '#0042DA', iconColor: '#FFFFFF' },
previewMessage: { backgroundColor: '#ffffff', textColor: 'black' },
}}
/>
)
}
```
This code will show the bubble and let a preview message appear after 5 seconds.
### Open or close the preview message
You can use these commands:
```js
import { showPreviewMessage } from '@typebot.io/react'
Typebot.showPreviewMessage()
```
```js
import { hidePreviewMessage } from '@typebot.io/react'
Typebot.hidePreviewMessage()
```
### Open or close the chat window
You can use these commands:
```js
import { open } from '@typebot.io/react'
open()
```
```js
import { close } from '@typebot.io/react'
close()
```
```js
import { toggle } from '@typebot.io/react'
toggle()
```
## Additional configuration
You can prefill the bot variable values in your embed code by adding the `prefilledVariables` option. Here is an example:
```tsx
import { Standard } from '@typebot.io/react'
const App = () => {
return (
<Standard
typebot="lead-generation-copy-3luzm6b"
style={{ width: '100%', height: '600px' }}
prefilledVariables={{
'Current URL': 'https://my-site/account',
'User name': 'John Doe',
}}
/>
)
}
```
It will prefill the `Current URL` variable with "https://my-site/account" and the `User name` variable with "John Doe". More info about variables: [here](/editor/variables).
Note that if your site URL contains query params (i.e. https://typebot.io?User%20name=John%20Doe), the variables will automatically be injected to the typebot. So you don't need to manually transfer query params to the bot embed configuration.

View File

@ -1,3 +1,5 @@
> ⚠️ This library is deprecated in favor of [`@typebot.io/js`](https://www.npmjs.com/package/@typebot.io/js) and [`@typebot.io/react`](https://www.npmjs.com/package/@typebot.io/react)
# Typebot JS library # Typebot JS library
Frontend library to embed typebots from [Typebot](https://www.typebot.io/). Frontend library to embed typebots from [Typebot](https://www.typebot.io/).