renderSwml

View as MarkdownOpen in Claude

Render the current SWML document. For a plain SWMLService, this delegates to the underlying SwmlBuilder’s getDocument() method and returns the in-memory document object.

The signature accepts optional callId and modifications arguments. These are unused by the base SWMLService implementation but are part of the override-friendly signature: AgentBase overrides renderSwml() to consume them and returns a serialized JSON string instead.

Parameters

callId
string

Optional call id. Used by the AgentBase override; ignored by a plain SWMLService.

modifications
Record<string, unknown>

Optional SWML modifications. Used by the AgentBase override; ignored by a plain SWMLService.

Returns

Record<string, unknown> | string — A plain SWMLService returns the in-memory document object (with version and sections); the AgentBase override returns a serialized JSON string.

Example

import { SWMLService } from '@signalwire/sdk';
const service = new SWMLService({ name: 'my-ivr' });
service.addVerb('answer', {});
service.addVerb('play', { url: 'https://example.com/greeting.mp3' });
service.addVerb('hangup', {});
const doc = service.renderSwml();
console.log(JSON.stringify(doc, null, 2));
// {
// "version": "1.0.0",
// "sections": {
// "main": [
// { "answer": {} },
// { "play": { "url": "https://example.com/greeting.mp3" } },
// { "hangup": {} }
// ]
// }
// }