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

1import { SWMLService } from '@signalwire/sdk';
2
3const service = new SWMLService({ name: 'my-ivr' });
4service.addVerb('answer', {});
5service.addVerb('play', { url: 'https://example.com/greeting.mp3' });
6service.addVerb('hangup', {});
7
8const doc = service.renderSwml();
9console.log(JSON.stringify(doc, null, 2));
10// {
11// "version": "1.0.0",
12// "sections": {
13// "main": [
14// { "answer": {} },
15// { "play": { "url": "https://example.com/greeting.mp3" } },
16// { "hangup": {} }
17// ]
18// }
19// }