Skip to navigation

Create a new SWML script resource.

Request

namestringRequired
Name of the SWML Script.
contentsmap from strings to any or stringRequired
The SWML document, as a JSON object or as a string of JSON or YAML. A Calling Script uses [calling SWML methods](/docs/swml/reference/calling); a Messaging Script uses [messaging SWML methods](/docs/swml/reference/messaging).
script_typeenumOptionalDefaults to calling
The kind of script to create. Defaults to `calling` when omitted, so set it to `messaging` explicitly to create a Messaging Script.
Allowed values:
status_callback_urlstringOptionalformat: "uri"
URL that receives status callbacks for messages sent or calls made by this script.

Response

idstringRequiredformat: "uuid"
Unique ID of the SWML Script.
project_idstringRequiredformat: "uuid"
Unique ID of the Project.
display_namestringRequired
Display name of the SWML Script Fabric Resource
typeenumRequired
Type of the Fabric Resource
Allowed values:
created_atdatetimeRequired
Date and time when the resource was created.
updated_atdatetimeRequired
Date and time when the resource was updated.
swml_scriptobjectRequired
SWML Script data.

Response Example

Response
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"project_id": "1313fe58-5e14-4c11-bbe7-6fdfa11fe780",
"display_name": "Reply Bot",
"type": "swml_script",
"created_at": "2024-05-06T12:20:00Z",
"updated_at": "2024-05-06T12:25:00Z",
"swml_script": {
"contents": {
"sections": {
"main": [
{
"reply": "Thanks for your message!"
}
]
},
"version": "1.0.0"
},
"display_name": "Reply Bot",
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"request_url": "https://example.com/swml_script",
"script_type": "messaging"
}
}

Example

import { RestClient } from "@signalwire/sdk";
const client = new RestClient({
project: "your-project-id",
token: "your-api-token",
host: "your-space.signalwire.com",
});
const result = await client.fabric.swmlScripts.create({
name: "my-script",
contents: JSON.stringify({
version: "1.0.0",
sections: { main: [{ answer: {} }, { hangup: {} }] },
}),
});
console.log(`Created: ${result.id}`);