File size: 875 Bytes
20d97e8
 
5879f9e
20d97e8
 
 
5879f9e
20d97e8
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sqlite3

# Allowing database access from multiple threads
conn = sqlite3.connect("call_logs.db", check_same_thread=False)
c = conn.cursor()

# Create Table for call logs
c.execute('''CREATE TABLE IF NOT EXISTS call_logs
             (id INTEGER PRIMARY KEY, transcript TEXT, intent TEXT, priority TEXT, sentiment TEXT, ai_response TEXT)''')
conn.commit()

def log_call(transcript, intent, priority, sentiment, ai_response):
    """Save the call analysis results to database."""
    c.execute("INSERT INTO call_logs (transcript, intent, priority, sentiment, ai_response) VALUES (?, ?, ?, ?, ?)",
              (transcript, intent, priority, sentiment, ai_response))
    conn.commit()

def fetch_recent_calls(limit=5):
    """Fetch latest logged calls from database."""
    c.execute("SELECT * FROM call_logs ORDER BY id DESC LIMIT ?", (limit,))
    return c.fetchall()