toDict

View as MarkdownOpen in Claude

Convert all contexts to a dictionary for SWML generation. Calls validate() first and throws Error if the configuration is invalid.

Returns

Record<string, unknown> — A mapping of context names to their serialized dictionaries, ready for inclusion in the SWML document.

Example

import { ContextBuilder } from '@signalwire/sdk';
const builder = new ContextBuilder();
const ctx = builder.addContext('default');
ctx.addStep('greet').setText('Hello!');
const data = builder.toDict();
// {"default": {"steps": [{"name": "greet", "text": "Hello!"}]}}