2
0
Files
bot/packages/lib/getBlockById.ts
Baptiste Arnaud 35300eaf34 ♻️ Introduce typebot v6 with events (#1013)
Closes #885
2023-11-08 15:34:16 +01:00

25 lines
695 B
TypeScript

import { Block, Group } from '@typebot.io/schemas'
export const getBlockById = (
blockId: string,
groups: Group[]
): { block: Block; group: Group; blockIndex: number; groupIndex: number } => {
for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
for (
let blockIndex = 0;
blockIndex < groups[groupIndex].blocks.length;
blockIndex++
) {
if (groups[groupIndex].blocks[blockIndex].id === blockId) {
return {
block: groups[groupIndex].blocks[blockIndex],
group: groups[groupIndex],
blockIndex,
groupIndex,
}
}
}
}
throw new Error(`Block with id ${blockId} was not found`)
}