***

title: expression
slug: /reference/typescript/agents/data-map/expression
description: Add a pattern-based response without an API call.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[ref-datamap]: /docs/server-sdks/reference/typescript/agents/data-map

[ref-functionresult]: /docs/server-sdks/reference/typescript/agents/function-result

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

## **Parameters**

<ParamField path="testValue" type="string" required={true} toc={true}>
  Template string to test (e.g., `"${args.command}"`).
</ParamField>

<ParamField path="pattern" type="string | RegExp" required={true} toc={true}>
  Regex pattern to match against the test value.
</ParamField>

<ParamField path="output" type="FunctionResult" required={true} toc={true}>
  [FunctionResult][ref-functionresult] to return when the pattern matches.
</ParamField>

<ParamField path="nomatchOutput" type="FunctionResult" toc={true}>
  Optional FunctionResult to return when the pattern does not match.
</ParamField>

## **Returns**

[`DataMap`][ref-datamap] -- Self for method chaining.

## **Example**

```typescript {4}
import { DataMap, FunctionResult } from '@signalwire/sdk';

const dm = new DataMap('route_command');
dm.expression(
  '${args.command}',
  /play.*/,
  new FunctionResult('Playing file.'),
  new FunctionResult('Unknown command.'),
);
```