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:

{
"version": "1.0.0",
"sections": {
"main": [
{"answer": {}},
{"ai": {}}
]
}
}

Example

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