Subversion Repositories SmartDukaan

Rev

Rev 35624 | Rev 35660 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35624 Rev 35654
Line 25... Line 25...
25
import org.springframework.http.MediaType;
25
import org.springframework.http.MediaType;
26
import org.springframework.http.ResponseEntity;
26
import org.springframework.http.ResponseEntity;
27
import org.springframework.stereotype.Controller;
27
import org.springframework.stereotype.Controller;
28
import org.springframework.transaction.annotation.Transactional;
28
import org.springframework.transaction.annotation.Transactional;
29
import org.springframework.ui.Model;
29
import org.springframework.ui.Model;
30
import org.springframework.web.bind.annotation.ModelAttribute;
-
 
31
import org.springframework.web.bind.annotation.RequestBody;
30
import org.springframework.web.bind.annotation.*;
32
import org.springframework.web.bind.annotation.RequestMapping;
-
 
33
import org.springframework.web.bind.annotation.RequestMethod;
-
 
34
 
31
 
35
import javax.servlet.http.HttpServletRequest;
32
import javax.servlet.http.HttpServletRequest;
36
 
33
 
37
@Controller
34
@Controller
38
@Transactional(rollbackFor = Throwable.class)
35
@Transactional(rollbackFor = Throwable.class)
Line 59... Line 56...
59
    RecordingService recordingService;
56
    RecordingService recordingService;
60
 
57
 
61
    @Autowired
58
    @Autowired
62
    AgentRecordingRepository agentRecordingRepository;
59
    AgentRecordingRepository agentRecordingRepository;
63
 
60
 
64
    /**
-
 
65
     * Knowlarity Click2Call Webhook - First Event (Call Report Handler).
-
 
66
     * <p>
-
 
67
     * This endpoint is called by Knowlarity when a click-to-call event is initiated or completed.
-
 
68
     * Knowlarity sends call detail data as form-urlencoded POST, which is mapped to {@link CallDetailModel}.
-
 
69
     * <p>
-
 
70
     * The incoming third-party data from Knowlarity may not always match our expected model fields.
-
 
71
     * If Knowlarity changes their payload structure or sends unexpected/null values,
-
 
72
     * errors can occur during binding or in {@link RecordingService#updateAgentRecording}.
-
 
73
     * <p>
-
 
74
     * URL: POST /click2call/report-handler
-
 
75
     * Content-Type: application/x-www-form-urlencoded
-
 
76
     * Third-party: Knowlarity
-
 
77
     */
-
 
78
    @RequestMapping(value = "/click2call/report-handler", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
-
 
79
    public ResponseEntity<?> click2callReportHandlerPost(HttpServletRequest request, Model model, @ModelAttribute CallDetailModel callDetail) throws Exception {
-
 
80
        // Log raw parameters from Knowlarity before processing, so we can see exactly what they sent
-
 
81
        LOGGER.info("report-handler raw params from Knowlarity: {}", request.getParameterMap());
-
 
82
        try {
-
 
83
            LOGGER.info("first event call detail (mapped): {}", callDetail);
-
 
84
            recordingService.updateAgentRecording(callDetail);
-
 
85
        } catch (Exception e) {
-
 
86
            LOGGER.error("Error processing report-handler webhook. Raw params: {}", request.getParameterMap(), e);
-
 
87
        }
-
 
88
        return responseSender.ok(true);
-
 
89
    }
-
 
90
 
61
 
91
 
-
 
92
    /**
62
    /*
93
     * Knowlarity Click2Call Webhook - Recording URL Update.
-
 
94
     *
-
 
95
     * This endpoint is called by Knowlarity after a call recording is available.
-
 
96
     * Knowlarity sends updated call detail (including the recording URL) as form-urlencoded POST,
-
 
97
     * mapped to {@link CallDetailModel}.
-
 
98
     *
-
 
99
     * The incoming third-party data from Knowlarity may not always match our expected model fields.
-
 
100
     * If Knowlarity changes their payload structure or sends unexpected/null values,
-
 
101
     * errors can occur during binding or in {@link RecordingService#updateAgentRecordingUrl}.
-
 
102
     *
-
 
103
     * URL: POST /click2call/report-handler/recording-url
63
     * URL: POST /click2call/report-handler/recording-url
104
     * Content-Type: application/x-www-form-urlencoded
64
     * Content-Type: application/x-www-form-urlencoded
105
     * Third-party: Knowlarity
65
     * Third-party: Knowlarity
106
     */
66
     */
107
    @RequestMapping(value = "/click2call/report-handler/recording-url", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
67
    @RequestMapping(value = "/click2call/report-handler/recording-url", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
Line 117... Line 77...
117
        return responseSender.ok(true);
77
        return responseSender.ok(true);
118
    }
78
    }
119
 
79
 
120
    /**
80
    /**
121
     * Knowlarity Click2Call Webhook - Push Call Log.
81
     * Knowlarity Click2Call Webhook - Push Call Log.
122
     *
-
 
123
     * This endpoint is called by Knowlarity to push call log data in JSON format,
-
 
124
     * mapped to {@link PushCallLogModel}.
-
 
125
     *
-
 
126
     * The incoming third-party data from Knowlarity may not always match our expected model fields.
-
 
127
     * If Knowlarity changes their JSON payload structure or sends unexpected/null values,
-
 
128
     * errors can occur during deserialization or in {@link RecordingService#updateAgentCallLog}.
-
 
129
     *
-
 
130
     * URL: POST /click2call/push-call-log-handler
-
 
131
     * Content-Type: application/json
-
 
132
     * Third-party: Knowlarity
-
 
133
     */
82
     */
134
    @RequestMapping(value = "/click2call/push-call-log-handler", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
83
    @RequestMapping(value = "/click2call/push-call-log-handler/{srNumber}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
135
    public ResponseEntity<?> click2callPushLogHandler(HttpServletRequest request, @RequestBody String rawBody) throws Exception {
84
    public ResponseEntity<?> click2callPushLogHandler(HttpServletRequest request, @RequestBody String rawBody, @PathVariable String srNumber) throws Exception {
136
        // Log raw JSON body from Knowlarity before processing, so we can see exactly what they sent
85
        // Log raw JSON body from Knowlarity before processing, so we can see exactly what they sent
137
        LOGGER.info("push-call-log raw JSON from Knowlarity: {}", rawBody);
86
        LOGGER.info("push-call-log raw JSON from Knowlarity: {}", rawBody);
138
        try {
87
        try {
139
            ObjectMapper objectMapper = new ObjectMapper();
88
            ObjectMapper objectMapper = new ObjectMapper();
140
            PushCallLogModel pushCallLogModel = objectMapper.readValue(rawBody, PushCallLogModel.class);
89
            PushCallLogModel pushCallLogModel = objectMapper.readValue(rawBody, PushCallLogModel.class);