expression

View as MarkdownOpen in Claude

Add a pattern-based response that does not require an API call. Expressions are evaluated in order; the first matching pattern wins.

Parameters

testValue
stringRequired

Template string to test (e.g., "${args.command}").

pattern
string | RegExpRequired

Regex pattern to match against the test value.

output
FunctionResultRequired

FunctionResult to return when the pattern matches.

nomatchOutput
FunctionResult

Optional FunctionResult to return when the pattern does not match.

Returns

DataMap — Self for method chaining.

Example

1import { DataMap, FunctionResult } from '@signalwire/sdk';
2
3const dm = new DataMap('route_command');
4dm.expression(
5 '${args.command}',
6 /play.*/,
7 new FunctionResult('Playing file.'),
8 new FunctionResult('Unknown command.'),
9);