2
0

docs: 📝 Add Code block

This commit is contained in:
Baptiste Arnaud
2022-05-17 13:48:56 -07:00
parent 0de0d128b3
commit fbcd46dd9c
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
# Code
The "Code" block allows you to execute Javascript code. If you want to set a variable value with Javascript, use the [Set variable block](./set-variable) instead.
**It doesn't allow you to create custom visual block**
<img src="/img/blocks/code.png" width="600" alt="Code block"/>
## Examples
### Reload page
```js
window.location.reload()
```
### Wait for 3 seconds
By default, Promises will be awaited. So something like this will work:
```js
return new Promise((res) => setTimeout(res, 3000))
```
### Post a message to parent
```js
postMessage('hello there!', '*')
```
Then on your parent website you could listen for those messages:
```js
addEventListener('message', ({ data }) => console.log(data))
```
Do you need to do something but you're not sure how to? [Ask the community for help!](https://www.facebook.com/groups/typebot)

BIN
apps/docs/static/img/blocks/code.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB