getDocument

View as MarkdownOpen in Claude

Get the current SWML document as a plain JavaScript object. The returned structure follows the standard SWML format with version and sections keys.

Functionally identical to renderSwml(); getDocument() exists as a Python-compat alias. Use renderDocument() when you need a JSON string rather than an object.

Returns

Record<string, unknown> — The current SWML document. Structure:

1{
2 "version": "1.0.0",
3 "sections": {
4 "main": [
5 {"answer": {}},
6 {"ai": {}}
7 ]
8 }
9}

Example

1import { SWMLService } from '@signalwire/sdk';
2
3const service = new SWMLService({ name: 'my-service' });
4service.addVerb('answer', {});
5service.addVerb('play', { url: 'https://example.com/audio.mp3' });
6
7const doc = service.getDocument();
8console.log((doc as any).version); // "1.0.0"
9console.log(((doc as any).sections.main as []).length); // 2