transfer

View as MarkdownOpen in Claude

Transfer the execution of the script to a different SWML section, URL, or RELAY application. Once the transfer is complete, the script will continue executing SWML from the new location.

Properties

transfer
objectRequired

An object that accepts the following properties.

transfer.dest
stringRequired

Specifies where to transfer to. The value can be one of:

  • "<section_name>" - section in the SWML document to jump to
  • A URL (http or https) - URL to fetch next document from. Sends HTTP POST. Authentication can also be set in the url in the format of username:password@url.
  • An inline SWML document (as a JSON string) - SWML document provided directly as a JSON string
transfer.params
object

Named parameters to send to a section, URL, or application.

transfer.meta
object

User data, ignored by SignalWire. Accepts an object mapping variable names to values.

Valid Destination Values

The destination string can be one of:

  • "section_name" - section in the current document to execute. (For example: execute: main)
  • "relay:<relay application>" - relay application to notify (currently not implemented)
  • "https://example.com/sub-swml.yaml" - URL pointing to the document to execute. An HTTP POST request will be sent to the URL. Authentication can also be set in the url in the format of username:password@url. The params object is passed, along with the variables and the Call object.

Examples

Basic transfer to a URL

1version: 1.0.0
2sections:
3 main:
4 - transfer:
5 dest: "https://example.com/next"

Basic transfer to a section

1version: 1.0.0
2sections:
3 main:
4 - play:
5 url: 'say:Transferring you to another section'
6 - transfer:
7 dest: subsection
8 - play:
9 url: 'say:Back!'
10 subsection:
11 - play:
12 url: 'say:inside a subsection'

Named parameter with sub-parameters

1version: 1.0.0
2sections:
3 main:
4 - transfer:
5 - dest: "https://example.com/next"
6 - params:
7 - foo: "bar"

Transfer to a SWML script hosted on a server

1version: 1.0.0
2sections:
3 main:
4 - prompt:
5 play: >-
6 say: Press 1 to be transfered to the Sales department, 2 for marketing
7 department or anything else to listen to some music.
8 - switch:
9 variable: prompt_value
10 case:
11 '1':
12 - transfer:
13 dest: 'https://<YOUR_NGROK_UUID>.ngrok-free.app'
14 params:
15 where: sales
16 '2':
17 - transfer:
18 dest: 'https://<YOUR_NGROK_UUID>.ngrok-free.app'
19 params:
20 where: marketing
21 - play:
22 url: 'https://cdn.signalwire.com/swml/April_Kisses.mp3'

A minimal server for this SWML script can be written as follows:

1from flask import Flask, request
2from waitress import serve
3
4app = Flask(__name__)
5
6@app.route("/", methods=['POST'])
7def swml():
8 content = request.get_json(silent=True)
9 print(content)
10 return '''
11version: 1.0.0
12sections:
13 main:
14 - answer: {}
15 - play:
16 url: 'say: Welcome to the {} department.'
17'''.format(content['params']['where'])
18
19if __name__ == "__main__":
20 serve(app, host='0.0.0.0', port=6000)

This server (running on localhost) can be made accessible to the wider web (and thus this SWML script) using forwarding tools like ngrok. Visit ngrok.com to learn how.

The server will be sent the payload in the following format:

1{
2 "call": {
3 "call_id": "<call_id>",
4 "node_id": "<node_id>",
5 "segment_id": "<segment_id>",
6 "call_state": "answered",
7 "direction": "inbound",
8 "type": "phone",
9 "from": "<address>",
10 "to": "<address>",
11 "from_number": "<address>",
12 "to_number": "<address>",
13 "headers": [],
14 "project_id": "<your Project UUID>",
15 "space_id": "<your Space UUID>"
16 },
17 "vars": {
18 "answer_result": "success",
19 "prompt_result": "match_digits",
20 "prompt_value_raw": "2",
21 "prompt_value": "2"
22 },
23 "params": { "where": "marketing" }
24}

The call object is described in detail in the introduction. All variables created within the SWML document are passed inside vars, and the params object contains the parameters defined in the params parameter of transfer.