Reference Video: AI Outbound Calling for Automated Sales | AI Sales Agent (youtube.com)
Here's the python code for zapier code step in order to build the automation:
## You can use chatGPT in case of any indentation issues by pasting the following code with instructions: Fix if there're any indentation issue.
import requestsimport time # Import the time module
# Replace these with your Vapi API Authorization token and Phone Number ID
authtoken = 'yourauthtokenhere' # Do not hardcode sensitive data
phonenumberid = 'yourphonenumberidhere' # Do not hardcode sensitive data
# Replace this with input data (names and phones) from your audience
input_data = {
'names': 'John Doe,Jane Smith', # Example names
'phones': '1234567890,0987654321' # Example phone numbers
}
# Split names and phone numbers
names = input_data['names'].split(',')
phones = input_data['phones'].split(',')
# Iterate over each lead (name and phone)
for name, phone in zip(names, phones):
# Prepare customer details
customer_number = f"+1{phone.strip()}" # Assuming the phone number should be in international format
customer_name = name.strip()
# Create the header with Authorization token
headers = {
'Authorization': f'Bearer {auth_token}',
'Content-Type': 'application/json',
}
# Create the data payload for the API request
data = {
"assistantId": "yourassistantid_here", # Replace this with your assistantId
'phoneNumberId': phonenumberid,
'customer': {
'number': customer_number,
},
"assistantOverrides": {
"firstMessage": f"Hello {customer_name}, Do you have a moment to talk?",
}
}
# Make the POST request to Vapi to create the phone call
response = requests.post(
'https://api.vapi.ai/call/phone', headers=headers, json=data)
# Check if the request was successful and print the response
if response.status_code == 201:
print(f'Call created successfully for {customername} at {customernumber}')
print(response.json())
else:
print(f'Failed to create call for {customername} at {customernumber}')
print(response.text)
# Wait for 1 minute before making the next API call
print("Waiting for 1 minute before the next call...")
time.sleep(60)
output_data = {"success": "completed"}
output = output_data
