Messaging

switch

View as MarkdownOpen in Claude

Branch on a variable’s value, with optional text transforms applied before matching. Useful for keyword-driven inbound message handling.

Properties

switch
objectRequired

An object that accepts the following properties.

switch.variable
stringRequired

Variable path to match. Specified without the %{} wrapper (e.g. message.body).

switch.transform
string

Transform to apply to the value before matching. One of lowercase, uppercase, trim, lowercase_trim, or uppercase_trim.

switch.case
objectRequired

Map of values to arrays of SWML methods to execute. The key is the value to compare against variable (after applying transform); the value is the array of methods to run on match.

switch.default
object[]

Array of SWML methods to execute if no case matches. If omitted and no case matches, execution stops with an error.

Examples

Keyword-based reply

1version: 1.0.0
2sections:
3 main:
4 - switch:
5 variable: message.body
6 transform: lowercase_trim
7 case:
8 help:
9 - reply:
10 body: "Reply STOP to unsubscribe, or visit https://example.com/help."
11 stop:
12 - reply:
13 body: "You've been unsubscribed."
14 start:
15 - reply:
16 body: "Welcome back!"
17 default:
18 - reply:
19 body: "Sorry, I didn't understand that. Reply HELP for assistance."

Branch on a saved request response

1version: 1.0.0
2sections:
3 main:
4 - request:
5 url: "https://api.example.com/customer"
6 body:
7 phone: "%{message.from}"
8 save_variables: true
9 - switch:
10 variable: request_response.tier
11 case:
12 gold:
13 - reply:
14 body: "Welcome back, valued customer!"
15 silver:
16 - reply:
17 body: "Thanks for being a member."
18 default:
19 - reply:
20 body: "Thanks for your message."