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

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