bindDigit

View as MarkdownOpen in Claude

Bind a DTMF digit sequence to automatically trigger a Relay method when the caller presses those digits. This enables in-call DTMF shortcuts without requiring an active collect operation.

Use clearDigitBindings() to remove bindings.

Parameters

digits
stringRequired

The DTMF digit sequence to bind (e.g., "*1", "##").

bindMethod
stringRequired

The Relay calling method to execute when the digit sequence is detected (e.g., "calling.transfer", "calling.play").

bindParams
Record<string, unknown> | undefined

Parameters to pass to the bound method when triggered.

realm
string | undefined

A namespace for grouping digit bindings. Useful for selectively clearing bindings by realm.

maxTriggers
number | undefined

Maximum number of times this binding can be triggered. After reaching the limit, the binding is automatically removed.

Returns

Promise<Record<string, unknown>> — Server response confirming the binding.

Example

import { RelayClient } from '@signalwire/sdk';
const client = new RelayClient({
project: process.env.SIGNALWIRE_PROJECT_ID!,
token: process.env.SIGNALWIRE_API_TOKEN!,
contexts: ['default']
});
client.onCall(async (call) => {
await call.answer();
// Bind *0 to transfer to an operator
const result = await call.bindDigit('*0', 'calling.transfer', {
bindParams: { dest: 'operator' },
realm: 'shortcuts',
});
console.log(`Digit binding created: ${JSON.stringify(result)}`);
// Bind *9 to play a help message
await call.bindDigit('*9', 'calling.play', {
bindParams: { play: [{ type: 'tts', text: 'Press star-zero for an operator.' }] },
realm: 'shortcuts',
});
});
await client.run();