This skill should be used when the user wants to download or retrieve a file from the CRM database and save it to the filesystem. Triggers on requests like "download the contract from CRM", "save the database file to disk", "get the PDF from the database", or "retrieve the attachment from CRM". Uses the bel-crm-db skill for schema knowledge.
Download files stored in the CRM PostgreSQL database and save them to the filesystem in _RESULTS_FROM_AGENT/.
Use this skill when the user wants to:
Trigger phrases:
Do NOT use this skill if:
bel-open-file instead)bel-show-crm-file instead)To understand the database structure and query files, invoke the bel-crm-db skill first to get access to table schemas and connection details.
Determine the file_id from the database. This may require querying tables that link to files:
Common junction tables:
company_site_file tableperson_file tableevent_file tablesales_opportunity_file tableExample query to find files:
-- Find all files for a company
SELECT f.file_id, f.file_name, f.mime_type, f.file_size
FROM file f
JOIN company_site_file csf ON f.file_id = csf.file_id
WHERE csf.company_site_id = 123;
Execute the download script with the file_id:
python scripts/download_file_from_db.py <file_id>
Options:
# Download with custom output directory
python scripts/download_file_from_db.py 456 --output-dir /custom/path
# Quiet mode (only output file path)
python scripts/download_file_from_db.py 456 --quiet
Inform the user where the file was saved:
✅ File downloaded successfully!
File path: _RESULTS_FROM_AGENT/contract.pdf
Original name: contract.pdf
MIME type: application/pdf
Size: 245,832 bytes
The script queries the file table with this structure:
CREATE TABLE file (
file_id SERIAL PRIMARY KEY,
file_hash VARCHAR(64) UNIQUE NOT NULL,
file_name VARCHAR(255) NOT NULL,
mime_type VARCHAR(127),
file_data BYTEA NOT NULL,
file_size INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
_RESULTS_FROM_AGENT/_1, _2, etc. if file existsThe script uses environment variables for database connection:
POSTGRES_URL (preferred): Full connection stringPOSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORDCommon errors:
file_id doesn't exist in databaseThis skill integrates with:
bel-crm-db: For schema knowledge and querying file metadatabel-open-file: To open the downloaded file after savingbel-show-crm-file: Orchestration skill that uses both download and openUser: "Download file ID 789 from the database"
1. Use bel-crm-db to understand schema
2. Run: python scripts/download_file_from_db.py 789
3. Report the saved file path to user
User: "Download the contract for Acme Corp"
1. Use bel-crm-db to query:
- Find company_site_id for "Acme Corp"
- Find file_id via company_site_file junction table
2. Run: python scripts/download_file_from_db.py <file_id>
3. Report results to user
User: "Download all images for event ID 5"
1. Query event_file junction table for all file_ids
2. Loop through each file_id:
- python scripts/download_file_from_db.py <file_id>
3. Report all downloaded file paths