typebot.io icon indicating copy to clipboard operation
typebot.io copied to clipboard

Loop (Iteration) Block

Open defsanmith opened this issue 6 months ago • 6 comments

Problem / Motivation TypeBot currently has no native mechanism to repeat a sequence of blocks. Builders are forced to:

  • Duplicate blocks manually
  • Inject custom JavaScript
  • Abandon certain use-cases altogether A first-class Loop Block will let flows iterate over a list or repeat utntil a condition is met, unlocking multi-item data capture, retry logic, dynamic surveys, and more.

Proposed Solution Add a Loop (Iteration) Block that can wrap any sub-flow and execute it repeatedly based on one of three modes:

  1. Fixed Count: iterations = n; exits when counter reaches zero
  2. For-Each: list = varArray; exits when end of array
  3. Until Condition: continueIf = expression; exits when expression evaluates to false

Builder UX

  • Drag-and-drop "Loop" container; creators can next blocks inside.
  • The side panel shows a loop model dropdown and configurable parameters.
  • Visual badge displays current mode, e.g., For-Each.

Runtime behavior

  • Maintains loop index (loop.index, loop.item) in conversation state.
  • Supports a break via a "Break Loop" exit inside nested blocks.
  • Hard guardrail maxIterations to prevent infinite loops.

defsanmith avatar May 22 '25 18:05 defsanmith