forked from ruvnet/voicebot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
77 lines (66 loc) · 2.25 KB
/
Copy pathapp.py
File metadata and controls
77 lines (66 loc) · 2.25 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from flask import Flask, render_template, request, redirect, url_for, flash
import os
import requests
from prompts import INTERVIEW_PROMPTS
app = Flask(__name__)
app.secret_key = os.urandom(24)
API_KEY = os.getenv('BLAND_AI_API_KEY')
API_URL = 'https://api.bland.ai/v1/calls'
@app.route('/')
def home():
return render_template('home.html', interview_prompts=INTERVIEW_PROMPTS)
@app.route('/start-call', methods=['POST'])
def start_call():
phone_number = request.form.get('phone_number')
interview_type = request.form.get('interview_type')
voice = request.form.get('voice')
if not phone_number:
flash('Phone number is required!', 'error')
return redirect(url_for('home'))
headers = {
'Authorization': f'{API_KEY}'
}
data = {
"phone_number": phone_number,
"from": None,
"task": INTERVIEW_PROMPTS.get(interview_type, INTERVIEW_PROMPTS["default"]),
"model": "enhanced",
"language": "en",
"voice": voice, # Use the selected voice
"voice_settings": {},
"pathway_id": None,
"local_dialing": False,
"max_duration": "2",
"answered_by_enabled": True,
"wait_for_greeting": True,
"record": True,
"amd": False,
"interruption_threshold": 100,
"voicemail_message": None,
"temperature": None,
"transfer_phone_number": None,
"transfer_list": {},
"metadata": {},
"pronunciation_guide": [],
"start_time": None,
"request_data": {},
"tools": [],
"dynamic_data": [],
"analysis_preset": None,
"analysis_schema": {},
"webhook": None,
"calendly": {}
}
try:
response = requests.post(API_URL, json=data, headers=headers)
response.raise_for_status()
flash('Call started successfully!', 'success')
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
if response is not None:
print(f"Response content: {response.text}")
flash(f'An error occurred: {e}', 'error')
return redirect(url_for('home'))
if __name__ == '__main__':
app.run(debug=True) # Comment this out for production
# pass # Gunicorn will handle running the app