renderDocument

View as MarkdownOpen in Claude

Render the current SWML document as a JSON string. This is the serialized form returned to SignalWire when a call requests SWML. Delegates to SwmlBuilder.renderDocument() under the hood.

For the document as a plain object, use getDocument() or renderSwml() instead.

Returns

string — The SWML document serialized as a JSON string.

Example

1import { SWMLService } from '@signalwire/sdk';
2
3const service = new SWMLService({ name: 'my-service' });
4service.addVerb('answer', {});
5service.addVerb('hangup', {});
6
7const jsonStr = service.renderDocument();
8console.log(jsonStr);
9// '{"version":"1.0.0","sections":{"main":[{"answer":{}},{"hangup":{}}]}}'