File size: 2,432 Bytes
7d72bcf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from .webhook_manager import WebhookManager
import logging
from datetime import datetime
import uuid

logger = logging.getLogger(__name__)

class CallProcessor:
    def __init__(self, customer):
        self.customer = customer
        self.webhook_manager = WebhookManager(customer)

    def process_and_send_call(self, audio_file, caller_number, called_number):
        """Process call and send results to customer's webhook"""
        try:
            # Generate a unique call ID
            call_id = str(uuid.uuid4())

            # Process the call (transcription, summary, sentiment)
            # This is where you would integrate with your existing call processing logic
            # For now, we'll use placeholder data
            call_data = {
                'id': call_id,
                'caller_number': caller_number,
                'called_number': called_number,
                'transcription': "Sample transcription...",  # Replace with actual transcription
                'summary': "Sample summary...",  # Replace with actual summary
                'sentiment': "positive",  # Replace with actual sentiment
                'keywords': "sample, keywords"  # Replace with actual keywords
            }

            # Send to customer's webhook
            success = self.webhook_manager.send_call_results(call_data)

            if success:
                logger.info(f"Successfully processed and sent call {call_id} for customer {self.customer.id}")
                return call_data
            else:
                logger.warning(f"Failed to send call results to webhook for customer {self.customer.id}")
                return None

        except Exception as e:
            logger.error(f"Failed to process and send call for customer {self.customer.id}: {str(e)}")
            raise

    def get_call_details(self, call_id):
        """Get call details from customer's database"""
        try:
            return self.db_manager.get_call_record(call_id)
        except Exception as e:
            logger.error(f"Failed to get call details for call {call_id}: {str(e)}")
            raise

    def search_calls(self, filters=None):
        """Search calls in customer's database"""
        try:
            return self.db_manager.search_call_records(filters)
        except Exception as e:
            logger.error(f"Failed to search calls for customer {self.customer.id}: {str(e)}")
            raise