2
0
Files
bot/packages/bot-engine/src/services/inputs.ts
2022-01-18 18:27:26 +01:00

14 lines
469 B
TypeScript

import { ChoiceInputStep, ChoiceItem, Table, Target } from 'models'
export const getSingleChoiceTargetId = (
currentStep: ChoiceInputStep,
choiceItems: Table<ChoiceItem>,
answerContent?: string
): Target | undefined => {
const itemId = currentStep.options.itemIds.find(
(itemId) => choiceItems.byId[itemId].content === answerContent
)
if (!itemId) throw new Error('itemId should exist')
return choiceItems.byId[itemId].target ?? currentStep.target
}