File size: 1,513 Bytes
322549d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45d5936
322549d
 
45d5936
322549d
45d5936
322549d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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()