Spaces:
Sleeping
Sleeping
import streamlit as st | |
import requests | |
import threading | |
from dotenv import load_dotenv | |
import os | |
# Load environment variables from .env file | |
load_dotenv() | |
# Retrieve environment variables | |
auth_token = os.getenv('auth_token') | |
phone_number_id = os.getenv('phone_number_id') | |
assistant_id = os.getenv('assistant_id') | |
def make_call(phone_number): | |
headers = { | |
'Authorization': f'Bearer {auth_token}', | |
'Content-Type': 'application/json', | |
} | |
data = { | |
'assistantId': assistant_id, | |
'phoneNumberId': phone_number_id, | |
'customer': { | |
'number': phone_number, | |
}, | |
} | |
response = requests.post('https://api.vapi.ai/call/phone', headers=headers, json=data) | |
if response.status_code == 201: | |
st.write(f'Call to {phone_number} created successfully') | |
else: | |
st.write(f'Failed to create call to {phone_number}') | |
def main(): | |
st.title('Outbound Calls Using VAPI.AI') | |
phone_numbers_input = st.text_input('Enter phone numbers (e.g., +62187461, +198724914):') | |
phone_numbers = [num.strip() for num in phone_numbers_input.split(',') if num.strip()] | |
if st.button('Make Calls'): | |
threads = [] | |
for number in phone_numbers: | |
thread = threading.Thread(target=make_call, args=(number,)) | |
thread.start() | |
threads.append(thread) | |
for thread in threads: | |
thread.join() | |
st.success('Calls initiated successfully') | |
if __name__ == '__main__': | |
main() | |