Skip to main content

Built-in Utility Functions

Based provides built-in utility functions that are available in all deployments for common operations like debugging, notifications, and more. The print function works like Python’s standard print, but outputs are captured and made available in the session trace for debugging purposes. This is invaluable for understanding flow execution and troubleshooting issues. Syntax:
Usage:
All print outputs appear in the session trace view, making it easy to debug conversation flows without interrupting the user experience. Print statements do not send messages to the user—they’re purely for developer debugging.

Sending SMS Messages with send_sms

The send_sms function allows you to send SMS messages programmatically from within your Based flow. This is useful for sending confirmations, notifications, or follow-up messages. Syntax:
Parameters:
  • to (string, required): The recipient’s phone number in E.164 format (e.g., "+12025551234")
  • content (string, required): The SMS message content to send
  • from_number (string, required): Your phone number from your Brainbase phone number library
Return Value: Returns an SMSResult object with the following properties: Example:
Handling Failures Gracefully: The send_sms function is designed to never interrupt your flow. All errors are captured in the result object, allowing you to handle failures gracefully:
The from_number must be a phone number registered in your Brainbase phone number library with proper A2P (Application-to-Person) verification for SMS delivery compliance.

Making HTTP Requests

Based provides the standard Python requests module for making HTTP requests to external APIs. This gives you full compatibility with the widely-used requests library. Examples:
Using .ask() with API Responses: You can use the .ask() method on response data to extract structured information:
All HTTP requests are automatically logged in the session trace for debugging and observability. You can see request/response details, timing, and any errors in the trace view.

Legacy API Utility (Deprecated)

The api utility is deprecated. Please use the standard requests module instead.
The legacy api.get_req() and api.post_req() methods are still supported for backwards compatibility:

Third-Party Integrations

Based provides an integrations client for connecting to third-party services configured in your Brainbase workspace. Usage:
Integrations must be connected in your Brainbase workspace before they can be used in Based flows. See the Integrations documentation for setup instructions.