RelayCall

bind_digit

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 clear_digit_bindings() to remove bindings.

Parameters

digits
strRequired

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

bind_method
strRequired

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

bind_params
dict | NoneDefaults to None

Parameters to pass to the bound method when triggered.

realm
str | NoneDefaults to None

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

max_triggers
int | NoneDefaults to None

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

Returns

dict — Server response confirming the binding.

Example

from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
contexts=["default"],
)
@client.on_call
async def handle_call(call):
await call.answer()
# Bind *0 to transfer to an operator
result = await call.bind_digit(
digits="*0",
bind_method="calling.transfer",
bind_params={"dest": "operator"},
realm="shortcuts",
)
print(f"Digit binding created: {result}")
# Bind *9 to play a help message
await call.bind_digit(
digits="*9",
bind_method="calling.play",
bind_params={"play": [{"type": "tts", "params": {"text": "Press star-zero for an operator."}}]},
realm="shortcuts",
)
client.run()