Skip to content

Commit

Permalink
🚑 (typebotLink) Fix incoming linked typebot variables filling
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Aug 25, 2023
1 parent 27b15a0 commit 055cf03
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,30 @@ import {
SessionState,
Variable,
ReplyLog,
VariableWithValue,
Edge,
typebotInSessionStateSchema,
TypebotInSession,
} from '@typebot.io/schemas'
import { ExecuteLogicResponse } from '@/features/chat/types'
import { createId } from '@paralleldrive/cuid2'
import { isDefined, isNotDefined } from '@typebot.io/lib/utils'
import { isNotDefined } from '@typebot.io/lib/utils'
import { createResultIfNotExist } from '@/features/chat/queries/createResultIfNotExist'
import { executeJumpBlock } from '../jump/executeJumpBlock'

export const executeTypebotLink = async (
state: SessionState,
block: TypebotLinkBlock
): Promise<ExecuteLogicResponse> => {
const logs: ReplyLog[] = []
const typebotId = block.options.typebotId
if (
typebotId === 'current' ||
typebotId === state.typebotsQueue[0].typebot.id
) {
return executeJumpBlock(state, {
groupId: block.options.groupId,
})
}
if (!typebotId) {
logs.push({
status: 'error',
Expand Down Expand Up @@ -91,10 +99,7 @@ const addLinkedTypebotToState = async (
}
: currentTypebotInQueue

const shouldMergeResults =
block.options.mergeResults !== false ||
currentTypebotInQueue.typebot.id === linkedTypebot.id ||
block.options.typebotId === 'current'
const shouldMergeResults = block.options.mergeResults !== false

if (
currentTypebotInQueue.resultId &&
Expand Down Expand Up @@ -168,26 +173,23 @@ const createResumeEdgeIfNecessary = (
}

const fillVariablesWithExistingValues = (
variables: Variable[],
variablesWithValues: Variable[]
): VariableWithValue[] =>
variables
.map((variable) => {
const matchedVariable = variablesWithValues.find(
(variableWithValue) => variableWithValue.name === variable.name
)
emptyVariables: Variable[],
existingVariables: Variable[]
): Variable[] =>
emptyVariables.map((emptyVariable) => {
const matchedVariable = existingVariables.find(
(existingVariable) => existingVariable.name === emptyVariable.name
)

return {
...variable,
value: matchedVariable?.value,
}
})
.filter((variable) => isDefined(variable.value)) as VariableWithValue[]
return {
...emptyVariable,
value: matchedVariable?.value,
}
})

const fetchTypebot = async (state: SessionState, typebotId: string) => {
const { typebot: typebotInState, resultId } = state.typebotsQueue[0]
const { resultId } = state.typebotsQueue[0]
const isPreview = !resultId
if (typebotId === 'current') return typebotInState
if (isPreview) {
const typebot = await prisma.typebot.findUnique({
where: { id: typebotId },
Expand Down

4 comments on commit 055cf03

@vercel
Copy link

@vercel vercel bot commented on 055cf03 Aug 25, 2023

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 055cf03 Aug 25, 2023

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 055cf03 Aug 25, 2023

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

psmix.online
receita.info
rhino.cr8.ai
sheep.cr8.ai
snake.cr8.ai
svhm.mprs.in
tiger.cr8.ai
video.cr8.ai
webwhats.pro
yoda.riku.ai
zebra.cr8.ai
alvodelas.com
bemestar.club
bot.krdfy.com
cat.hidden.sg
cgcassets.com
cnvhub.com.br
drapamela.com
facelabko.com
filmylogy.com
goldorayo.com
rabbit.cr8.ai
shop.mexwa.my
signup.cr8.ai
start.taxt.co
theusm.com.br
turkey.cr8.ai
vhpage.cr8.ai
vitamyway.com
whatchat.site
www.wiccom.it
am.nigerias.io
an.nigerias.io
app.yvon.earth
ar.nigerias.io
bot.enreso.org
bot.mail2wa.me
bot.rslabs.pro
bots.bng.tools
bots.bridge.ai
chad.gocto.com
chat.hayuri.id
chat.uprize.hu
chatgpt.lam.ee
chicken.cr8.ai
drayumi.social
gollum.riku.ai
gsbulletin.com
journey.cr8.ai
desafioem21d.com
digitando.online
faqs.nigerias.io
feiraodehoje.com
georgemarttt.com
haymanevents.com
viewer-v2-typebot-io.vercel.app
mdb.assessoria.aloisio.progenbr.com
mdb.assessoria.girotto.progenbr.com
mdb.assessoria.marinho.progenbr.com
mdb.assessoria.rodrigo.progenbr.com
register.thailandmicespecialist.com
mdb.assessoria.desideri.progenbr.com
mdb.assessoria.fernanda.progenbr.com
mdb.assessoria.jbatista.progenbr.com
mdb.assessoria.mauricio.progenbr.com
mdb.evento.autocadastro.progenbr.com
form.shopmercedesbenzsouthorlando.com
mdb.evento.equipeinterna.progenbr.com
bot.studiotecnicoimmobiliaremerelli.it
mdb.assessoria.boaventura.progenbr.com
mdb.assessoria.jtrebesqui.progenbr.com
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
gabinete.baleia.formulario.progenbr.com
mdb.assessoria.carreirinha.progenbr.com
chrome-os-inquiry-system.itschromeos.com
mdb.assessoria.paulomarques.progenbr.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com
mdb.assessoria.qrcode.ademir.progenbr.com
mdb.assessoria.qrcode.arthur.progenbr.com
mdb.assessoria.qrcode.danilo.progenbr.com
mdb.assessoria.qrcode.marcao.progenbr.com
mdb.assessoria.qrcode.marcio.progenbr.com
mdb.assessoria.qrcode.aloisio.progenbr.com
mdb.assessoria.qrcode.girotto.progenbr.com
mdb.assessoria.qrcode.marinho.progenbr.com
mdb.assessoria.qrcode.rodrigo.progenbr.com
mdb.assessoria.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.desideri.progenbr.com
mdb.assessoria.qrcode.fernanda.progenbr.com
mdb.assessoria.qrcode.jbatista.progenbr.com
mdb.assessoria.qrcode.mauricio.progenbr.com
mdb.assessoria.fernanda.regional.progenbr.com
mdb.assessoria.qrcode.boaventura.progenbr.com
mdb.assessoria.qrcode.jtrebesqui.progenbr.com
mdb.assessoria.qrcode.carreirinha.progenbr.com
mdb.assessoria.qrcode.paulomarques.progenbr.com
mdb.assessoria.qrcode.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.fernanda.regional.progenbr.com

@vercel
Copy link

@vercel vercel bot commented on 055cf03 Aug 25, 2023

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
builder-v2-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.