<aside> ℹ️ Note: this document is subject to change and may be updated periodically as development and testing of the functionality progresses. Updates will be highlighted in the Changelog below this message.

</aside>

Uploading to audio from Aircall should be a simple process:

  1. Retrieve links to all relevant audio files via Aircall API - documented in Aircall API docs
  2. Perform Voyc upload routine per audio file - documented in Voyc upload API docs

Example script:

import os
import requests

logger = Logger()

api_key = os.environ.get("VOYC_API_KEY")
if not api_key:
    raise ValueError("VOYC_API_KEY environment variable not present")

def generate_tokens():
    res = requests.post(
        "<https://api.app.voyc.ai/api/v2/auth/token/>",
        headers={
            "Content-type": "application/json",
            "Authorization": f"Api-Key {api_key}",
        },
    )

    if res.ok:
        bod = res.json()
        access_token = bod["access"]
        refresh_token = bod["refresh"]

        return access_token, refresh_token

def voyc_step_1(access_token, json):
    url = (
        f"<https://api.app.voyc.ai/api/v2/workspace/{organisation_id}/>"
        "conversation/upload_data/"
    )
    res = requests.post(
        url,
        json=json,
        headers={
            "Content-type": "application/json",
            "Authorization": f"Bearer {access_token}",
        },
    )

    return res

def voyc_step_2(recording, upload_data):
    files = {"file": recording}
    res = requests.post(
        url=upload_data["data"]["url"],
        files=files,
        data=upload_data["data"]["fields"],
    )

def fetch_recording_from_aircall(url: str) -> bytes:
    logger.info(f"Fetching recording from aircall for url {url}")
    response = requests.get(url)
    response.raise_for_status()
    return response.content

def upload_audio(recording_url, recording_data) -> dict:

    access_token, _ = generate_tokens()
    recording = fetch_recording_from_aircall(recording_url)

    # Note that the recording_data will need to formatted as per the Voyc documentation
    upload_data = voyc_step_1(access_token, json=recording_data)
    voyc_step_2(recording, upload_data=upload_data)

    return {"statusCode": 200, "body": '{"message": "success"}'}

def handler():
    # retrieve all relevant calls from aircall
    payload = {"from": unix_start, "to": unix_end}
    res = requests.get("<https://api.aircall.io/v1/calls>", params=payload)

    all_calls = res.body["calls"]
    for call in all_calls:
        recording_audio = # format call data
        recording_url = call["recording"]
        upload_audio(recording_url, recording_audio)

handler()

References: