Skip to content

Commit

Permalink
🐛 (bot) Update result variables when overwritten by input
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Dec 28, 2022
1 parent 5b06128 commit f49a301
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const InputChatBlock = ({
setAnswer(label ?? value)
const isRetry = !isInputValid(value, block.type)
if (!isRetry && addAnswer)
await addAnswer({
await addAnswer(typebot.variables)({
blockId: block.id,
groupId: block.groupId,
content: value,
Expand Down
30 changes: 23 additions & 7 deletions packages/bot-engine/src/providers/AnswersProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { safeStringify } from '@/features/variables'
import {
AnswerInput,
ResultValues,
Variable,
VariableWithUnknowValue,
VariableWithValue,
} from 'models'
Expand All @@ -12,6 +13,8 @@ const answersContext = createContext<{
resultId?: string
resultValues: ResultValues
addAnswer: (
existingVariables: Variable[]
) => (
answer: AnswerInput & { uploadedFiles: boolean }
) => Promise<void> | undefined
updateVariables: (variables: VariableWithUnknowValue[]) => void
Expand All @@ -38,13 +41,26 @@ export const AnswersProvider = ({
createdAt: new Date(),
})

const addAnswer = (answer: AnswerInput & { uploadedFiles: boolean }) => {
setResultValues((resultValues) => ({
...resultValues,
answers: [...resultValues.answers, answer],
}))
return onNewAnswer && onNewAnswer(answer)
}
const addAnswer =
(existingVariables: Variable[]) =>
(answer: AnswerInput & { uploadedFiles: boolean }) => {
if (answer.variableId)
updateVariables([
{
id: answer.variableId,
value: answer.content,
name:
existingVariables.find(
(existingVariable) => existingVariable.id === answer.variableId
)?.name ?? '',
},
])
setResultValues((resultValues) => ({
...resultValues,
answers: [...resultValues.answers, answer],
}))
return onNewAnswer && onNewAnswer(answer)
}

const updateVariables = (newVariables: VariableWithUnknowValue[]) => {
const serializedNewVariables = newVariables.map((variable) => ({
Expand Down

5 comments on commit f49a301

@vercel
Copy link

@vercel vercel bot commented on f49a301 Dec 28, 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 f49a301 Dec 28, 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 f49a301 Dec 28, 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-typebot-io.vercel.app
docs.typebot.io
docs-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on f49a301 Dec 28, 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
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on f49a301 Dec 28, 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

ns8.vn
yobot.me
247987.com
8jours.top
bee.cr8.ai
bot.aws.bj
bot.bbc.bj
cat.cr8.ai
finplex.be
pig.cr8.ai
sat.cr8.ai
bot.aipr.kr
docs.cr8.ai
minipost.uk
mole.cr8.ai
team.cr8.ai
wolf.cr8.ai
rhino.cr8.ai
sheep.cr8.ai
svhm.mprs.in
tiger.cr8.ai
video.cr8.ai
zebra.cr8.ai
bot.krdfy.com
goldorayo.com
rabbit.cr8.ai
signup.cr8.ai
turkey.cr8.ai
vhpage.cr8.ai
am.nigerias.io
an.nigerias.io
ar.nigerias.io
bot.enreso.org
bot.lalmon.com
chicken.cr8.ai
panther.cr7.ai
panther.cr8.ai
penguin.cr8.ai
ticketfute.com
unicorn.cr8.ai
apo.nigerias.io
apr.nigerias.io
aso.nigerias.io
bot.ageenda.com
pant.maxbot.com.br
positivobra.com.br
survey.digienge.io
this-is-a-test.com
zap.techadviser.in
bot.digitalbled.com
bot.eventhub.com.au
bot.jepierre.com.br
bot.winglabs.com.br
carsalesenquiry.com
chatbot.repplai.com
demo.botscientis.us
forms.webisharp.com
kbsub.wpwakanda.com
live.botscientis.us
mentoria.omelhor.vc
nutrisamirbayde.com
order.maitempah.com
quest.wpwakanda.com
survey1.digienge.io
test.botscientis.us
typebot.stillio.com
wordsandimagery.com
bium.gratirabbit.com
bot.ansuraniphone.my
bot.cotemeuplano.com
bot.leadbooster.help
chat.hayurihijab.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
kuiz.sistemniaga.com
offer.botscientis.us
sellmycarglasgow.com
talkbot.agfunnel.com
tenorioadvogados.com
uppity.wpwakanda.com
abutton.wpwakanda.com
acelera.maxbot.com.br
aidigitalmarketing.kr
bbutton.wpwakanda.com
bot.incusservices.com
bot.meuesocial.com.br
bot.ramonmatos.com.br
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

Please sign in to comment.