This Python script continuously polls the SignalWire API for new call recordings, creates vCon (virtual conversation) objects from these recordings, and sends them to a specified webhook. It's designed to run as a long-running process, making it suitable for production environments where continuous monitoring of new recordings is required.
- Polls SignalWire API at configurable intervals
- Creates vCon objects from SignalWire recordings
- Includes audio content in the vCon
- Sends vCons to a configured webhook
- Handles graceful shutdown on termination signals
- Provides detailed logging
- Supports debug mode for local testing and diagnostics
- Python 3.12
- SignalWire account and API credentials
- Webhook endpoint to receive vCon data
-
Clone this repository or download the script.
-
Install dependencies using Poetry (recommended):
# Install Poetry curl -sSL https://install.python-poetry.org | python3 - # Install dependencies poetry install
Alternatively, you can use pip:
pip install signalwire vcon requests python-dotenv
This project uses Poetry for dependency management. To set up a development environment:
-
Install Poetry if you haven't already:
curl -sSL https://install.python-poetry.org | python3 -
-
Install project dependencies:
poetry install
This will create a virtual environment and install both main and development dependencies.
-
Activate the virtual environment:
poetry shell
-
You can now run the script, tests, or other development tasks within this environment.
The script uses environment variables for configuration. Set the following variables before running the script:
SIGNALWIRE_PROJECT_ID
: Your SignalWire Project IDSIGNALWIRE_AUTH_TOKEN
: Your SignalWire Auth TokenSIGNALWIRE_SPACE_URL
: Your SignalWire Space URLWEBHOOK_URL
: The URL of the webhook to receive vCon data (not required in debug mode)POLL_INTERVAL
: The interval (in seconds) between API polls (default: 300)DEBUG_MODE
: Set to "true" to enable debug mode (default: "false")DEBUG_DIR
: Directory where vCon files will be saved in debug mode (default: "vcon_debug")
Example:
export SIGNALWIRE_PROJECT_ID=your_project_id
export SIGNALWIRE_AUTH_TOKEN=your_auth_token
export SIGNALWIRE_SPACE_URL=your_space_url
export WEBHOOK_URL=https://your-webhook-endpoint.com/vcon
export POLL_INTERVAL=300
export DEBUG_MODE=false
export DEBUG_DIR=vcon_debug
When DEBUG_MODE
is set to "true", the script will:
- Not require a webhook URL
- Save vCon objects as JSON files to the directory specified by
DEBUG_DIR
instead of sending them to a webhook - Log additional information to assist with debugging
This is useful for testing and development without needing a webhook endpoint.
Run the script using Poetry:
poetry run python signalwire_vcon_script.py
Or activate the Poetry environment first:
poetry shell
python signalwire_vcon_script.py
The script will start polling the SignalWire API for new recordings at the specified interval. For each new recording, it will:
- Create a vCon object
- Download the audio content
- Add the audio content to the vCon
- Send the vCon to the configured webhook (or save to file in debug mode)
The script logs its operations to the console. You can redirect this output to a file for persistent logging:
python signalwire_vcon_script.py > signalwire_vcon_processor.log 2>&1
The script can be terminated gracefully in the following ways:
- Press Ctrl+C in the terminal where it's running
- Send a SIGTERM signal (e.g.,
kill <pid>
) - Use process management tools like supervisord or systemd
When terminated, the script will complete processing the current batch of recordings before shutting down.
The script includes error handling to manage issues with the SignalWire API, webhook communication, or other unexpected errors. All errors are logged for later review.
This project uses pytest for testing and Poetry for dependency management. The test suite verifies the functionality of the SignalWire adapter, including API interactions and vCon creation.
To run the tests:
./run_tests.sh
This script will:
- Install all dependencies using Poetry
- Run the test suite with code coverage reporting
- Generate HTML coverage reports in the
htmlcov/
directory
Tests are configured in pyproject.toml
with the following settings:
- Full test coverage reporting for the
signalwire_adapter
module - Both terminal and HTML coverage reports
- Verbose test output
When adding new functionality, please ensure test coverage by adding test cases to test_signalwire_adapter.py
.
For production deployment, consider using a process manager like supervisord or systemd to ensure the script keeps running and to manage automatic restarts if needed.
This project has been updated to use Python 3.12, which offers:
- Improved performance
- Better error messages with more precise information
- Enhanced type hinting and static analysis
- More efficient memory management
If you're upgrading from a previous version:
- Make sure you have Python 3.12 installed
- Update your virtual environment if you're using one
- Install dependencies using Poetry:
poetry install
Docker users: The Dockerfile has been updated to use the Python 3.12 base image.
Contributions to improve the script are welcome. Please submit a pull request or create an issue to discuss proposed changes.
This project is licensed under the MIT License - see the LICENSE.txt file for details.
For questions or issues, please open an issue in this repository. We'll do our best to address your concerns promptly.