Skip to content

Commit

Permalink
✨ (typebot-js) Add setHiddenVariables command
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Dec 31, 2022
1 parent f49a301 commit 99850dd
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/typebot-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typebot-js",
"version": "2.2.14",
"version": "2.2.15",
"main": "dist/index.js",
"unpkg": "dist/index.global.js",
"license": "AGPL-3.0-or-later",
Expand Down
1 change: 1 addition & 0 deletions packages/typebot-js/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './close'
export * from './hideMessage'
export * from './open'
export * from './setHiddenVariables'
export * from './showMessage'
export * from './toggle'
43 changes: 43 additions & 0 deletions packages/typebot-js/src/commands/setHiddenVariables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { IframeParams } from '../types'

export const setHiddenVariables = (
hiddenVariables: IframeParams['hiddenVariables']
) => {
const existingIframe = document.querySelector('.typebot-iframe') as
| HTMLIFrameElement
| undefined
if (!existingIframe) return
const hostUrlParams = new URLSearchParams(document.location.search)
const hostQueryObj: { [key: string]: string } = {}
hostUrlParams.forEach((value, key) => {
hostQueryObj[key] = value
})
const isLoadWhenVisible = existingIframe.hasAttribute('data-src')
const url = (
existingIframe.getAttribute('data-src') || existingIframe.src
).split('?')[0]
const iframeUrl = `${url}${parseQueryParams({
...hiddenVariables,
...hostQueryObj,
})}`
existingIframe.setAttribute(isLoadWhenVisible ? 'data-src' : 'src', iframeUrl)
}

export const parseQueryParams = (starterVariables?: {
[key: string]: string | undefined
}): string => {
return parseStarterVariables(starterVariables)
}

const parseStarterVariables = (starterVariables?: {
[key: string]: string | undefined
}) =>
starterVariables && Object.keys(starterVariables).length > 0
? `?${Object.keys(starterVariables)
.filter((key) => starterVariables[key])
.map(
(key) =>
`${key}=${encodeURIComponent(starterVariables[key] as string)}`
)
.join('&')}`
: ''
20 changes: 1 addition & 19 deletions packages/typebot-js/src/iframe/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { close } from '../commands'
import { parseQueryParams } from '../commands/setHiddenVariables'
import { TypebotPostMessageData, IframeCallbacks, IframeParams } from '../types'
import './style.css'

Expand Down Expand Up @@ -30,25 +31,6 @@ export const createIframe = ({
return iframe
}

const parseQueryParams = (starterVariables?: {
[key: string]: string | undefined
}): string => {
return parseStarterVariables(starterVariables)
}

const parseStarterVariables = (starterVariables?: {
[key: string]: string | undefined
}) =>
starterVariables && Object.keys(starterVariables).length > 0
? `?${Object.keys(starterVariables)
.filter((key) => starterVariables[key])
.map(
(key) =>
`${key}=${encodeURIComponent(starterVariables[key] as string)}`
)
.join('&')}`
: ''

export const listenForTypebotMessages = (callbacks: IframeCallbacks) => {
window.addEventListener('message', (event) => {
const data = event.data as { from?: 'typebot' } & TypebotPostMessageData
Expand Down
11 changes: 10 additions & 1 deletion packages/typebot-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { initContainer } from './embedTypes/container'
import { initPopup, getPopupActions } from './embedTypes/popup'
import { initBubble, getBubbleActions } from './embedTypes/chat'
import { open, close, toggle, showMessage, hideMessage } from './commands'
import {
open,
close,
toggle,
showMessage,
hideMessage,
setHiddenVariables,
} from './commands'

export {
initContainer,
Expand All @@ -14,6 +21,7 @@ export {
toggle,
showMessage,
hideMessage,
setHiddenVariables,
}

const defaultExports = {
Expand All @@ -27,6 +35,7 @@ const defaultExports = {
toggle,
showMessage,
hideMessage,
setHiddenVariables,
}

export default defaultExports
Expand Down

5 comments on commit 99850dd

@vercel
Copy link

@vercel vercel bot commented on 99850dd Dec 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app
docs.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 99850dd Dec 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

bot.joof.it
yoda.riku.ai
bergamo.store
bot.tvbeat.it
app.yvon.earth
bots.bridge.ai
chat.hayuri.id
gollum.riku.ai
talk.gocare.io
bot.jesopizz.it
fitness.riku.ai
bot.contakit.com
zap.fundviser.in
bot.rihabilita.it
viewer.typebot.io
bot.danyservice.it
bot.boston-voip.com
bot.dsignagency.com
chatbot.matthesv.de
demo.wemakebots.xyz
88584434.therpm.club
92109660.therpm.club
bot.barrettamario.it
hello.advergreen.com
bot.coachayongzul.com
bot.digitalpointer.id
bot.eikju.photography
bot.outstandbrand.com
bot.robertohairlab.it
criar.somaperuzzo.com
bot.ilmuseoaiborghi.it
bot.pratikmandalia.com
form.bridesquadapp.com
michaeljackson.riku.ai
87656003.actualizar.xyz
88152257.actualizar.xyz
91375310.actualizar.xyz
arrivalx2.wpwakanda.com
bot.hotelplayarimini.it
link.venturasuceder.com
invite.bridesquadapp.com
bot.amicidisanfaustino.it
chat.thehomebuyersusa.com
forms.hiabhaykulkarni.com
typebot-viewer.vercel.app
bot.adventureconsulting.hu
casestudyemb.wpwakanda.com
chat.atlasoutfittersk9.com
herbalife.barrettamario.it
homepageonly.wpwakanda.com
liveconvert.kandalearn.com
mainmenu1one.wpwakanda.com
tarian.theiofoundation.org
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
liveconvert2.kandalearn.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br
forms.escoladeautomacao.com.br
viewer-v2-typebot-io.vercel.app
bot.studiotecnicoimmobiliaremerelli.it
viewer-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 99850dd Dec 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
app.typebot.io
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 99850dd Dec 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 99850dd Dec 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2-alpha – ./apps/viewer

bot.artiweb.app
bot.devitus.com
bot.tc-mail.com
chat.sureb4.com
eventhub.com.au
games.klujo.com
sakuranembro.it
typebot.aloe.do
bot.piccinato.co
bot.sv-energy.it
botc.ceox.com.br
clo.closeer.work
cockroach.cr8.ai
faqs.nigerias.io
feedback.ofx.one
form.syncwin.com
bot.truongnguyen.live
cdd.searchcube.com.sg
chat.missarkansas.org
chatbot.ownacademy.co
sbutton.wpwakanda.com
815639944.21000000.one
aplicacao.bmind.com.br
apply.ansuraniphone.my
bbutton.wpwwakanda.com
bot.louismarcondes.com
bot.t20worldcup.com.au
c23111azqw.nigerias.io
felipewelington.com.br
form.searchcube.com.sg
gcase.barrettamario.it
help.giversforgood.com
info.clickasuransi.com
kodawariab736.skeep.it
my.swamprecordsgnv.com
premium.kandabrand.com
report.gratirabbit.com
resume.gratirabbit.com
83242573.actualizar.xyz
bot.blackboxtips.com.br
bot.upgradesolutions.eu
help.comebackreward.com
mainmenu.diddancing.com
register.kandabrand.com
signup.hypemarketing.in
subfooter.wpwakanda.com
survey.hypemarketing.in
testbot.afterorigin.com
91181264.your-access.one
ai.chromebookstoreph.com
form.sergiolimajr.com.br
hunterbot.saleshunter.ai
link.cascadigital.com.br
onboarding.growthside.io
reward.onlinebotdemo.xyz
type.opaulovieira.com.br
aibot.angrybranding.co.uk
bot.aidigitalmarketing.kr
bot.arraesecenteno.com.br
bot.blackboxsports.com.br
bot.cabinrentalagency.com
bot.fusionstarreviews.com
boyfriend-breakup.riku.ai
brigadeirosemdrama.com.br
chat.ertcrebateportal.com
chat.thisiscrushhouse.com
sellmyharleylouisiana.com
verfica.botmachine.com.br
configurator.bouclidom.com
help.atlasoutfittersk9.com
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
piazzatorre.barrettamario.it
requests.swamprecordsgnv.com
type.cookieacademyonline.com
bot.brigadeirosemdrama.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
yourfeedback.comebackreward.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
viewer-v2-alpha-typebot-io.vercel.app
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
viewer-v2-alpha-git-main-typebot-io.vercel.app

Please sign in to comment.