Platform-Specific Functions
Based supports different deployment platforms (chat, voice, email, SMS) and provides specialized functions for each platform. These functions allow you to take advantage of platform-specific capabilities.Voice Deployment Functions
When your Based agent is deployed for voice conversations, you can use these special functions to control call flow:transfer(phone_number, options?)
Transfers the current call to another phone number. Optionally supports dialing extensions after the call connects.
Syntax:
phone_number(string): The destination phone number to transfer to (E.164 format recommended, e.g.+15551234567). When usingsipDomain, this is treated as a SIP username (e.g."frontdesk") routed through your Twilio SIP Domain.extension(string, optional): Simple extension digits to dial after the call connectsoptions(dict, optional): Advanced transfer options with the following keys:extension(string): Extension digits to route the call after it connects. In PSTN mode, sent as DTMF tones. In SIP mode, passed as a SIP header to the PBX.pauseSeconds(number): Seconds to wait before sending digits (default: 1 second)sipDomain(string): A Twilio SIP Domain (e.g.yourcompany.sip.twilio.com). When set,phone_numberis treated as a SIP username (e.g."frontdesk") and the call is routed via SIP instead of the PSTN.message(string): A message to say to the caller before transferring. Works for all transfer types; when usingsipDomain, prefer this over a standalonesay()to ensure the message is delivered before the SIP leg is initiated.
When transferring to extensions, the
pauseSeconds parameter controls how long to wait after the call connects before dialing the extension digits. The default of 1 second works for most phone systems, but you may need to increase this for systems that have longer greeting messages or slower IVR responses.When using
sipDomain, the phone_number argument is treated as a SIP username (alphanumeric, e.g. "frontdesk") and the call is routed via sip:<username>@<domain> instead of over the PSTN. When extension is provided, it is included as a SIP header so the PBX can route the call to the correct internal extension; pauseSeconds controls the delay before the header is sent. Use message to speak to the caller before the transfer is initiated.end_call()
Ends the current call immediately. Use this to gracefully terminate a voice conversation after completing the interaction.
Syntax:
click_ivr(digits)
Sends DTMF tones (keypad presses) during an active call. This is useful for navigating IVR (Interactive Voice Response) menus programmatically, such as pressing “1” for sales or entering an account number.
Syntax:
digits(string): The DTMF digits to send. Can include numbers 0-9,*, and#
The
click_ivr function sends DTMF tones immediately. If you need to wait for an IVR prompt before sending tones, use a say statement or add appropriate delays in your flow logic.