Skip to content

Support squads in start #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions vapi_python/vapi_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
CHANNELS = 1


def create_web_call(api_url, api_key, assistant):
def create_web_call(api_url, api_key, payload):
url = f"{api_url}/call/web"
headers = {
'Authorization': 'Bearer ' + api_key,
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, json=assistant)
response = requests.post(url, headers=headers, json=payload)
data = response.json()
if response.status_code == 201:
call_id = data.get('id')
Expand All @@ -27,15 +27,29 @@ def __init__(self, *, api_key, api_url="https://api.vapi.ai"):
self.api_key = api_key
self.api_url = api_url

def start(self, *, assistant_id=None, assistant=None, assistant_overrides=None):
def start(
self,
*,
assistant_id=None,
assistant=None,
assistant_overrides=None,
squad_id=None,
squad=None,
):
# Start a new call
if assistant_id:
assistant = {'assistantId': assistant_id, 'assistantOverrides': assistant_overrides}
payload = {'assistantId': assistant_id, 'assistantOverrides': assistant_overrides}
elif assistant:
assistant = {'assistant': assistant, 'assistantOverrides': assistant_overrides}
payload = {'assistant': assistant, 'assistantOverrides': assistant_overrides}
elif squad_id:
payload = {'squadId': squad_id}
elif squad:
payload = {'squad': squad}
else:
raise Exception("Error: No assistant specified.")

call_id, web_call_url = create_web_call(
self.api_url, self.api_key, assistant)
self.api_url, self.api_key, payload)

if not web_call_url:
raise Exception("Error: Unable to create call.")
Expand Down